-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathjulia.py
80 lines (66 loc) · 1.79 KB
/
julia.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# PyJulia.py
# Plot a Julia set
#rebuilt GF 12sep11
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from numpy import * #do we need this
import sys
# Initalize screen dimensions and the screen origin
width = 250
height = 250
hcenter = 0.0
vcenter = 0.0
axrng = 1.5
hstep = 2*axrng/width
vstep = 2*axrng/height
def init():
# White background
glClearColor(1.0, 1.0, 1.0, 1.0)
# The next statement is all one line!!!
gluOrtho2D(hcenter-axrng,hcenter+axrng,vcenter- axrng,vcenter+axrng)
def drawjulia():
glClear(GL_COLOR_BUFFER_BIT)
glBegin(GL_POINTS)
# Julia set complex number
z = complex(-0.728, 0.1230)
y = vcenter + axrng
while y > vcenter - axrng:
y-= vstep
x = hcenter - axrng
while x < hcenter + axrng:
x+= hstep
n = 0
a = complex(x,y)
# n < 100 is the number of iterations
# Increase this value to show finer detail
# Decrease the value if nothing shows on the screen
while n < 100:
n+=1
a = a**2 + z
zz = abs(a)
# zz > 2 is the critical escape value
# Some functions require larger escape values
# This zz > 2 conditional provides coloration for # points outside the Julia set
if zz > 10:
#glColor3f(sin(2*zz),cos(zz),sin(4*zz))
#glVertex2f(x,y)
n = 5001
# This zz < 2 conditional provides coloration for
# points inside the Julia set.
if zz < 10:
glColor3f(cos(5*zz),sin(4*zz)*cos(4*zz),sin(2*zz))
glVertex2f(x,y)
glEnd()
glFlush()
def main():
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE)
glutInitWindowPosition(50, 50)
glutInitWindowSize(width, height)
glutInit(sys.argv)
glutCreateWindow("Julia Set")
glutDisplayFunc(drawjulia)
init()
glutMainLoop()
main()
# End Program