Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimations.py
More file actions
Latest commit
181 lines (133 loc) · 5.29 KB
/
Copy pathAnimations.py
File metadata and controls
181 lines (133 loc) · 5.29 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
importrandom
importthreading
importtime
importDirection
importFrameCollection2DasFrames
importapi
classTickerAnimation(threading.Thread):
def__init__(self, game_name):
super(TickerAnimation, self).__init__()
self._stop_event=threading.Event()
self.game_name=game_name
defstop(self):
self._stop_event.set()
defstopped(self):
returnself._stop_event.is_set()
defrun(self):
forlinself.game_name:
foriinreversed(range(0, 8)): # range goes to 0 to 7 (always 1 less than given)
api.change_face(api.Face.FRONT, i, Frames.letter_to_frame(l))
sleep=0.3/len(self.game_name)
time.sleep(sleep)
api.change_face(api.Face.FRONT, i, Frames.empty)
time.sleep(0.5)
classRain(threading.Thread):
def__init__(self, intensity, cube_size, speed):
super(Rain, self).__init__()
self.intensity=int(intensity*10)
self.cube_size=cube_size
self.speed=int(speed*10)
self.rain_drops= []
self.fall_speed=1/ (self.cube_size-1)
defrun(self):
whileDirection.direction_p_1.value!=7:
forxinself.rain_drops:
api.cuboid_off(x, 1, 2, 1)
# Set new location for falling rain_drops
forrain_dropinself.rain_drops:
ifrain_drop[1] -self.fall_speed<0:
self.rain_drops.remove(rain_drop)
else:
rain_drop[1] -=self.fall_speed
forxinrange(self.intensity):
self.rain_drops=self.rain_drops+ [[random.random(), 1, random.random()]]
forxinself.rain_drops:
ifx[1] <1/ (self.cube_size-1):
api.cuboid_on(x, 1, 1, 1)
else:
api.cuboid_on(x, 1, 2, 1)
time.sleep(1/self.speed)
api.display(api.leds)
classSnow(threading.Thread):
def__init__(self, intensity, cube_size, speed):
super(Snow, self).__init__()
self.intensity=int(intensity*10)
self.cube_size=cube_size
self.speed=int(speed*10)
self.snow_drops= []
self.fall_speed=1/ (self.cube_size-1)
defrun(self):
whileDirection.direction_p_1.value!=7:
forxinself.snow_drops:
api.cuboid_off(x, 1, 1, 1)
forsnow_dropinself.snow_drops:
ifsnow_drop[1] -self.fall_speed<0:
self.snow_drops.remove(snow_drop)
else:
snow_drop[1] -=self.fall_speed
forxinrange(self.intensity):
self.snow_drops=self.snow_drops+ [[random.random(), 1, random.random()]]
forxinself.snow_drops:
api.cuboid_on(x, 1, 1, 1)
time.sleep(1/self.speed)
api.display(api.leds)
classFog:
def__init__(self, intensity, cube_size, speed):
super(Fog, self).__init__()
self.intensity=int(intensity*10)
self.cube_size=cube_size
self.speed=int(speed*10)
self.fog_stripes= []
self.fall_speed=1/ (self.cube_size-1)
defrun(self):
whileDirection.direction_p_1.value!=7:
forxinself.fog_stripes:
api.cuboid_off(x, 1, 1, 3)
forfog_stripeinself.fog_stripes:
iffog_stripe[2] +self.fall_speed>7:
self.fog_stripes.remove(fog_stripe)
else:
fog_stripe[2] +=self.fall_speed
forxinrange(self.intensity):
self.fog_stripes=self.fog_stripes+ [[random.random(), random.random(), random.random()]]
forxinself.fog_stripes:
api.cuboid_on(x, 1, 1, 3)
time.sleep(1/self.speed)
api.display(api.leds)
classClouds(threading.Thread):
def__init__(self, intensity, cube_size, speed):
super(Clouds, self).__init__()
self.intensity=int(intensity*10) %11
self.cube_size=cube_size
self.speed=int(speed*10) %11
self.cloud_stripes= []
self.fall_speed=1/ (self.cube_size-1)
defrun(self):
c=0
whileDirection.direction_p_1.value!=7:
forxinself.cloud_stripes:
api.cuboid_off(x, 2, 2, 3)
forcloud_stripeinself.cloud_stripes:
ifcloud_stripe[2] +self.fall_speed>1:
self.cloud_stripes.remove(cloud_stripe)
else:
cloud_stripe[2] +=self.fall_speed
ifc==0:
self.cloud_stripes=self.cloud_stripes+ [[random.random(), 1, 0]]
c+=1
elifc==11- (self.intensity%11):
c=0
else:
c+=1
forxinself.cloud_stripes:
api.cuboid_on(x, 2, 2, 3)
time.sleep(1/self.speed)
api.display(api.leds)
classSun(threading.Thread):
def__init__(self):
super(Sun, self).__init__()
defrun(self):
api.draw_sun([0.5, 0.5, 0.5], 8, 8, 8)
api.display(api.leds)
whileDirection.direction_p_1.value!=7:
time.sleep(0.5)