• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Mar 24th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from OpenGL.GL import *
2. from OpenGL.GLUT import *
3. import numpy as np
4. from math import *
5.
6. def drawRect(w=0.5, h=0.5, xc=0, yc=0, rf=.5, gf=0, bf=0.1, lineWidth=5):
7.     glColor3f(rf, gf, bf)
8.     glBegin(GL_POLYGON)
9.     glVertex(-w / 2 + xc, -h / 2  + yc)
10.     glVertex(-w / 2  + xc, h / 2 + yc)
11.     glVertex(w / 2 + xc, h / 2 + yc)
12.     glVertex(w / 2 + xc, -h / 2 + yc)
13.     glEnd()
14.     glColor3f(rf, gf, bf)
15.     glLineWidth(GLfloat(lineWidth))
16.     glBegin(GL_LINE_LOOP)
17.     glVertex(w / 2 - w + xc, h / 2 - h + yc)
18.     glVertex(w / 2 - w + xc, h / 2 + yc)
19.     glVertex(w / 2 + xc, h / 2 + yc)
20.     glVertex(w / 2 + xc, h / 2 - h + yc)
21.     glEnd()
22. def details(w,h,xc,yc,lineWidth,rf,gf,bf):
23.     glColor3f(rf, gf, bf)
24.     glLineWidth(GLfloat(lineWidth))
25.     glBegin(GL_LINE_LOOP)
26.     glVertex(w / 2 - w + xc, h / 2 - h + yc)
27.     glVertex(w / 2 - w + xc, h / 2 + yc)
28.     glVertex(w / 2 + xc, h / 2 + yc)
29.     glVertex(w / 2 + xc, h / 2 - h + yc)
30.     glEnd()
31. def face(w=.3,h=.3,xc=0,yc=.45,rf=.5,gf=0,bf=.1):
32.     glColor3f(rf, gf, bf)
33.     glBegin(GL_POLYGON)
34.     glVertex(w / 2 - w + xc, h / 2 - h + yc)
35.     glVertex(w / 2 - w + xc+.05, h / 2 + yc)
36.     glVertex(w / 2 + xc-.05, h / 2 + yc)
37.     glVertex(w / 2 + xc, h / 2 - h + yc)
38.     glEnd()
39.     glColor3f(0.6, .5, 0)
40.     glBegin(GL_POLYGON)
42.     for theta in np.arange(0, pi, 0.01):
43.         x = radius * cos(theta)
44.         y = radius * sin(theta)
45.         glVertex(x + xc, y + yc+h/2)
46.     glEnd()
47.     glColor3f(0.6, .5, 0)
48.     glBegin(GL_LINES)
49.     glVertex(0,.6)
50.     glVertex(0,.75)
51.     glEnd()
52.     glColor3f(.6, .5, 0)
53.     glBegin(GL_POLYGON)
55.     lineWidth=.0001
56.     for theta in np.arange(0, 2 * pi, 0.1):
57.         x = (radius - lineWidth) * cos(theta)
58.         y = (radius - lineWidth) * sin(theta)
59.         glVertex(x , y + .75)
60.     glEnd()
61.     glColor3f(1, 1, 1)
62.     glBegin(GL_POLYGON)
63.     radius = .015
64.     lineWidth = .0001
65.     for theta in np.arange(0, 2 * pi, 0.1):
66.         x = (radius - lineWidth) * cos(theta)
67.         y = (radius - lineWidth) * sin(theta)
68.         glVertex(x, y + .75)
69.     glEnd()
70.     details(.16,.001,0,.4,3,0,0,0)
71.     details(.0015, .025, 0, .45, 3, 0, 0, 0)
72.
73.
74.
75. def drawCircle(radius=.013, xt=0, yt=0, r=0, g=0, b=0, rf=1, gf=1, bf=0, lineWidth=.006):
76.     glColor3f(r, g, b)
77.     glBegin(GL_POLYGON)
78.     for theta in np.arange(0, 2 * pi, 0.1):
79.         x = radius * cos(theta)
80.         y = radius * sin(theta)
81.         glVertex(x + xt, y + yt)
82.     glEnd()
83.
84.     glColor3f(1, 1, 1)
85.     glBegin(GL_POLYGON)
86.     for theta in np.arange(0, 2 * pi, 0.1):
87.         x = (radius - lineWidth) * cos(theta)
88.         y = (radius - lineWidth) * sin(theta)
89.         glVertex(x + xt, y + yt)
90.     glEnd()
91.
92.     glColor3f(r, g, b)
93.     glBegin(GL_POLYGON)
94.     for theta in np.arange(0, 2 * pi, 0.1):
95.         x = (radius - 2*lineWidth) * cos(theta)
96.         y = (radius - 2*lineWidth) * sin(theta)
97.         glVertex(x + xt, y + yt)
98.     glEnd()
99.
100. def eyes():
101.     drawCircle(.03,.075,.51)
102.     drawCircle(.03,-.075,.51)
103.
105.     glColor3f(r, g, b)
106.     glBegin(GL_POLYGON)
107.     for theta in np.arange(0, -pi, -0.01):
108.         x = radius * cos(theta)
109.         y = radius * sin(theta)
110.         glVertex(x + xt, y + yt)
111.     glEnd()
112.
113.     glColor3f(rg,gg,bg)
114.     glBegin(GL_POLYGON)
115.     for theta in np.arange(0, -pi, -0.01):
116.         x = (radius - lineWidth) * cos(theta)
117.         y = (radius - lineWidth) * sin(theta)
118.         glVertex(x + xt, y + yt)
119.     glEnd()
120. def legs():
121.     for i in range(100):
122.         details(.13,.001,.14,-.28-i/200,5,.5,0,.1)
123.         details(.13,.001,-.14,-.28-i/200,5,.5,0,.1)
124.     for i in range(0,100,6):
125.         details(.13,.001,.14,-.28-i/200,2,.2,.1,.2)
126.         details(.13,.001,-.14,-.28-i/200,2,.2,.1,.2)
127.
128.     mouse(.07,.14,-.78,0.6,0.5,0,.009,.6, 0.3,0)
129.     mouse(.07, -.14, -.78, 0.6,0.5,0, .009,.6, 0.3,0)
130.
131. def arms():
132.     details(.01, .15, .268, .18, 4, 0.6, 0.5, 0)
133.     details(.01, .15, -.268, .18, 3, 0.6, 0.5, 0)
134.     details(.01, .15, .286, .18, 3, 0.6, 0.3, 0)
135.     details(.01, .15, -.282, .18, 3, 0.6, 0.3, 0)
136.     for i in range(80):
137.         details(.007,.1,.302+i/200,.18,3,.5,0,.1)
138.         details(.007,.1,-.3-i/200,.18,3,.5,0,.1)
139.     for i in range(0,80,6):
140.         details(.0001,.109,.302+i/200,.18,2,.2,.1,.2)
141.         details(.0001,.109,-.302-i/200,.18,2,.2,.1,.2)
142.     drawCircle(.06,.71,.18,.6,.5,0,0,1,0,0)
143.     drawRect(.08,.05,.75,.18,1,1,1)
144.     drawCircle(.06, -.71, .18, .6, .5, 0, 0, 1, 0, 0)
145.     drawRect(.08, .05,- .75, .18, 1, 1, 1)
146.
147. def body():
148.     drawRect(.4,.3,0,0,.6,0.4,0.1)
149.     drawCircle(.03,0,0,.4,0,0.2,0,0,0,0)
150.     drawCircle(.03, 0.15, 0, .4, 0, 0.2, 0, 0, 0, 0)
151.     drawCircle(.03, -0.15, 0, .4, 0, 0.2, 0, 0, 0, 0)
152.     drawCircle(.03, 0, .1, .4, 0, 0.2, 0, 0, 0, 0)
153.     drawCircle(.03, 0, -.1, .4, 0, 0.2, 0, 0, 0, 0)
154.     drawCircle(.03, 0.15, 0.1, .4, 0, 0.2, 0, 0, 0, 0)
155.     drawCircle(.03, -0.15, 0.1, .4, 0, 0.2, 0, 0, 0, 0)
156.     drawCircle(.03, -0.15, -0.1, .4, 0, 0.2, 0, 0, 0, 0)
157.     drawCircle(.03, 0.15, -0.1, .4, 0, 0.2, 0, 0, 0, 0)
158.
159.
160.
161. def draw():
162.     glClearColor(1, 1, 1, 1)
163.     glClear(GL_COLOR_BUFFER_BIT)
164.     arms()
165.     drawRect(.05,.06,.12,.5,0.2,0,0.2)
166.     drawRect(.05, .06, -.12, .5, 0.2,0,0.2)
167.     drawRect()
168.     details(.2,.001,0,.27,5,0.6,0.5,0)
169.     details(.2, .001, 0, .29, 5, .6, 0.3,0)
170.     details(.15,.001,0.14,-.265,5,.6,.3,0)
171.     details(.15, .001, -0.14, -.265, 5, .6, .3, 0)
172.     face()
173.     eyes()
174.     mouse()
175.     legs()
176.     body()
177.     details(.001,.08,0,.36,2.5,0,0,0)
178.     details(.001, .06, 0.04, .37, 2.5, 0, 0, 0)
179.     details(.001, .06, -0.04, .37, 2.5, 0, 0, 0)
180.     glFlush()
181. glutInit()
182. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
183. glutInitWindowSize(600, 600)
184. glutCreateWindow(b"Test")
185. glutDisplayFunc(draw)
186. glutMainLoop()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top