wordsalad.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python3
  2. import pyglet
  3. from pyglet.window import key
  4. from pyglet.window import mouse
  5. import pyglet.graphics
  6. import pyglet.gl
  7. window = pyglet.window.Window()
  8. label = pyglet.text.Label('Hello, world',
  9. font_name = 'Times New Roman',
  10. font_size = 36,
  11. x = window.width//2, y = window.height // 2,
  12. anchor_x = 'center', anchor_y = 'center')
  13. vertex_list = pyglet.graphics.vertex_list(512, 'v2f', 'c3B')
  14. for i in range(512):
  15. vertex_list.vertices[i*2:i*2+2] = [i*1.0,i*1.5]
  16. vertex_list.colors[i*2:i*2+3] = [i % 250, i % 175, i % 100 ]
  17. @window.event
  18. def on_draw():
  19. window.clear()
  20. label.draw()
  21. vertex_list.draw(pyglet.gl.GL_POINTS)
  22. print(len(vertex_list.vertices))
  23. pyglet.graphics.draw_indexed(4, pyglet.gl.GL_TRIANGLES,
  24. [0,1,2,0,2,3],
  25. ('v2i', (100, 100,
  26. 150, 100,
  27. 150, 250,
  28. 200, 250)),
  29. ('c3B', (0,128,128,
  30. 128,0,128,
  31. 128,128,0,
  32. 85,85,85))
  33. )
  34. @window.event
  35. def on_key_press(symbol, modifiers):
  36. if symbol == key.A:
  37. print('The "A" key was pressed')
  38. elif symbol == key.LEFT:
  39. print('The left arrow key was pressed')
  40. elif symbol == key.ENTER:
  41. print('The enter key was pressed')
  42. @window.event
  43. def on_mouse_press(x, y, button, modifiers):
  44. if button == mouse.LEFT:
  45. print('The left mouse button was pressed at (%s,%s)' % (x, y))
  46. # x and y start at lower-left as origin
  47. pyglet.app.run()