Post by scalion on Oct 16, 2018 12:59:45 GMT 1
Hello my friends,
The buddhabrot is an "inverted" version of the mandelbrot fractal. That is, without going into the details, we display the new point position at each iteration (instead of displaying the point of origin only if the last position is within a radius of 2 or of it assign a color according to the number of iterations before it leaves the limit radius).
In this demo the colors of the dots are "stored" in an accumulation array and the max value of dot number for one pixel (zmax) is used to display the rendering without overload color.
Have a nice day
Here the code of BuddhaBrot demo :
OpenW Fixed 1, _X / 2 - 300, _Y / 2 - 300, 600, 600 : Void SetForegroundWindow(Me.hWnd) : AutoRedraw = 1 : BackColor = 0
Global Long ImW = _X, ImH = _Y
Global Large NPLOT = 0
Global Dim z(ImW, ImH) As Double
Global Dim zr(ImW, ImH) As Double
Global Dim zg(ImW, ImH) As Double
Global Dim zb(ImW, ImH) As Double
ArrayFill z(), 0
Global Double zmax, zrmax, zgmax, zbmax, a, e, i, i2, m, r, r2, rt, t, x, xx, y, yy, StartTime = Timer
Global Double xleft, ytop, pm, AfxLeft, AfyTop, zoom = 1.5
Global Long Afx, Afy, red, green, blue, count
t = Timer - 1
xleft = -2
ytop = -2
pm = Max(4 / ImW, 4 / ImH) / zoom
AfxLeft = ImW / 2 - 2 / pm
AfyTop = ImH / 2 - 2 / pm + 100
zmax = 0.01, zrmax = 0.01, zgmax = 0.01, zbmax = 0.01
ArrayFill z(), 0
ArrayFill zr(), 0
ArrayFill zg(), 0
ArrayFill zb(), 0
Do
'x = (Rnd - 0.5) * 4
'y = (Rnd - 0.5) * 4
'x = 2 - Rnd * Rnd * 2 : If Rand(2) = 0 x = -x
'y = 2 - Rnd * Rnd * 2 : If Rand(2) = 0 y = -y
a = Rnd * 2 * PI : r = 2 - (Rnd * Rnd * Rnd) * 2 : y = Sin(a) * r : x = Cos(a) * r
red = 127 + Abs(Sin(x * 2 * PI ) * 127)
green = 127 + Abs(Sin(r * 2 * PI) * 127)
blue = 127 + Abs(Sin(y * 2 * PI) * 127)
xx = x : yy = y
r = xx : i = yy
r2 = r * r : i2 = i * i
For count = 1 To 505 //1 + Rand(1 + Rand(1 + Rand(500)))
rt = r2 - i2 + xx
i = 2 * r * i + yy
r = rt
r2 = r * r
i2 = i * i
If r2 + i2 >= 4 Exit For
If count >= 495 Or count <= 10 ZAARGBplot i , r , red, green, blue
Next count
If Timer - t > 5
InstantShowZAARGB
t = Timer
EndIf
PeekEvent
Loop Until Me Is Nothing
Proc ZAARGBplot(x#, y#, r#, g#, b#) Naked
x = AfxLeft + (x - xleft) / pm
y = AfyTop + (y - ytop) / pm
Inc NPLOT
Afx = x
Afy = y
For Afy = Int(y) - 2 To Int(y) + 2
For Afx = Int(x) - 2 To Int(x) + 2
If Afx > 0
If Afx < ImW
If Afy > 0
If Afy < ImH
m = Max(0, 1 - Sqr((x - Afx) ^ 2 + (y - Afy) ^ 2))
z(Afx, Afy) = z(Afx, Afy) + m
zr(Afx, Afy) = zr(Afx, Afy) + r * m
zg(Afx, Afy) = zg(Afx, Afy) + g * m
zb(Afx, Afy) = zb(Afx, Afy) + b * m
zrmax = Max(zrmax, zr(Afx, Afy))
zgmax = Max(zgmax, zg(Afx, Afy))
zbmax = Max(zbmax, zb(Afx, Afy))
zmax = Max(zmax, z(Afx, Afy))
EndIf
EndIf
EndIf
EndIf
Next Afx
Next Afy
EndProc
Proc InstantShowZAARGB()
Local Double d, a, r, g, b, m, tis
Local Long X, Y, Ox, Oy
tis = Timer
If Timer - StartTime > 0
TitleW 1, "zmax=" & Trim(zmax) & " Plots=" & Trim(NPLOT) & " (" & Round(NPLOT / (Timer - StartTime), 2) & "/s)"
Else
TitleW 1, "zmax=" & Trim(zmax) & " Plots=" & Trim(NPLOT)
EndIf
If zmax > 0
Ox = _X / 2 - ImW / 2
Oy = _Y / 2 - ImH / 2
For Y = 0 To Pred(ImH)
For X = 0 To Pred(ImW)
d = (z(X, Y) / zmax)
m = Min(1, d * 12000)
r = 255.99 * zr(X, Y) / zrmax
g = 255.99 * zg(X, Y) / zgmax
b = 255.99 * zb(X, Y) / zbmax
'Plot Ox + X, Oy + Y, RGB(m * r / 2, m * g, m * 200 + m * 55 / 255 )
Plot Ox + X, Oy + Y, RGB(m * r , m * g, m * b)
PeekEvent : If Me Is Nothing End
Next X
Next Y
EndIf
StartTime += Timer - tis
EndProc