pyglet-cornerpin/examples/pattern.py

45 lines
929 B
Python
Raw Normal View History

2024-10-23 16:39:16 +02:00
import pyglet
2024-11-05 18:33:11 +01:00
from pyglet_cornerpin import PygletCornerPin
2024-10-23 16:39:16 +02:00
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()