Fractal Viewer
A simple fractal viewer.It plots the Mandelbrot Set at the desired size. All you need to do is open a blank form and paste the code in the editor.
AI
KI-Zusammenfassung: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Quellcode
Private Sub Form_Click()
'These four constants define the rectangular region
'of the complex plain that will be iterated.
'Change the values to zoom in/out.
Const ComplexPlain_X1 As Currency = -2
Const ComplexPlain_Y1 As Currency = 2
Const ComplexPlain_X2 As Currency = 2
Const ComplexPlain_Y2 As Currency = -2
'These two variables are used to store the
'ScaleWidth and ScaleHeight values,for
'faster access.
Dim ScreenWidth As Integer
Dim ScreenHeight As Integer
'These two variables reflect the X and Y
'intervals of the loop that moves from
'(ComplexPlain_X1,ComplexPlain_Y1) to
'(ComplexPlain_X2,ComplexPlain_Y2) in
'the complex plain.
Dim StepX As Currency
Dim StepY As Currency
'These two are used in the main loop.
Dim X As Currency
Dim Y As Currency
'Cx and Cy are the real and imaginary part
'respectively of C,in the function
' Zv=Zv-1^2 + C
Dim Cx As Currency
Dim Cy As Currency
'Zx and Zy are the real and imaginary part
'respectively of Z,in the function
' Zv=Zv-1^2 + C
Dim Zx As Currency
Dim Zy As Currency
'This byte variable is assigned a number
'for each pixel in the form.
Dim Color As Byte
'Used in the function that we iterate.
Dim TempX As Currency
Dim TempY As Currency
ScreenWidth = Me.ScaleWidth
ScreenHeight = Me.ScaleHeight
'Calculate the intervals of the loop.
StepX = Abs(ComplexPlain_X2 - ComplexPlain_X1) / ScreenWidth
StepY = Abs(ComplexPlain_Y2 - ComplexPlain_Y1) / ScreenHeight
'Clear the form.
Cls
Plotting = True
For X = 0 To ScreenWidth
For Y = 0 To ScreenHeight
Cx = ComplexPlain_X1 + X * StepX
Cy = ComplexPlain_Y2 + Y * StepY
Zx = 0
Zy = 0
Color = 0
'If you want more fancy fractals,change the
'255 to a higher number,but know that the
'higher you make it,the longer it takes
'for the fractal to be plotted.
While (Not (Zx * Zx + Zy * Zy > 4)) And Color < 255 And Plotting
TempX = Zx
TempY = Zy
Zx = TempX * TempX - TempY * TempY + Cx
Zy = 2 * TempX * TempY + Cy
Color = Color + 1
Wend
If Not Plotting Then Exit Sub
'You can change Color*100 to something else
'in order to get other color schemes in the
'fractal.The function you aply must always
'return a value in the range (0 to 16777215)
SetPixel Me.hdc, X, Y, Color * 100
Next
Me.Refresh
DoEvents
Next
Plotting = False
End Sub
Private Sub Form_Load()
Me.AutoRedraw = True
Me.ScaleMode = 3
Me.Caption = "The Mandelbrot Set"
MsgBox "Resize the form and click on it to get the fractal." & vbCrLf & _
"Keep in mind that large fractals take longer to appear.", vbInformation, "The Mandelbrot Set"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Plotting = False
End Sub
Originalkommentare (3)
Wiederhergestellt von der Wayback Machine