Advertisement
Void-voiD

Untitled

Mar 9th, 2020
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.44 KB | None | 0 0
  1. import pyglet
  2. from pyglet.gl import *
  3. from pyglet.window import key
  4. import math
  5. import numpy as np
  6. from pyglet.window import mouse
  7. import random
  8.  
  9. window = pyglet.window.Window(1000, 1000, resizable = True)
  10. window.set_minimum_size(144, 144)
  11. gl.glClearColor(0, 0.5, 0.8, 1)
  12.  
  13. pos = [0, 0, 0]
  14. isFramedMode = False
  15. 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]]
  16.  
  17.  
  18. def which(mode, first, second, third, fourth, color):
  19.     if mode:
  20.         glBegin(GL_LINE_LOOP)
  21.         glColor3f(0, 0, 0)
  22.     else:
  23.         glBegin(GL_POLYGON)
  24.         glColor3f(*color)
  25.  
  26.     glVertex3f(*first)
  27.     glVertex3f(*second)
  28.     glVertex3f(*third)
  29.     glVertex3f(*fourth)
  30.  
  31.     glEnd()
  32.  
  33.  
  34. def baseCube(framed):
  35.     lbf = [-0.5, -0.5, -0.5]
  36.     rbf = [0.5, -0.5, -0.5]
  37.     rtf = [0.5, 0.5, -0.5]
  38.     ltf = [-0.5, 0.5, -0.5]
  39.  
  40.     lbn = [-0.5, -0.5, 0.5]
  41.     rbn = [0.5, -0.5, 0.5]
  42.     rtn = [0.5, 0.5, 0.5]
  43.     ltn = [-0.5, 0.5, 0.5]
  44.  
  45.     # BOTTOM
  46.     which(framed, lbn, lbf, rbf, rbn, colors[0])
  47.  
  48.     # BACK
  49.     which(framed, lbf, ltf, rtf, rbf, colors[1])
  50.  
  51.     # LEFT
  52.     which(framed, lbn, lbf, ltf, ltn, colors[2])
  53.  
  54.     # RIGHT
  55.     which(framed, rbn, rbf, rtf, rtn, colors[3])
  56.  
  57.     # TOP
  58.     which(framed, ltn, ltf, rtf, rtn, colors[4])
  59.  
  60.     # FRONT
  61.     which(framed, lbn, ltn, rtn, rbn, colors[5])
  62.  
  63.  
  64. @window.event
  65. def on_draw():
  66.     global isFramedMode
  67.     window.clear()
  68.  
  69.     glMatrixMode(GL_PROJECTION)
  70.     glLoadIdentity()
  71.     gluPerspective(45, 1, 0.1, 100)
  72.  
  73.     glMatrixMode(GL_MODELVIEW)
  74.     glLoadIdentity()
  75.  
  76.     glPushMatrix()
  77.     glTranslated(-0.45, -0.45, -1.7)
  78.     glScaled(0.15, 0.15, 0.15)
  79.     baseCube(False)
  80.     glPopMatrix()
  81.  
  82.     glMatrixMode(GL_MODELVIEW)
  83.     glLoadIdentity()
  84.  
  85.     glPushMatrix()
  86.     glTranslated(-2 + pos[0], -2 + pos[1], -5 + pos[2])
  87.     baseCube(isFramedMode)
  88.     glPopMatrix()
  89.  
  90. @window.event
  91. def on_resize(width, height):
  92.     glViewport(0, 0, width, height)
  93.  
  94.  
  95. # @window.event
  96. # def on_mouse_press(x, y, button, modifiers):
  97.  
  98.  
  99. @window.event
  100. def on_key_press(symbol, modifiers):
  101.     global pos
  102.     if symbol == key.S:
  103.         pos[1] -= 0.5
  104.     elif symbol == key.W:
  105.         pos[1] += 0.5
  106.     elif symbol == key.D:
  107.         pos[0] += 0.5
  108.     elif symbol == key.A:
  109.         pos[0] -= 0.5
  110.     elif symbol == key.UP:
  111.         pos[2] += 0.5
  112.     elif symbol == key.DOWN:
  113.         pos[2] -= 0.5
  114.  
  115.  
  116. pyglet.app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement