-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathgingerbread.py
65 lines (49 loc) · 1.33 KB
/
gingerbread.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
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
"""
The gingerbread man
The gingerbread man is again iterated function sequence ( see mathworld.wolfram.com∞
for example). This code generates the gingerbread man based on the parameters
suggested in the book. But the starting point can be altered by clicking the mouse.
http://www.de-brauwer.be/wiki/wikka.php?wakka=PyOpenGLGingerbread
"""
x = 115
y = 121
def initFun():
glClearColor(1.0, 1.0, 1.0, 0.0)
glColor3f(0.0, 0.0, 0.0)
glPointSize(4.0)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(0.0, 640.0, 0.0, 480.0)
def mouseFun(button, state, xIn, yIn):
global x
global y
if button == GLUT_LEFT_BUTTON and state == GLUT_DOWN:
x = xIn
y = 480 - yIn
glutPostRedisplay()
def displayFun():
global x
global y
glClear(GL_COLOR_BUFFER_BIT)
glBegin(GL_POINTS)
M = 40
L = 3
for i in range(0, 500000):
glVertex2f(x, y)
tmp = x
x = M * (1 + 2 * L) - y + abs(x - L * M)
y = tmp
glEnd()
glFlush()
if __name__ == "__main__":
glutInit()
glutInitWindowSize(640, 480)
glutCreateWindow(b"Gingerbread")
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
glutDisplayFunc(displayFun)
glutMouseFunc(mouseFun)
initFun()
glutMainLoop()