Advertisement
Void-voiD

Untitled

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