-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrain_animation.py
49 lines (38 loc) · 1.53 KB
/
rain_animation.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
import random
import sculpy
class RainAnimation(sculpy.ShaderStyleAnimation):
def __init__(self, row_count, column_count):
super().__init__(row_count, column_count)
self.ball_states = []
for _ in range(0, row_count):
ball_states_row = []
for _ in range(0, column_count):
ball_states_row.append(None)
self.ball_states.append(ball_states_row)
def get_ball_position(self, row, column, timestamp, time_delta, last_position):
top = 0.0
bottom = -90000.0
base_velocity = 1500.0
if timestamp == 0.0:
return top
ball_state = self.ball_states[row][column]
max_velocity = base_velocity + (375.0 * (self.column_count - column - 1))
new_position = last_position
if ball_state is None:
if random.randrange(0, 500) == 0:
ball_state = False
elif ball_state == False:
velocity = sculpy.map_range_clamp(top, bottom * 0.10, base_velocity * 0.5, max_velocity, last_position)
new_position -= velocity * time_delta
if new_position <= bottom:
new_position = bottom
ball_state = True
elif ball_state == True:
velocity = max_velocity
new_position += velocity * time_delta
if new_position >= top:
new_position = top
ball_state = None
self.ball_states[row][column] = ball_state
return new_position
ANIMATION_CLASS = RainAnimation