-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmandelrot.pyde
50 lines (40 loc) · 969 Bytes
/
mandelrot.pyde
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
from math import sqrt
xmin = -0.25
xmax = 0.25
ymin = -1
ymax = -0.5
rangex = xmax-xmin
rangey = ymax-ymin
def setup():
global xscl, yscl
size(600,600)
colorMode(HSB)
noStroke()
xscl = float(rangex)/width
yscl = float(rangey)/height
def draw():
#translate(width/2,height/2)
for x in range(width):
for y in range(height):
z = [(xmin + x*xscl), (ymin + y*yscl)]
col= mandelbrot(z,100)
if col==100:
fill(0)
else:
fill(3*col,255,255)
rect(x,y,1,1)
def cAdd(a,b):
return [a[0]+b[0],a[1]+b[1]]
def magnitude(z):
return sqrt(z[0]**2 +z[1]**2)
def cMult(u,v):
return[u[0]*v[0]-u[1]*v[1],u[1]*v[0]+u[0]*v[1]]
def mandelbrot(z,num):
count= 0
z1=z
while count <= num:
if magnitude(z1) > 2.0:
return count
z1=cAdd(cMult(z1,z1),z)
count += 1
return num