Python Mandelbrot fractal - NumWorks 1.1.2 & 1.2.0 (cmath) comparison
Mandelbrot fractal in Python.
On the left, the NumWorks 1.1.2 original program.
On the right, the same program adapted for the newer NumWorks 1.2.0 firmware, using a function and complex numbers (cmath module).
NumWorks 1.1.2 original code :
import kandinsky
N=10
for x in range(320)
for y in range(222)
zr=0
zi=0
cr=2.7*x/319-2.1
ci=-1.87*y/221+0.935
i=0
while i {less than} N and zr*zr+zi*zi {less than} 4
i=i+1
s=zr
zr=zr*zr-zi*zi+cr
zi=2*s*zi+ci
rgb=int(255*i/N)
col=kandinsky.color(int(rgb),int(.75*rgb),int(.23*rgb))
kandinsky.set_pixel(x,y,col)
Equivalent code for the newer firmware :
import kandinsky
def mandelbrot(N) :
for x in range(320):
for y in range(222):
z=complex(0,0)
c=complex(2.7*x/319-2.1,-1.87*y/221+0.935)
i=0
while i {less than} N and abs(z) {less than} 2:
j=j+1
z=z*z+c
rgb=int(255*i/N)
col=kandinsky.color(int(t),int(.75*t),int(.23*t))
kandinsky.set_pixel(x,y,col)
call with : mandelbrot(10)