Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. import pyglet
  2. from pyglet.gl import *
  3. from pyglet.window import key
  4. from pyglet.window import mouse
  5. from random import randint
  6.  
  7. window = pyglet.window.Window(900, 600, resizable=True)
  8. window.set_minimum_size(200, 100)
  9. colorStatus = 0
  10.  
  11. #batch = pyglet.graphics.Batch()
  12. #hexo = batch.add(6, pyglet.gl.GL_POLYGON, None, ('v2i', (300, 300, 375, 175, 525, 175, 600, 300, 525, 425, 375, 425)),
  13. #('c3B', (0, 0, 20, 11, 107, 85, 50, 0, 115, 127, 4, 4, 20, 1, 1, 0, 12, 17)))
  14.  
  15. @window.event
  16. def on_draw():
  17. #window.clear()
  18. #batch.draw()
  19.  
  20. if colorStatus == 0:
  21. glColor3b(randint(0, 255), randint(0, 255), randint(0, 255))
  22. elif colorStatus != 0:
  23. glColor3b(randint(0, 255), randint(0, 255), randint(0, 255))
  24. glClear(GL_COLOR_BUFFER_BIT)
  25. glBegin(GL_POLYGON)
  26. glVertex2f(300, 300)
  27. glVertex2f(375, 175)
  28. glVertex2f(525, 175)
  29. glVertex2f(600, 300)
  30. glVertex2f(525, 425)
  31. glVertex2f(375, 425)
  32. glEnd()
  33.  
  34.  
  35.  
  36.  
  37.  
  38. @window.event
  39. def on_resize(width, height):
  40. glViewport(0, 0, width, height)
  41.  
  42.  
  43. #@window.event
  44. #def on_mouse_press(x, y, button, modifiers):
  45. #if button == mouse.LEFT:
  46. #hexo.delete()
  47. #batch.add(6, pyglet.gl.GL_POLYGON, None, ('v2i', (300, 300, 375, 175, 525, 175, 600, 300, 525, 425, 375, 425)),
  48. #('c3B', (0, 0, 25, 11, 107, 85, 50, 0, 15, 127, 4, 4, 20, 130, 1, 0, 12, 17)))
  49.  
  50. @window.event
  51. def on_mouse_press(x, y, button, modifiers):
  52. global colorStatus
  53. if button == mouse.LEFT:
  54. colorStatus += 1
  55.  
  56.  
  57. @window.event
  58. def on_key_press(symbol, modifiers):
  59. if (symbol == key.RIGHT) | (symbol == key.D):
  60. glTranslatef(100, 0, 0)
  61. elif (symbol == key.LEFT) | (symbol == key.A):
  62. glTranslatef(-100, 0, 0)
  63. elif (symbol == key.UP) | (symbol == key.W):
  64. glTranslatef(0, 100, 0)
  65. elif (symbol == key.DOWN) | (symbol == key.S):
  66. glTranslatef(0, - 100, 0)
  67.  
  68.  
  69. pyglet.app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement