2 pièce(s) jointe(s)
Mandelbrot et Julia sans le module Complex
Bonjour,
Passionné depuis des années 70 par le graphisme et les fractales, j'ai voulu recemant m'initier à Haskell. A l'aide des consieil obtenus ici j'ai reussi de créer des petits codes pour une vingaine des fractales les plus répendues. Les codes el les images sont visible sur http://haskellaskvasil.wordpress.com.
Les problèmes sont apparus quant j'ai voulu m'attaquer aux complexes. Pour m'instruire j'ai consulté tous ce que j'ai pu trouver sur le net. Hélas, à part deux codes pour Mandel les "index hors limite", "not in scope" et modul manquant son la monnée courante. Le point commun : ils utilisent tous le module Complex.
Voici deux petits codes VB6 dessinant Mandelbrot et Julia en 1026 x 750 points et ceci en une vingtaine de secondes et sans complexe.
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
| Public Function Simple_Mandel()
minX = -2.4: maxX = 2.4
minY = -1.5: maxY = 1.5
w = Me.ScaleWidth: h = Me.ScaleHeight
DoEvents
If Touche <> 0 Then Exit Function
For x = 0 To w - 1
rc = minX + (maxX - minX) / w * x
For y = 0 To h - 1
ic = minY + (maxY - minY) / h * y
rz = 1
iz = 0
For a = 1 To 29: Rem choix de 32 itérations
DoEvents
r = rz
i = iz
rz = r * r - i * i + rc
iz = 2 * r * i + ic
module = rz * rz + iz * iz
If module > 4 Then Exit For
Next a
PSet (x, y) , RGB(64, 10 * a Mod 255, 20 * a Mod 255)
Next y
Next x
While Touche = 0
DoEvents
Wend
End Function
Public Function JuliaSet()
Dim cRe As Double, cIm As Double
Dim newRe As Double, newIm As Double, oldRe As Double, oldIm As Double
Dim zoom As Double: zoom = 1
moveX = 0: moveY = 0
Dim color As Double
Dim maxIterations As Integer: maxIterations = 300
w = Me.ScaleWidth: h = Me.ScaleHeight
cRe = -0.7
cIm = 0.27015
Dim x As Integer, y As Integer
For x = 0 To w
For y = 0 To h
newRe = 1.5 * (x - w / 2) / (0.5 * zoom * w) + moveX
newIm = (y - h / 2) / (0.5 * zoom * h) + moveY
Dim i As Integer
For i = 0 To maxIterations
oldRe = newRe
oldIm = newIm
newRe = oldRe * oldRe - oldIm * oldIm + cRe
newIm = 2 * oldRe * oldIm + cIm
'if the point is outside the circle with radius 2: stop
If ((newRe * newRe + newIm * newIm) > 4) Then Exit For
Next i
color = RGB(255 Mod (i * 30 + 1), 255 Mod (i + 1), 20 * i) '< maxIterations))
PSet (x, y), color
Next y, x
Me.Refresh
End Function |
Pièce jointe 173072
Pièce jointe 173073
Malgré mes efforts, je n'arrive pas à faire les codes correspondants en Haskell, que j'ai commencé à apprendre depuis peu.
Alors possible ou pas possible ?