-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnowman.py
More file actions
135 lines (112 loc) · 2.3 KB
/
snowman.py
File metadata and controls
135 lines (112 loc) · 2.3 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import math
state=1
x1=-20
x2=20
y1=-50
y2=-50
x3=-50
x4=50
y3=20
y4=20
def clearScreen():
gluOrtho2D(-100,100,-100,100)
glClearColor(0.0,.0,0.0,0.0)
def drawCircle(xc,yc,r):
i=0.0
glColor3f(1.0,1.0,1.0)
glBegin(GL_TRIANGLE_FAN)
glVertex2f(xc,yc)
while i<360.0:
glVertex2f(r*math.cos(math.pi*i/180)+xc,r*math.sin(math.pi*i/180)+yc)
i=i+0.1
glEnd()
glFlush()
def drawPoints(x,y):
glColor3f(0.0,0.0,0.0)
glPointSize(15)
glBegin(GL_POINTS)
glVertex2f(x,y)
glEnd()
glFlush()
def drawTriangle(x1,y1,x2,y2,x3,y3):
glColor3f(1.0,0.0,0.0)
glBegin(GL_POLYGON)
glEnd()
glFlush()
def drawLines(x1,y1,x2,y2):
glLineWidth(5)
glColor3f(1,0.29,0)
glBegin(GL_LINES)
glVertex2f(x1,y1)
glVertex2f(x2,y2)
glEnd()
glFlush()
def drawTriangle(x1,y1,x2,y2,x3,y3):
edges=[
[0,1],
[1,2],
[2,0]
]
points=[
[x1,y1],
[x2,y2],
[x3,y3]
]
setTriangle(edges,points)
def setTriangle(edges,points):
glColor3f(1,0,0)
glBegin(GL_POLYGON)
for e in edges:
for v in e:
glVertex2fv(points[v])
glEnd()
glFlush()
def display():
glClear(GL_COLOR_BUFFER_BIT)
drawLines(-20,-20,x1,y1)
drawLines(20,-20,x2,y2)
drawLines(-20,20,x3,y3)
drawLines(20,20,x4,y4)
drawCircle(0,55,15)
drawTriangle(2,50,-2,54,-15,38)
drawPoints(-5,60)
drawPoints(5,60)
drawCircle(0,0,40)
drawPoints(0,20)
drawPoints(0,0)
drawPoints(0,-20)
glutSwapBuffers()
def rotation(x1,y1,xr,yr,angle):
X1=(x1-xr)*math.cos(math.radians(angle))-(y1-yr)*math.sin(math.radians(angle))+xr
Y1=(x1-xr)*math.sin(math.radians(angle))+(y1-yr)*math.cos(math.radians(angle))+yr
return X1,Y1
def update(values):
global state,x1,y1,x2,y2,x3,y3,x4,y4
glutPostRedisplay()
glutTimerFunc(int(1000/60),update,0)
if state==1:
x1,y1=rotation(x1,y1,-20,-20,5)
x2,y2=rotation(x2,y2,20,-20,-5)
x3,y3=rotation(x3,y3,-20,20,5)
x4,y4=rotation(x4,y4,20,20,-5)
state=0
else:
x1,y1=rotation(x1,y1,-20,-20,-5)
x2,y2=rotation(x2,y2,20,-20,5)
x3,y3=rotation(x3,y3,-20,20,-5)
x4,y4=rotation(x4,y4,20,20,5)
state=1
def main():
glutInit()
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE )
glutInitWindowPosition(50,50)
glutInitWindowSize(800,800)
glutCreateWindow("SnowMan")
glutDisplayFunc(display)
glutTimerFunc(0,update,0)
clearScreen()
glutMainLoop()
main()