-
Notifications
You must be signed in to change notification settings - Fork 2
/
snowin.py
70 lines (52 loc) · 1.49 KB
/
snowin.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
61
62
63
64
65
66
67
68
69
70
# This is a screensaver I made on accident trying to make a
# flying through space screen saver, kept it because vibes
import pygame
import random
# Initialize Pygame
pygame.init()
# Set the window size
window_size = (1800, 2000)
# Create the window
screen = pygame.display.set_mode(window_size, pygame.FULLSCREEN)
# Set the window title
pygame.display.set_caption("Snow Day")
# Set the background color
bg_color = (0, 0, 0)
# Set the number of stars
num_stars = 500
# Create the list of stars
stars = []
for i in range(num_stars):
x = random.randint(0, window_size[0])
y = random.randint(0, window_size[1])
size = random.randint(1, 3)
stars.append([x, y, size])
# Set the game clock
clock = pygame.time.Clock()
# Set the speed of the stars
speed = 100
# Set the game loop flag
running = True
# Start the game loop
while running:
# Handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Clear the screen
screen.fill(bg_color)
# Update the position of the stars
for star in stars:
star[1] += speed * clock.get_time() / 1000
if star[1] > window_size[1]:
star[1] = 0
star[0] = random.randint(0, window_size[0])
# Draw the stars
for star in stars:
pygame.draw.circle(screen, (255, 255, 255), (star[0], int(star[1])), star[2])
# Update the display
pygame.display.flip()
# Limit the frame rate
clock.tick(60)
# Quit Pygame
pygame.quit()