45 lines
930 B
Python
45 lines
930 B
Python
|
import pyglet
|
||
|
from pyglet_corner_pin import PygletCornerPin
|
||
|
|
||
|
window = pyglet.window.Window()
|
||
|
|
||
|
|
||
|
# Generate a test pattern
|
||
|
batch = pyglet.graphics.Batch()
|
||
|
pattern = []
|
||
|
d = 20
|
||
|
y_steps = int(window.height / d)
|
||
|
x_steps = int(window.width / d)
|
||
|
colors = [
|
||
|
(255,255,255,255),
|
||
|
(180,180,180,180)
|
||
|
]
|
||
|
for i in range(y_steps+3):
|
||
|
y = int(i * d)
|
||
|
for j in range(x_steps+3):
|
||
|
x = int(j * d)
|
||
|
pattern.append(
|
||
|
pyglet.shapes.Rectangle(x,y, d,d, colors[(i+j) % len(colors)], batch=batch)
|
||
|
)
|
||
|
|
||
|
@window.event
|
||
|
def on_key_press(symbol, modifiers):
|
||
|
if symbol == pyglet.window.key.Q or symbol == pyglet.window.key.ESCAPE:
|
||
|
window.close()
|
||
|
exit()
|
||
|
|
||
|
|
||
|
pins = PygletCornerPin(window)
|
||
|
# event handlers for dragging:
|
||
|
window.push_handlers(pins)
|
||
|
|
||
|
@window.event
|
||
|
def on_draw():
|
||
|
window.clear()
|
||
|
# draw test pattern
|
||
|
batch.draw()
|
||
|
# draw corner pins
|
||
|
pins.draw()
|
||
|
|
||
|
|
||
|
pyglet.app.run()
|