-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·64 lines (54 loc) · 1.58 KB
/
main.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
#! /usr/bin/env python
#
# Methods related to displaying Chaos Game
#
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
import Image
import ngon
import ChaosGame
#screen_size = 900
#verts = 5
#dim = 2
#frac = 0.5
#max_iter = 5*10**5
screen_size = int(sys.argv[1])
verts = int(sys.argv[2])
dim = int(sys.argv[3])
frac = float(sys.argv[4])
max_iter = int(sys.argv[5])
def point2Display(point):
return [int(float(screen_size)*(point[0]+1.0)/2.0),int(float(screen_size)*(point[1]+1.0)/2.0)]
def initFun():
glClearColor(0.0,0.0,0.0,0.0)
glColor3f(1.0,1.0,1.0)
glPointSize(1.0)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(0.0,float(screen_size),0.0,float(screen_size))
def displayFun():
glClear(GL_COLOR_BUFFER_BIT)
glBegin(GL_POINTS)
#build ngon
new_ngon = ngon.Ngon(dim,verts)
#play game & plot points
points = ChaosGame.ChaosGame.play(new_ngon, frac, max_iter)
for point in points:
curx,cury = point2Display(point)
#print curx,cury
glVertex2f(curx,cury)
glEnd()
glFlush()
screenshot = glReadPixels( 0,0, screen_size, screen_size, GL_RGBA, GL_UNSIGNED_BYTE)
im = Image.frombuffer("RGBA", (screen_size,screen_size), screenshot, "raw", "RGBA", 0, 0)
im.save("images/chaos_game"+"_"+str(verts)+"_"+str(frac)+".png")
#exit()
if __name__ == '__main__':
glutInit()
glutInitWindowSize(screen_size,screen_size)
glutCreateWindow("Chaos Game")
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
glutDisplayFunc(displayFun)
initFun()
glutMainLoop()