forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyInverseJulia.py
More file actions
62 lines (51 loc) · 1.22 KB
/
PyInverseJulia.py
File metadata and controls
62 lines (51 loc) · 1.22 KB
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
# PyInverseJulia.py
# Plot a Julia set
# Using inverse iteration
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from random import *
from numpy import *
import sys
# If psyco isn't installed, delete the next two lines!
#import psyco
#psyco.full()
nRange = 2.0
width = 1000
height = 1000
def init():
glClearColor(0.0, 0.0, 0.0, 0.0)
gluOrtho2D(-nRange,nRange,-nRange,nRange)
def drawMandel():
glClear(GL_COLOR_BUFFER_BIT)
# complex seed point
a = complex(-.780737,-.105882)
for i in range(0,10000):
glBegin(GL_POINTS)
x = 2*nRange*random()-2
y = 2*nRange*random()-2
n = 0
z = complex(x,y)
# since there are two square roots
# we randomly choose between them
while n < 10:
n+=1
if random() < .5:
z = sqrt(z-a)
else:
z = -sqrt(z-a)
zz = abs(z)
glColor3f(3/sin(3*zz),cos(3*z.real),2*sin(zz))
glVertex2f(z.real,z.imag)
glEnd()
glFlush()
def main():
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE)
glutInitWindowPosition(50, 50)
glutInitWindowSize(width, height)
glutInit(sys.argv)
glutCreateWindow("Julia Set")
glutDisplayFunc(drawMandel)
init()
glutMainLoop()
main()