Repository navigation
Expand file tree
/
Copy pathsnow.py
More file actions
78 lines (55 loc) · 2.21 KB
/
Copy pathsnow.py
File metadata and controls
78 lines (55 loc) · 2.21 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
import random
import math
import arcade
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Snow"
class Snowflake:
def __init__(self):
self.x = 0
self.y = 0
def reset_pos(self):
self.y = random.randrange(SCREEN_HEIGHT, SCREEN_HEIGHT + 100)
self.x = random.randrange(SCREEN_WIDTH)
class MyGame(arcade.Window):
def __init__(self, width, height, title):
super().__init__(width, height, title)
self.shapes = arcade.ShapeElementList()
color2 = (215, 214, 255)
color1 = (0, 10, 12)
points = (0, 0), (SCREEN_WIDTH, 0), (SCREEN_WIDTH, SCREEN_HEIGHT), (0, SCREEN_HEIGHT)
colors = (color1, color1, color2, color2)
rect = arcade.create_rectangle_filled_with_colors(points, colors)
self.shapes.append(rect)
self.snowflake_list = None
def start_snowfall(self):
self.snowflake_list = []
for i in range(50):
snowflake = Snowflake()
snowflake.x = random.randrange(SCREEN_WIDTH)
snowflake.y = random.randrange(SCREEN_HEIGHT + 200)
snowflake.size = random.randrange(4)
snowflake.speed = random.randrange(20, 40)
snowflake.angle = random.uniform(math.pi, math.pi * 2)
self.snowflake_list.append(snowflake)
self.set_mouse_visible(False)
arcade.set_background_color(arcade.color.BLACK)
def on_draw(self):
arcade.start_render()
self.shapes.draw()
for snowflake in self.snowflake_list:
arcade.draw_circle_filled(snowflake.x, snowflake.y,
snowflake.size, arcade.color.WHITE)
def on_update(self, delta_time):
for snowflake in self.snowflake_list:
snowflake.y -= snowflake.speed * delta_time
if snowflake.y < 0:
snowflake.reset_pos()
snowflake.x += snowflake.speed * math.cos(snowflake.angle) * delta_time
snowflake.angle += 1 * delta_time
def main():
window = MyGame(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
window.start_snowfall()
arcade.run()
if __name__ == "__main__":
main()