Skip to content

Instantly share code, notes, and snippets.

@jgoldfar
Created March 10, 2022 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgoldfar/78a5d1ba764fccdb5cea302453c4b945 to your computer and use it in GitHub Desktop.
Save jgoldfar/78a5d1ba764fccdb5cea302453c4b945 to your computer and use it in GitHub Desktop.
Simple Mandelbrot Generator in Python
import math, cmath;
nsq=100;
ndiv=20;
dval=6;
size(20*cm,20*cm);
#fontsize(10)
for x,y in grid(nsq,nsq,math.floor(WIDTH/nsq),math.floor(HEIGHT/nsq)):
ctrz=complex(6*(x+(math.ceil(WIDTH/nsq)/2)-(WIDTH/2))/(WIDTH),6*(y+(math.ceil(HEIGHT/nsq)/2)-(HEIGHT/2))/(HEIGHT));
tmp=complex(0,0);
# print(abs(ctrz));
# print(ctrz);
for i in range(ndiv):
tmp=tmp*tmp + ctrz;
print(abs(tmp))
if abs(tmp)>dval:
print(float(i)/ndiv);
fill(float(i)/ndiv);
break;
print("");
# c=color(random(),random(), random());
# fill(c);
rect(x,y,math.ceil(WIDTH/nsq),math.ceil(HEIGHT/nsq));
#fill(0)
#text(ctrz,x+math.ceil(WIDTH/nsq)/2,y+math.ceil(HEIGHT/nsq)/2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment