Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyglet
- from pyglet.gl import *
- from pyglet.window import key
- import math
- import numpy as np
- from pyglet.window import mouse
- import random
- window = pyglet.window.Window(1000, 1000, resizable = True)
- window.set_minimum_size(144, 144)
- gl.glClearColor(0, 0.5, 0.8, 1)
- pos = [0, 0, 0]
- isFramedMode = False
- colors = [[0.1, 0.7, 0.1], [0.25, 0.5, 0.25], [0.4, 0.5, 0.4], [0.55, 0.5, 0.55], [0.7, 0.5, 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 isFramedMode
- window.clear()
- glMatrixMode(GL_PROJECTION)
- glLoadIdentity()
- gluPerspective(45, 1, 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])
- baseCube(isFramedMode)
- glPopMatrix()
- @window.event
- def on_resize(width, height):
- glViewport(0, 0, width, height)
- # @window.event
- # def on_mouse_press(x, y, button, modifiers):
- @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
- pyglet.app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement