-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpurple_rain.py
77 lines (63 loc) · 1.81 KB
/
purple_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python3
from random import randint , choice
try:
import pygame
except ImportError:
print("please install pygame module with 'pip install pygame'")
#classes
class Drop:
def __init__(self,surface , color , x, y , width , height ,gravity):
self.surface = surface
self.color = color
self.x = x
self.y = y
self.width = width
self.height = height
self.time = 0
self.g= gravity
def fall(self):
self.y =int( self.y + (self.g/2)*self.time**2 )
if self.y > 700:
self.y = -1*randint(300,1500)
self.time = 0.03
self.time += 0.01
pygame.draw.rect(self.surface , self.color ,[ self.x , self.y , self.width , self.height ])
#colors
#colors are in rgb (red , green , blue) format
gloomywhite = (220 , 220 , 220 )
white = (255 , 255 , 255)
un = (230, 230, 250)
purple = ( 138, 43, 226 )
blue = ( 0 , 0 , 230 )
rainblue = (36, 113, 163 )
clock = pygame.time.Clock()
#
pygame.init()
gamedisplay = pygame.display.set_mode((900,600))
pygame.display.set_caption('PurpleRain')
pygame.display.update()
gameexit = False
drops = []
widths = [i for i in range(1,5)]
heights = [i for i in range(15,40,4)]
gravities = [ i for i in range(2,20,4)]
size = list(zip(widths , heights,gravities))
#making the rain drops
for i in range(500):
x = randint(10,890)
y = -1*randint(300 , 1500)
width , height , g = choice(size)
raindrop = Drop(gamedisplay , purple,x,y,width , height,g)
drops.append(raindrop)
#main loop
while not gameexit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameexit=True
gamedisplay.fill(un)
for d in drops:
d.fall()
pygame.display.update()
clock.tick(70)
pygame.display.quit()
quit()