| 1 |
import random |
| 2 |
|
| 3 |
import pyglet |
| 4 |
|
| 5 |
window = pyglet.window.Window(vsync=False) |
| 6 |
|
| 7 |
|
| 8 |
pyglet.resource.path = ['../resources'] |
| 9 |
pyglet.resource.reindex() |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
image = pyglet.resource.image("pyglet.png") |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
image.anchor_x = image.width // 2 |
| 19 |
image.anchor_y = image.height // 2 |
| 20 |
|
| 21 |
|
| 22 |
batch = pyglet.graphics.Batch() |
| 23 |
|
| 24 |
scales = [1.0, 0.75, 0.5, 0.25] |
| 25 |
|
| 26 |
sprites = [] |
| 27 |
|
| 28 |
for i in range(1000): |
| 29 |
sprite = pyglet.sprite.Sprite(image, |
| 30 |
x=random.randint(0, window.width), |
| 31 |
y=random.randint(0, window.height), |
| 32 |
batch=batch) |
| 33 |
|
| 34 |
|
| 35 |
sprite.scale = random.choice(scales) |
| 36 |
|
| 37 |
|
| 38 |
sprite.color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) |
| 39 |
|
| 40 |
|
| 41 |
sprites.append(sprite) |
| 42 |
|
| 43 |
|
| 44 |
@window.event |
| 45 |
def on_draw(): |
| 46 |
window.clear() |
| 47 |
batch.draw() |
| 48 |
|
| 49 |
|
| 50 |
pyglet.app.run() |