Created
March 10, 2022 04:35
-
-
Save jgoldfar/78a5d1ba764fccdb5cea302453c4b945 to your computer and use it in GitHub Desktop.
Simple Mandelbrot Generator in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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