1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #!/usr/bin/env python3
- import pyglet
- from pyglet.window import key
- from pyglet.window import mouse
- import pyglet.graphics
- import pyglet.gl
- window = pyglet.window.Window()
- label = pyglet.text.Label('Hello, world',
- font_name = 'Times New Roman',
- font_size = 36,
- x = window.width//2, y = window.height // 2,
- anchor_x = 'center', anchor_y = 'center')
- vertex_list = pyglet.graphics.vertex_list(512, 'v2f', 'c3B')
- for i in range(512):
- vertex_list.vertices[i*2:i*2+2] = [i*1.0,i*1.5]
- vertex_list.colors[i*2:i*2+3] = [i % 250, i % 175, i % 100 ]
- @window.event
- def on_draw():
- window.clear()
- label.draw()
- vertex_list.draw(pyglet.gl.GL_POINTS)
- print(len(vertex_list.vertices))
- pyglet.graphics.draw_indexed(4, pyglet.gl.GL_TRIANGLES,
- [0,1,2,0,2,3],
- ('v2i', (100, 100,
- 150, 100,
- 150, 250,
- 200, 250)),
- ('c3B', (0,128,128,
- 128,0,128,
- 128,128,0,
- 85,85,85))
- )
- @window.event
- def on_key_press(symbol, modifiers):
- if symbol == key.A:
- print('The "A" key was pressed')
- elif symbol == key.LEFT:
- print('The left arrow key was pressed')
- elif symbol == key.ENTER:
- print('The enter key was pressed')
- @window.event
- def on_mouse_press(x, y, button, modifiers):
- if button == mouse.LEFT:
- print('The left mouse button was pressed at (%s,%s)' % (x, y))
- # x and y start at lower-left as origin
- pyglet.app.run()
|