-
Notifications
You must be signed in to change notification settings - Fork 0
/
JuliaFractal.xojo_code
93 lines (86 loc) · 2.8 KB
/
JuliaFractal.xojo_code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#tag Class
Protected Class JuliaFractal
#tag Method, Flags = &h0
Function DrawJuliaFractal(width As Integer, height As Integer, maxIterations As Integer, zoomFactor As Double, offsetX As Double, offsetY As Double, constantReal As Double, constantImaginary As Double) As Picture
// Création d'un objet Picture pour dessiner le graphique fractal de type Julia
Dim fractalPic As New Picture(width, height, 32)
Dim g As Graphics = fractalPic.Graphics
// Parcours de chaque pixel de l'objet Picture
For y As Integer = 0 To height - 1
For x As Integer = 0 To width - 1
// Conversion des coordonnées de l'écran aux coordonnées de la fractale de Julia
Dim zx As Double = 1.5 * (x - width / 2) / (0.5 * zoomFactor * width) + offsetX
Dim zy As Double = (y - height / 2) / (0.5 * zoomFactor * height) + offsetY
Dim iteration As Integer = 0
Dim xtemp As Double
While (zx * zx + zy * zy <= 4.0) And (iteration < maxIterations)
xtemp = zx * zx - zy * zy + constantReal
zy = 2.0 * zx * zy + constantImaginary
zx = xtemp
iteration = iteration + 1
Wend
// Couleur en fonction du nombre d'itérations
Dim xcolor As Color
If iteration = maxIterations Then
// Pour les points à l'intérieur de l'ensemble de Julia
xcolor = Color.RGB(0, 0, 0) // Noir
Else
// Pour les points en dehors de l'ensemble de Julia
Dim smoothColor As Double = iteration + 1 - Log(Log(Sqrt(zx * zx + zy * zy))) / Log(2.0)
Dim smoothColorRatio As Double = smoothColor / maxIterations
Dim hue As Double = 0.7 + 10 * smoothColorRatio
xcolor = Color.HSV(hue, 1.0, 1.0)
End If
// Dessin du pixel dans l'objet Graphics
g.DrawingColor = xcolor
g.DrawLine(x,y,x,y)
Next
Next
// Retour de l'objet Picture contenant le graphique fractal de type Julia
Return fractalPic
End Function
#tag EndMethod
#tag ViewBehavior
#tag ViewProperty
Name="Name"
Visible=true
Group="ID"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Index"
Visible=true
Group="ID"
InitialValue="-2147483648"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Super"
Visible=true
Group="ID"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Left"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Top"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag EndViewBehavior
End Class
#tag EndClass