Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from OpenGL.GL import *
- from OpenGL.GLUT import *
- import numpy as np
- from math import *
- def drawRect(w=0.5, h=0.5, xc=0, yc=0, rf=.5, gf=0, bf=0.1, lineWidth=5):
- glColor3f(rf, gf, bf)
- glBegin(GL_POLYGON)
- glVertex(-w / 2 + xc, -h / 2 + yc)
- glVertex(-w / 2 + xc, h / 2 + yc)
- glVertex(w / 2 + xc, h / 2 + yc)
- glVertex(w / 2 + xc, -h / 2 + yc)
- glEnd()
- glColor3f(rf, gf, bf)
- glLineWidth(GLfloat(lineWidth))
- glBegin(GL_LINE_LOOP)
- glVertex(w / 2 - w + xc, h / 2 - h + yc)
- glVertex(w / 2 - w + xc, h / 2 + yc)
- glVertex(w / 2 + xc, h / 2 + yc)
- glVertex(w / 2 + xc, h / 2 - h + yc)
- glEnd()
- def details(w,h,xc,yc,lineWidth,rf,gf,bf):
- glColor3f(rf, gf, bf)
- glLineWidth(GLfloat(lineWidth))
- glBegin(GL_LINE_LOOP)
- glVertex(w / 2 - w + xc, h / 2 - h + yc)
- glVertex(w / 2 - w + xc, h / 2 + yc)
- glVertex(w / 2 + xc, h / 2 + yc)
- glVertex(w / 2 + xc, h / 2 - h + yc)
- glEnd()
- def face(w=.3,h=.3,xc=0,yc=.45,rf=.5,gf=0,bf=.1):
- glColor3f(rf, gf, bf)
- glBegin(GL_POLYGON)
- glVertex(w / 2 - w + xc, h / 2 - h + yc)
- glVertex(w / 2 - w + xc+.05, h / 2 + yc)
- glVertex(w / 2 + xc-.05, h / 2 + yc)
- glVertex(w / 2 + xc, h / 2 - h + yc)
- glEnd()
- glColor3f(0.6, .5, 0)
- glBegin(GL_POLYGON)
- radius=.05
- for theta in np.arange(0, pi, 0.01):
- x = radius * cos(theta)
- y = radius * sin(theta)
- glVertex(x + xc, y + yc+h/2)
- glEnd()
- glColor3f(0.6, .5, 0)
- glBegin(GL_LINES)
- glVertex(0,.6)
- glVertex(0,.75)
- glEnd()
- glColor3f(.6, .5, 0)
- glBegin(GL_POLYGON)
- radius=.03
- lineWidth=.0001
- for theta in np.arange(0, 2 * pi, 0.1):
- x = (radius - lineWidth) * cos(theta)
- y = (radius - lineWidth) * sin(theta)
- glVertex(x , y + .75)
- glEnd()
- glColor3f(1, 1, 1)
- glBegin(GL_POLYGON)
- radius = .015
- lineWidth = .0001
- for theta in np.arange(0, 2 * pi, 0.1):
- x = (radius - lineWidth) * cos(theta)
- y = (radius - lineWidth) * sin(theta)
- glVertex(x, y + .75)
- glEnd()
- details(.16,.001,0,.4,3,0,0,0)
- details(.0015, .025, 0, .45, 3, 0, 0, 0)
- def drawCircle(radius=.013, xt=0, yt=0, r=0, g=0, b=0, rf=1, gf=1, bf=0, lineWidth=.006):
- glColor3f(r, g, b)
- glBegin(GL_POLYGON)
- for theta in np.arange(0, 2 * pi, 0.1):
- x = radius * cos(theta)
- y = radius * sin(theta)
- glVertex(x + xt, y + yt)
- glEnd()
- glColor3f(1, 1, 1)
- glBegin(GL_POLYGON)
- for theta in np.arange(0, 2 * pi, 0.1):
- x = (radius - lineWidth) * cos(theta)
- y = (radius - lineWidth) * sin(theta)
- glVertex(x + xt, y + yt)
- glEnd()
- glColor3f(r, g, b)
- glBegin(GL_POLYGON)
- for theta in np.arange(0, 2 * pi, 0.1):
- x = (radius - 2*lineWidth) * cos(theta)
- y = (radius - 2*lineWidth) * sin(theta)
- glVertex(x + xt, y + yt)
- glEnd()
- def eyes():
- drawCircle(.03,.075,.51)
- drawCircle(.03,-.075,.51)
- def mouse(radius=.08,xt=0,yt=.4,r=0,g=0,b=0,lineWidth=.011,rg=1,gg=1,bg=1):
- glColor3f(r, g, b)
- glBegin(GL_POLYGON)
- for theta in np.arange(0, -pi, -0.01):
- x = radius * cos(theta)
- y = radius * sin(theta)
- glVertex(x + xt, y + yt)
- glEnd()
- glColor3f(rg,gg,bg)
- glBegin(GL_POLYGON)
- for theta in np.arange(0, -pi, -0.01):
- x = (radius - lineWidth) * cos(theta)
- y = (radius - lineWidth) * sin(theta)
- glVertex(x + xt, y + yt)
- glEnd()
- def legs():
- for i in range(100):
- details(.13,.001,.14,-.28-i/200,5,.5,0,.1)
- details(.13,.001,-.14,-.28-i/200,5,.5,0,.1)
- for i in range(0,100,6):
- details(.13,.001,.14,-.28-i/200,2,.2,.1,.2)
- details(.13,.001,-.14,-.28-i/200,2,.2,.1,.2)
- mouse(.07,.14,-.78,0.6,0.5,0,.009,.6, 0.3,0)
- mouse(.07, -.14, -.78, 0.6,0.5,0, .009,.6, 0.3,0)
- def arms():
- details(.01, .15, .268, .18, 4, 0.6, 0.5, 0)
- details(.01, .15, -.268, .18, 3, 0.6, 0.5, 0)
- details(.01, .15, .286, .18, 3, 0.6, 0.3, 0)
- details(.01, .15, -.282, .18, 3, 0.6, 0.3, 0)
- for i in range(80):
- details(.007,.1,.302+i/200,.18,3,.5,0,.1)
- details(.007,.1,-.3-i/200,.18,3,.5,0,.1)
- for i in range(0,80,6):
- details(.0001,.109,.302+i/200,.18,2,.2,.1,.2)
- details(.0001,.109,-.302-i/200,.18,2,.2,.1,.2)
- drawCircle(.06,.71,.18,.6,.5,0,0,1,0,0)
- drawRect(.08,.05,.75,.18,1,1,1)
- drawCircle(.06, -.71, .18, .6, .5, 0, 0, 1, 0, 0)
- drawRect(.08, .05,- .75, .18, 1, 1, 1)
- def body():
- drawRect(.4,.3,0,0,.6,0.4,0.1)
- drawCircle(.03,0,0,.4,0,0.2,0,0,0,0)
- drawCircle(.03, 0.15, 0, .4, 0, 0.2, 0, 0, 0, 0)
- drawCircle(.03, -0.15, 0, .4, 0, 0.2, 0, 0, 0, 0)
- drawCircle(.03, 0, .1, .4, 0, 0.2, 0, 0, 0, 0)
- drawCircle(.03, 0, -.1, .4, 0, 0.2, 0, 0, 0, 0)
- drawCircle(.03, 0.15, 0.1, .4, 0, 0.2, 0, 0, 0, 0)
- drawCircle(.03, -0.15, 0.1, .4, 0, 0.2, 0, 0, 0, 0)
- drawCircle(.03, -0.15, -0.1, .4, 0, 0.2, 0, 0, 0, 0)
- drawCircle(.03, 0.15, -0.1, .4, 0, 0.2, 0, 0, 0, 0)
- def draw():
- glClearColor(1, 1, 1, 1)
- glClear(GL_COLOR_BUFFER_BIT)
- arms()
- drawRect(.05,.06,.12,.5,0.2,0,0.2)
- drawRect(.05, .06, -.12, .5, 0.2,0,0.2)
- drawRect()
- details(.2,.001,0,.27,5,0.6,0.5,0)
- details(.2, .001, 0, .29, 5, .6, 0.3,0)
- details(.15,.001,0.14,-.265,5,.6,.3,0)
- details(.15, .001, -0.14, -.265, 5, .6, .3, 0)
- face()
- eyes()
- mouse()
- legs()
- body()
- details(.001,.08,0,.36,2.5,0,0,0)
- details(.001, .06, 0.04, .37, 2.5, 0, 0, 0)
- details(.001, .06, -0.04, .37, 2.5, 0, 0, 0)
- glFlush()
- glutInit()
- glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
- glutInitWindowSize(600, 600)
- glutCreateWindow(b"Test")
- glutDisplayFunc(draw)
- glutMainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement