-
Notifications
You must be signed in to change notification settings - Fork 33
/
Raspberry_Rain.py
61 lines (47 loc) · 1.53 KB
/
Raspberry_Rain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python
from __future__ import absolute_import, division, print_function, unicode_literals
"""
Simple Sprite objects fall across the screen and are moved back to the top once
they hit the bottom edge.
"""
import random, time
import demo
import pi3d
# Set last value (alpha) to zero for a transparent background!
BACKGROUND = (0.0, 0.0, 0.0, 0.0)
# Setup display and initialise pi3d and a shader.
DISPLAY = pi3d.Display.create(background=BACKGROUND, frames_per_second=20)
SHADER = pi3d.Shader('uv_flat')
TEXTURE = pi3d.Texture('textures/Raspi256x256.png')
BERRY_COUNT = 20
# Setup array of random x,y,z coords and initial rotation
RASPBERRIES = []
for b in range(BERRY_COUNT):
# Select size as a random number 0.2 and 2.5.
size = random.uniform(0.5, 2.5)
rasp = pi3d.ImageSprite(texture=TEXTURE, shader=SHADER, w=size, h=size)
# distance from the camera.
dist = random.uniform(2.0, 10.0)
rasp.position(random.uniform(-1.0, 1.0) * dist,
random.uniform(0.0, 4.0) * dist,
dist)
rasp.rotateToZ(random.uniform(0.0, 360.0))
RASPBERRIES.append(rasp)
DISPLAY.add_sprites(rasp)
# Fetch key presses
KEYBOARD = pi3d.Keyboard()
while DISPLAY.loop_running():
for b in RASPBERRIES:
b.translateY(-0.1)
b.rotateIncZ(1)
if b.y() < -2 * b.z():
b.positionX((random.uniform(0.0, 2.0) - 1) * b.z())
b.translateY(4.0 * b.z())
k = KEYBOARD.read()
if k >-1:
if k == 27:
KEYBOARD.close()
DISPLAY.stop()
break
elif k == 112:
pi3d.screenshot('raspberryRain.jpg')