Skip to content

Commit 5ab4b83

Browse files
authored
Add files via upload
1 parent d1dd69a commit 5ab4b83

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

ex7_1DrawingAJuliaSet.pyde

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#Julia "laces" defined from a function. Julia set consists of values such that an arbitrarily small perturbation can cause drastic changes in the sequence of iterated function values. Its behavior is "chaotic".
2+
3+
from math import sqrt
4+
5+
#range of x-values
6+
xmin = -2
7+
xmax = 2
8+
9+
#range of y-values
10+
ymin = -2
11+
ymax = 2
12+
13+
#calculate the range of x and y
14+
rangex = xmax - xmin
15+
rangey = ymax - ymin
16+
17+
def setup():
18+
global xscl, yscl
19+
size(600,600)
20+
colorMode(HSB)#Hue, Saturation, Brightness
21+
noStroke()
22+
xscl=width/float(rangex)
23+
yscl=height/float(rangey)
24+
25+
def draw():
26+
#origin in center:
27+
translate(width/2,height/2)
28+
#go over all x's and y's on the grid
29+
x = xmin #initialize to xmin value
30+
while x < xmax: #run the loop until xmax
31+
y = ymin #initialize to ymin value
32+
while y < ymax: #run the loop until ymax
33+
z = [x,y]
34+
c = [0.285,0.01]
35+
#put it into the julia program
36+
col = julia(z,c,100)
37+
#if julia returns 100
38+
if col == 100:
39+
fill(0)
40+
else:
41+
#map the color from 0 to 100
42+
#to 0 to 255
43+
#coll = map(col,0,100,0,300)
44+
fill(3*col,255,255)
45+
rect(x*xscl,y*yscl,1,1)
46+
y += 0.01
47+
x += 0.01
48+
49+
def julia(z, c, num):
50+
'''runs the process num times and returns the diverge count'''
51+
count=0;
52+
z1=z
53+
while count <= num:
54+
if magnitude(z1) > 2.0: #return count when magnitude exceeds 2.0
55+
return count
56+
z1=cAdd(cMult(z1,z1),c) #square the complex number z1, then add it in constant complex number c
57+
count+=1
58+
return num #return the diverge count
59+
60+
def cMult(u,v):
61+
'''Multiply the given two complex numbers and return their result.'''
62+
return [u[0]*v[0]-u[1]*v[1], u[0]*v[1]+u[1]*v[0]]
63+
64+
def cAdd(u,v):
65+
'''Add the given two complex numbers and return their result.'''
66+
return [u[0]+v[0], u[1]+v[1]]
67+
68+
def magnitude(u):
69+
'''Returns magnitude of a given complex number.'''
70+
return sqrt(u[0]**2 + u[1]**2)

0 commit comments

Comments
 (0)