Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pyglet.gl import *
- from pyglet.window import key
- from pyglet.window import mouse
- window = pyglet.window.Window(1000, 1000, resizable = True)
- window.set_minimum_size(144, 144)
- gl.glClearColor(0, 0.5, 0.8, 1)
- ratio = 1
- pos = [0, 0, 0]
- rot = [0, 0, 0]
- isFramedMode = False
- colors = [[0.1, 0.7, 0.1], [0.25, 0.5, 0.25], [0.4, 0.1, 0.4], [0.55, 0.5, 0.55], [0.7, 0.1, 0.7], [0.85, 0.5, 0.85]]
- def which(mode, first, second, third, fourth, color):
- if mode:
- glBegin(GL_LINE_LOOP)
- glColor3f(0, 0, 0)
- else:
- glBegin(GL_POLYGON)
- glColor3f(*color)
- glVertex3f(*first)
- glVertex3f(*second)
- glVertex3f(*third)
- glVertex3f(*fourth)
- glEnd()
- def baseCube(framed):
- lbf = [-0.5, -0.5, -0.5]
- rbf = [0.5, -0.5, -0.5]
- rtf = [0.5, 0.5, -0.5]
- ltf = [-0.5, 0.5, -0.5]
- lbn = [-0.5, -0.5, 0.5]
- rbn = [0.5, -0.5, 0.5]
- rtn = [0.5, 0.5, 0.5]
- ltn = [-0.5, 0.5, 0.5]
- # BOTTOM
- which(framed, lbn, lbf, rbf, rbn, colors[0])
- # BACK
- which(framed, lbf, ltf, rtf, rbf, colors[1])
- # LEFT
- which(framed, lbn, lbf, ltf, ltn, colors[2])
- # RIGHT
- which(framed, rbn, rbf, rtf, rtn, colors[3])
- # TOP
- which(framed, ltn, ltf, rtf, rtn, colors[4])
- # FRONT
- which(framed, lbn, ltn, rtn, rbn, colors[5])
- @window.event
- def on_draw():
- global ratio
- global isFramedMode
- window.clear()
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
- glEnable(GL_DEPTH_TEST)
- glMatrixMode(GL_PROJECTION)
- glLoadIdentity()
- gluPerspective(40, ratio, 0.1, 100)
- glMatrixMode(GL_MODELVIEW)
- glLoadIdentity()
- glPushMatrix()
- glTranslated(-0.45, -0.45, -1.7)
- glScaled(0.15, 0.15, 0.15)
- baseCube(False)
- glPopMatrix()
- glMatrixMode(GL_MODELVIEW)
- glLoadIdentity()
- glPushMatrix()
- glTranslated(-2 + pos[0], -2 + pos[1], -5 + pos[2])
- glRotatef(rot[0], 1, 0, 0)
- glRotatef(rot[1], 0, 1, 0)
- glRotatef(rot[2], 0, 0, 1)
- baseCube(isFramedMode)
- glPopMatrix()
- @window.event
- def on_resize(width, height):
- global ratio
- glViewport(0, 0, width, height)
- ratio = width / height
- @window.event
- def on_mouse_press(x, y, button, modifiers):
- global isFramedMode
- if button == mouse.LEFT:
- isFramedMode = not isFramedMode
- @window.event
- def on_key_press(symbol, modifiers):
- global pos
- if symbol == key.S:
- pos[1] -= 0.5
- elif symbol == key.W:
- pos[1] += 0.5
- elif symbol == key.D:
- pos[0] += 0.5
- elif symbol == key.A:
- pos[0] -= 0.5
- elif symbol == key.UP:
- pos[2] += 0.5
- elif symbol == key.DOWN:
- pos[2] -= 0.5
- elif symbol == key.Z:
- rot[0] -= 5
- elif symbol == key.X:
- rot[0] += 5
- elif symbol == key.C:
- rot[1] -= 5
- elif symbol == key.V:
- rot[1] += 5
- elif symbol == key.B:
- rot[2] -= 5
- elif symbol == key.N:
- rot[2] += 5
- pyglet.app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement