Zn=(Z(n-1))^2+C
where Z and C are complex numbers and C is constant, the mandelbrot set is the set of numbers Z0 for which Zn is bounded. that is, for any value n, including infinity, Zn is not infinite.
If you wish to calculate which points are part of the Mandelbrot set, it is reasonable to iterate a few hundred times and check if the absolute value of the current Z is more than some arbitrary number such as 2.
It is closely related to a julia set. the variable in a julia set is C, and Z0 is constant for any point on a julia set. If you take a point from a representation of the Mandelbrot set, you can create a Julia set for it by using its value of Z0 and plotting on the complex plane of C. There are programs that do this, such as the julia program in the Xscreensaver package.
Computer-generated representations of the Mandelbrot set are generally colorful, while the technical definition of the set allows for only two states: membership and non-membership. The colors typically come from either the number of iterations it takes for Zn exceed some value (indicating that the point is not a member) or the value of Zn with some arbitrary n. For example, if abs(Zn) is less than 2, assume it is a member and color it black. If it's between 2 and 3, color it red. 3-4, orange; 4-5, green; 5-6, blue; 6-100, indigo; 100-infinity, violet (numbers are pulled from the air and should not be taken as suggestions).
My uncle invited Benoit Mandelbrot over to his house once. He sent his son to pick Mandelbrot up at the airport, only he didn't know what Mandelbrot looked like. So he drew an approximation of the Mandelbrot set on a sign and held it up. Sure enough, the mathematician recognized it and was able to find his ride.
Let z be a complex number. Then, for each pixel, count how many times you can square z and add (r,i) to make a new z, before z's absolute value is larger than e.g. 2. Make sure to put an upper bound on this loop, because for some combinations of (r,i), z's absolute value never rises above 2.
Use these formulas: zr = zr2 - zi2 + r zi = 2zrzi + i Make sure you use the old zr in the second formula, and not the one you just calculated.
Now, pick the color of the pixel in question based on how many times the loop ilterated, and put it on the screen. Make the color black if your loop hit the upper bound.
Voila! After waiting a bit, you'll have a beautiful mandelbrot fractal on your screen.
:::::::::::::::::::. ,X222222222SS25222222222222222222252h#@@@@#2rA9s29;s29@@@&2S5552222222222222222 ::::::::::::::::::. G#92222225S22222222222222222222253H@@@S :G@S.@GAi. ;@@@AX5S5S2222222222222 :::::::::::::::::. HHX222252S222222222222222222225X&@@S. i@HX @ ,@@@A@ ;G@HX22S522222222222 ::::::::::::::::. #AX222SS2222222222222222222222h#@G2 . hM@3i@X@3 r.@G X A@92222SS22222222 :::::::::::::::. #A222S5222222222222222222222X&@@M .#@AX9@A@@. r ,@@;M@@ i@A52222S5222222 ::::::::::::::. MA22Si2222222222222222222229M@@r 3@#HHsMr, r@. ;9@2M@@: @@&22222i52222 :::::::::::::, AHX5S2222222222222222222252A@X #@@HA9 r@9 ;@@@@@H, #r2r2H@@Ar. @A522222S222 ::::::::::::, 5MXS5222222222222222222229#@@r : 3@@@@ , ;r2@r s@@@@@@; @@3@@.,h#@@; @25222222S2 :::::::::::: ,#3SX2222222222222222222&@@3 .@@@@@@,&2:@@@5 ,M#@#: .@@:2M@ @@;,@h5222222S :::::::::::, @hS222222222222222225XH@@ . i@@@@@@.9B :: #,@@@@9@#h@@@# : ;, ;@M, @35222222 ::::::::::: iB52222222222222252XGH#. 2@@@@#AA#@ .@@ .@@@ @@@@@@@@@@@@@@@@@@@3 @@#, &@A..@2222222 ::::::::::, @222222222222523&A@2; S,H@@#GXX3G@3. #@H. 2@@@@@@@@@@@@@@@@@@@@@@@#@@A @.B9X ##222222 :::::::::: iA22222252XhM@@@9; ,r@H#B@5Mi9X;99 X,@@ i.H@@@@@@@@@@@@@@@@@@@@@@@@@@@ @3@@@ @h52222 :::::::::, #G2252GM@@@@M 3s@@G G@5 @r&@: :@@s 9@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ :@22222 :::::::::.:M229H@@rS rBHAA9#A r:hh: ;@@@@@, ,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@: .@: @X2222 ::::::::: iB&@@25 r@@G2S5 r@# .;r 5. s@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@, @@5222 ::::::::: B@@; s@@GSii#@ @ :@@@@@@@@@, @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@3 ;#M: @2222 ::::::::: @@ i@@@##B@@;#@@ ;A@@@@@@@@@@@@; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ .@h@: @&222 ::::::::, @ &@22 5@ @@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2 @ri@: :#222 ::::::::.;B#@@@@@;@@r5@@@Ss .A@@.@@@@@@@@@@@@@@@h@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@::@ssX@: ;@222 ::::::::.;@r#235 r rr, . , 2M@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@9 @ 92@: ;@222 ::::::::.;29@@@@@@@@ :@; Mr ,sr @@@@@@@@@@@@@@@,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @H@5@: ;@222 ::::::::, @ ;@@53 5&h@ S@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Br5@: 3B222 ::::::::: @@ X@@HG29@@@@@i A@@@@@@@@@@G r@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ .@@#: @3222 ::::::::: 3#@H. M@#XSss#A @r G@s3G@@X@r @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@; S@@, @5222 ::::::::: rB3B@#s A@BG29;M@i , ,, ,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2 @ @: @BS222 :::::::::,.@X2XA@@@@. ;.3@##rs ,@9.h@ #@h3@@@M 5@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@:M @@. @22222 :::::::::: B&222222A@@@@B:. .B@A;G , SM@@sh ,3@# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@S ;#;@@ s@52222 ::::::::::.;BX2222222223AB#@@B . 9@@@@&SrsSMX@ rs@, :9@@@@@@@@@@@@@@@@@@@@@@@@@#. @BrH# @922222 ::::::::::, #3222222222222252GA#@:, .AM@@MG3XA@# @@X .#@@@@@@@@@@@@@@@@@@@@@@@i@@@ 3:9MA @H522222 ::::::::::: :#52222222222222222S23@#X :G@@@@HH@@ 3@ :H@@ .5@@@@@@@@@@@@@@@@@ : S@A BA2222222 :::::::::::, AH52222222222222222222XA@A; #H@@@@s5S , , .. ,rM#i : @@2S5 H@isS@22222222 ::::::::::::. #G5222222222222222222252G@@. rX@@@@sr@@@@##, @@@@@@ M@@H r H@@@s M2522222i5 ::::::::::::: :@955222222222222222222225G@@s . ,#@@2 r @# r@@@@@@S @@r: ##@@@H ,@9222222222 :::::::::::::, s#3252222222222222222222222h#@@ ;h@@@@;G@ .,A@@A G5HGB@@H 2@3222225S222 ::::::::::::::, 5M322S2222222222222222222222XA@h9 M#M93r@Hs @. HMX@&@@, ,@#322225S22222 :::::::::::::::, 2M3222SS2222222222222222222223A@@S;. :M@&iM r@H . @@H#3; ,@@&2222222222222 ::::::::::::::::, 5#922225S2222222222222222222252h#@H, ; r@HXHG@. r5; M@r B@G2222S5222222222 :::::::::::::::::, r@h2222255S2222222222222222222223H@@@. @@@iS 3M#@@: @@MX225S522222222222 ::::::::::::::::::, .X222222225552222222222222222222222&@@@@#X .#29M22. AX@@@A2555522222222222222
e.g. c = 0 + 0i i=0, n=0, n=n^2 + c => n=0 i=1, n=0, n=n^2 + c => n=0 this is a member, it is never going to go to infinity.
e.g. c = -1 + 0i i=0, n=0, n=n^2 + c => n=-1 i=1, n=-1, n=n^2 + c => n=0 i=2, n=0, n=n^2 + c => n=-1 i=3, n=-1, n=n^2 + c => n=0 this is a member, it is never going to go to infinity.
e.g. c = 1 + 0i i=0, n=0, n=n^2 + c => n=1 i=1, n=1, n=n^2 + c => n=2 i=2, n=2, n=n^2 + c => n=5 this is NOT a member, it is going to go to infinity.
Pretty pictures are generated when looking at the interesting areas around the edge of fractals. Colours are chosen depending on how fast the exiting numbers go to infinity. You can generate an ascii Mandelbrot Set picture with the following code.
A quick foundation course in complex number arithmetic: i is the square root of -1. So i^2 = -1. let c = x + yi, then c^2 = x^2 + 2xyi - y^2. #include < stdio.h > #define SWIDTH 79 #define SHEIGHT 47 #define MINX -2.0 #define MINY 0 #define MAXX 0.5 #define MAXY 1.5 #define DIFX 2.5 #define DIFY 1.5 #define MAXIT 64 char shades [ 38 ] =" ..^^:://II&&@@@***%%%$$$###"; int iter(double r, double i) { int foo=0; double rr,ii,zr,zi; rr=ii=zi=zr=0.0; while(foo< MAXIT && rr+ii< 4){ foo++; zi=2*zr*zi+i; zr=rr-ii+r; rr=zr*zr; ii=zi*zi; /*printf("%d %f %f %f %f %f %f\n",foo,r,i,zr,zi,rr,ii); */ } return foo; } main() { int x,y,i; double xp,yp; for(y=0;y<=SHEIGHT;y++){ xp=(double)y*DIFX/(double)SHEIGHT+MINX; for(x=0;x< SWIDTH;x++){ yp=(double)x*DIFY/(double)SWIDTH+MINY; i=iter(xp,yp); printf("%c",shades [ i%32 ] ); } printf("\n"); } }
#include < stdio.h > #define SWIDTH 79 #define SHEIGHT 47 #define MINX -2.0 #define MINY 0 #define MAXX 0.5 #define MAXY 1.5 #define DIFX 2.5 #define DIFY 1.5 #define MAXIT 64 char shades [ 38 ] =" ..^^:://II&&@@@***%%%$$$###"; int iter(double r, double i) { int foo=0; double rr,ii,zr,zi; rr=ii=zi=zr=0.0; while(foo< MAXIT && rr+ii< 4){ foo++; zi=2*zr*zi+i; zr=rr-ii+r; rr=zr*zr; ii=zi*zi; /*printf("%d %f %f %f %f %f %f\n",foo,r,i,zr,zi,rr,ii); */ } return foo; } main() { int x,y,i; double xp,yp; for(y=0;y<=SHEIGHT;y++){ xp=(double)y*DIFX/(double)SHEIGHT+MINX; for(x=0;x< SWIDTH;x++){ yp=(double)x*DIFY/(double)SWIDTH+MINY; i=iter(xp,yp); printf("%c",shades [ i%32 ] ); } printf("\n"); } }
The following is some Visual Basic code I came up with for drawing the Mandelbrot Set.
fractalmodule.vb:
Imports System.ComponentModel Imports System.Drawing Public Class MainForm Inherits System.Windows.Forms.Form Private RealMax, RealMin As Double Private ImaginaryMax, ImaginaryMin As Double Private MandelPicture As Bitmap Private IsDragging As Boolean Private DragRect As Rectangle Private Distance As Integer Private MouseTick As Integer Private CalcTime As Single Public Sub New() MyBase.New() MainForm = Me InitializeComponent() RealMax = 0.75 RealMin = -2.25 ImaginaryMax = 1.5 ImaginaryMin = -1.5 Show() Calc() End Sub Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Private Sub Calc() Dim p, q As Integer Dim pMax, qMax As Integer Dim MandelValue As Integer Dim MandelColour As Color Dim ColourMultiplier As Integer Dim StopWatch As DateTime = DateTime.Now MandelPicture = New Bitmap(Picture.Width, Picture.Height) pMax = Picture.Width qMax = Picture.Height ColourMultiplier = CInt(256 / Iterations) For p = 0 To pMax - 1 For q = 0 To qMax - 1 MandelValue = (ColourMultiplier * GetMandel(ScaleIt(pMax, p, _ RealMin, RealMax), ScaleIt(qMax, q, ImaginaryMin, _ ImaginaryMax))) - 1 MandelColour = Color.FromArgb(MandelValue, MandelValue, _ MandelValue) MandelPicture.SetPixel(p, q, MandelColour) Next Status.Text = Int(p / pMax * 100) & "%" Next Picture.Image = MandelPicture CalcTime = CSng(DateDiff(Microsoft.VisualBasic.DateInterval.Second, _ StopWatch, DateTime.Now)) PutViewportInStatus(RealMin, RealMax, ImaginaryMin, ImaginaryMax, _ CalcTime) End Sub Private Sub Picture_MouseMove(ByVal sender As Object, ByVal e As _ System.Windows.Forms.MouseEventArgs) Handles Picture.MouseMove Dim TempPic As Image Dim MyGfx As Graphics Dim MyPen As New Pen(Color.FromKnownColor( _ Drawing.KnownColor.IndianRed), 1) If IsDragging Then If e.X - DragRect.Left > e.Y - DragRect.Top Then Distance = e.X - DragRect.Left Else Distance = e.Y - DragRect.Top End If If MouseTick > 5 Then 'only draw every 5 pixels of movement MouseTick = 0 TempPic = MandelPicture.Clone( _ System.Drawing.Rectangle.FromLTRB(0, 0, MandelPicture.Width, _ MandelPicture.Height), Drawing.Imaging.PixelFormat.DontCare) MyGfx = Graphics.FromImage(TempPic) MyGfx.DrawRectangle(MyPen, DragRect.Left, DragRect.Top, _ Distance, Distance) Picture.Image = TempPic End If MouseTick += 1 PutViewportInStatus(ScaleIt(Picture.Width, DragRect.Left, RealMin, _ RealMax), ScaleIt(Picture.Height, DragRect.Top, ImaginaryMin, _ ImaginaryMax), ScaleIt(Picture.Width, DragRect.Left + Distance, + RealMin, RealMax), ScaleIt(Picture.Height, DragRect.Top + _ Distance, ImaginaryMin, ImaginaryMax)) Else Status.Text = "Location: (" & Format(ScaleIt(Picture.Width, e.X, _ RealMin, RealMax), "0.00 ") & Format(ScaleIt(Picture.Height, _ e.Y, ImaginaryMin, ImaginaryMax), "+ 0.00;- 0.00") & ")" End If End Sub Private Sub PutViewportInStatus(ByVal pMin As Double, ByVal qMin As Double, _ ByVal pMax As Double, ByVal qMax As Double, Optional ByVal Time _ As Single = 0) Status.Text = "Viewport: (" & Format(pMin, "0.00;-0.00") & _ Format(qMin, " + 0.00; - 0.00") & ") - (" & Format(pMax, _ "0.00;-0.00") & Format(qMax, " + 0.00; - 0.00") & ")" & _ Format(Time, "\; (0.00 seconds);;#") End Sub Private Sub Picture_MouseDown(ByVal sender As Object, ByVal e As _ System.Windows.Forms.MouseEventArgs) Handles Picture.MouseDown Select Case e.Button Case MouseButtons.Left IsDragging = True DragRect.X = e.X DragRect.Y = e.Y End Select End Sub Private Sub Picture_MouseUp(ByVal sender As Object, ByVal e As _ System.Windows.Forms.MouseEventArgs) Handles Picture.MouseUp Dim Input As String Select Case e.Button Case MouseButtons.Left If IsDragging = True Then IsDragging = False Picture.Image = MandelPicture If Distance > 0 Then RealMin = ScaleIt(Picture.Width, DragRect.Left, _ RealMin, RealMax) ImaginaryMin = ScaleIt(Picture.Height, DragRect.Top, _ ImaginaryMin, ImaginaryMax) RealMax = ScaleIt(Picture.Width, DragRect.Left + _ Distance, RealMin, RealMax) ImaginaryMax = ScaleIt(Picture.Height, DragRect.Top + _ Distance, ImaginaryMin, ImaginaryMax) Calc() End If End If Case MouseButtons.Right IsDragging = False 'Input = InputBox("0 < Iterations <= 256", "64").Trim 'If IsNumeric(Input) Then 'If CInt(Input) > 0 And CInt(Input) <= 256 Then ' Iterations = CInt(Input) ' Calc() 'Else ' Beep() 'End If 'End If End Select End Sub Private Sub Picture_MouseLeave(ByVal sender As Object, ByVal e As _ System.EventArgs) Handles Picture.MouseLeave PutViewportInStatus(RealMin, RealMax, ImaginaryMin, ImaginaryMax, _ CalcTime) End Sub #Region " Windows Form Designer generated code " 'Required by the Windows Form Designer Private components As System.ComponentModel.Container Private WithEvents Status As System.Windows.Forms.StatusBar Private WithEvents Picture As System.Windows.Forms.PictureBox Dim WithEvents MainForm As System.Windows.Forms.Form 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Private Sub InitializeComponent() Me.Picture = New System.Windows.Forms.PictureBox() Me.Status = New System.Windows.Forms.StatusBar() Me.SuspendLayout() ' 'Picture ' Me.Picture.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or _ System.Windows.Forms.AnchorStyles.Bottom) _ Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right) Me.Picture.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.Picture.Cursor = System.Windows.Forms.Cursors.Cross Me.Picture.Name = "Picture" Me.Picture.Size = New System.Drawing.Size(397, 373) Me.Picture.TabIndex = 0 Me.Picture.TabStop = False ' 'Status ' Me.Status.Location = New System.Drawing.Point(0, 375) Me.Status.Name = "Status" Me.Status.Size = New System.Drawing.Size(397, 20) Me.Status.TabIndex = 1 Me.Status.Text = "Please wait" ' 'MainForm ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(397, 395) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Status, _ Me.Picture}) Me.Font = New System.Drawing.Font("Tahoma", 8.0!) Me.MaximizeBox = False Me.MinimizeBox = False Me.Name = "MainForm" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent Me.Text = "Mandelbrot Set" Me.ResumeLayout(False) End Sub #End Region End Class
mainform.vb:
Imports System.ComponentModel Imports System.Drawing Public Class MainForm Inherits System.Windows.Forms.Form Private RealMax, RealMin As Double Private ImaginaryMax, ImaginaryMin As Double Private MandelPicture As Bitmap Private IsDragging As Boolean Private DragRect As Rectangle Private Distance As Integer Private MouseTick As Integer Private CalcTime As Single Public Sub New() MyBase.New() MainForm = Me InitializeComponent() RealMax = 0.75 RealMin = -2.25 ImaginaryMax = 1.5 ImaginaryMin = -1.5 Show() Calc() End Sub Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Private Sub Calc() Dim p, q As Integer Dim pMax, qMax As Integer Dim MandelValue As Integer Dim MandelColour As Color Dim ColourMultiplier As Integer Dim StopWatch As DateTime = DateTime.Now MandelPicture = New Bitmap(Picture.Width, Picture.Height) pMax = Picture.Width qMax = Picture.Height ColourMultiplier = CInt(256 / Iterations) For p = 0 To pMax - 1 For q = 0 To qMax - 1 MandelValue = (ColourMultiplier * GetMandel(ScaleIt(pMax, _ p, RealMin, RealMax), ScaleIt(qMax, q, ImaginaryMin, _ ImaginaryMax))) - 1 MandelColour = Color.FromArgb(MandelValue, MandelValue, _ MandelValue) MandelPicture.SetPixel(p, q, MandelColour) Next Status.Text = Int(p / pMax * 100) & "%" Next Picture.Image = MandelPicture CalcTime = CSng(DateDiff(Microsoft.VisualBasic.DateInterval.Second, _ StopWatch, DateTime.Now)) PutViewportInStatus(RealMin, RealMax, ImaginaryMin, ImaginaryMax, _ CalcTime) End Sub Private Sub Picture_MouseMove(ByVal sender As Object, ByVal e As _ System.Windows.Forms.MouseEventArgs) Handles Picture.MouseMove Dim TempPic As Image Dim MyGfx As Graphics Dim MyPen As New Pen(Color.FromKnownColor(Drawing.KnownColor.IndianRed _ ), 1) If IsDragging Then If e.X - DragRect.Left > e.Y - DragRect.Top Then Distance = e.X - DragRect.Left Else Distance = e.Y - DragRect.Top End If If MouseTick > 5 Then 'only draw every 5 pixels of movement MouseTick = 0 TempPic = MandelPicture.Clone( _ System.Drawing.Rectangle.FromLTRB(0, 0, MandelPicture.Width, _ MandelPicture.Height), Drawing.Imaging.PixelFormat.DontCare) MyGfx = Graphics.FromImage(TempPic) MyGfx.DrawRectangle(MyPen, DragRect.Left, DragRect.Top, _ Distance, Distance) Picture.Image = TempPic End If MouseTick += 1 PutViewportInStatus(ScaleIt(Picture.Width, DragRect.Left, RealMin, _ RealMax), ScaleIt(Picture.Height, DragRect.Top, ImaginaryMin, _ ImaginaryMax), ScaleIt(Picture.Width, DragRect.Left + Distance, _ RealMin, RealMax), ScaleIt(Picture.Height, DragRect.Top + _ Distance, ImaginaryMin, ImaginaryMax)) Else Status.Text = "Location: (" & Format(ScaleIt(Picture.Width, e.X, _ RealMin, RealMax), "0.00 ") & Format(ScaleIt(Picture.Height, _ e.Y, ImaginaryMin, ImaginaryMax), "+ 0.00;- 0.00") & ")" End If End Sub Private Sub PutViewportInStatus(ByVal pMin As Double, ByVal qMin As Double, _ ByVal pMax As Double, ByVal qMax As Double, Optional ByVal Time As _ Single = 0) Status.Text = "Viewport: (" & Format(pMin, "0.00;-0.00") & _ Format(qMin, " + 0.00; - 0.00") & ") - (" & Format(pMax, _ "0.00;-0.00") & Format(qMax, " + 0.00; - 0.00") & ")" & _ Format(Time, "\; (0.00 seconds);;#") End Sub Private Sub Picture_MouseDown(ByVal sender As Object, ByVal e As _ System.Windows.Forms.MouseEventArgs) Handles Picture.MouseDown Select Case e.Button Case MouseButtons.Left IsDragging = True DragRect.X = e.X DragRect.Y = e.Y End Select End Sub Private Sub Picture_MouseUp(ByVal sender As Object, ByVal e As _ System.Windows.Forms.MouseEventArgs) Handles Picture.MouseUp Dim Input As String Select Case e.Button Case MouseButtons.Left If IsDragging = True Then IsDragging = False Picture.Image = MandelPicture If Distance > 0 Then RealMin = ScaleIt(Picture.Width, DragRect.Left, RealMin, _ RealMax) ImaginaryMin = ScaleIt(Picture.Height, DragRect.Top, _ ImaginaryMin, ImaginaryMax) RealMax = ScaleIt(Picture.Width, DragRect.Left + _ Distance, RealMin, RealMax) ImaginaryMax = ScaleIt(Picture.Height, DragRect.Top + _ Distance, ImaginaryMin, ImaginaryMax) Calc() End If End If Case MouseButtons.Right IsDragging = False 'Input = InputBox("0 < Iterations <= 256", "64").Trim 'If IsNumeric(Input) Then 'If CInt(Input) > 0 And CInt(Input) <= 256 Then ' Iterations = CInt(Input) ' Calc() 'Else ' Beep() 'End If 'End If End Select End Sub Private Sub Picture_MouseLeave(ByVal sender As Object, ByVal e As _ System.EventArgs) Handles Picture.MouseLeave PutViewportInStatus(RealMin, RealMax, ImaginaryMin, ImaginaryMax, _ CalcTime) End Sub #Region " Windows Form Designer generated code " 'Required by the Windows Form Designer Private components As System.ComponentModel.Container Private WithEvents Status As System.Windows.Forms.StatusBar Private WithEvents Picture As System.Windows.Forms.PictureBox Dim WithEvents MainForm As System.Windows.Forms.Form 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Private Sub InitializeComponent() Me.Picture = New System.Windows.Forms.PictureBox() Me.Status = New System.Windows.Forms.StatusBar() Me.SuspendLayout() ' 'Picture ' Me.Picture.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or _ System.Windows.Forms.AnchorStyles.Bottom) _ Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right) Me.Picture.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.Picture.Cursor = System.Windows.Forms.Cursors.Cross Me.Picture.Name = "Picture" Me.Picture.Size = New System.Drawing.Size(397, 373) Me.Picture.TabIndex = 0 Me.Picture.TabStop = False ' 'Status ' Me.Status.Location = New System.Drawing.Point(0, 375) Me.Status.Name = "Status" Me.Status.Size = New System.Drawing.Size(397, 20) Me.Status.TabIndex = 1 Me.Status.Text = "Please wait" ' 'MainForm ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(397, 395) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Status, Me.Picture}) Me.Font = New System.Drawing.Font("Tahoma", 8.0!) Me.MaximizeBox = False Me.MinimizeBox = False Me.Name = "MainForm" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent Me.Text = "Mandelbrot Set" Me.ResumeLayout(False) End Sub #End Region End Class
#!/usr/bin/env python from __future__ import nested_scopes (lambda ITERS, BOUND, SCALE, RMIN, RMAX, IMIN, IMAX, STEP, SHADES,WRITE,LOG: [r for r in range( RMIN*SCALE, RMAX*SCALE, STEP) if WRITE('\n') or [i for i in range(IMIN*SCALE, IMAX*SCALE, STEP) if (lambda j : WRITE(SHADES[int(LOG(j+1))%len(SHADES)])) ((lambda k : reduce( lambda x, y : (abs(x[1]) <= BOUND) and (x[0]+1, (x[1])**2 + y[1]) or x, [(0,k)]*ITERS)) (complex(r/SCALE, i/SCALE))[0])]])( 10000, 4, 150.0, -2.25, 1.5, -1.25, 1.25, 5, ".^:/I&@*%%$$###,", __import__('sys').stdout.write, __import__('math').log)
Some thoughts on the form Zn=(Z(n-1))^2+C:
^2 can be replaced with ^P, where P is any number greater than 1. Whole numbers produce sets with P-1 buds, whereas other numbers produce extremely interesting chaotic sets (P=1.5 is my personal favorite). P can also be complex, which produces even cooler fractals; these don't even have the characteristic set centered around the origin!
Multiple dimensional fractals can be made by having any combination of Zr, Zi, Cr, Ci, Pr, and Pi be dependent on any number of axis (four is the most human minds can usually handle ;). I have not yet tested quaternions or octonions.
If any point Z0 is found to be not contained within the set, then any of the Zn's encountered during iteration are also not contained. The opposite is theoretically true, but only if you iterate infinitely.
I wrote this particularly fugly bit of perl once as a joke for a friend... (needs a terminal with ANSI colour).
printable version chaos
Everything2 Help
cooled by Jinmyo