pyglet-cornerpin/examples/pattern.py

45 lines
1 KiB
Python
Raw Normal View History

2024-10-23 14:39:16 +00:00
import pyglet
2024-11-05 17:33:11 +00:00
from pyglet_cornerpin import PygletCornerPin
2024-10-23 14:39:16 +00: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()
2024-11-11 09:31:44 +00:00
pins = PygletCornerPin(window, corners=[[100,100],[800,100],[150,500], [300,300]], source_points=[[100,100], [700,100], [100,500], [300,300]])
2024-10-23 14:39:16 +00:00
# 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()