Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- import sys
- import time
- WIDTH, HEIGHT = 600, 700
- WHITE = (255, 255, 255)
- BLUE = (0,100,200)
- RAIN_DENSITY = 50
- rain=[]
- canvas = pygame.display.set_mode((WIDTH,HEIGHT))
- background = pygame.Surface((WIDTH,HEIGHT))
- pygame.display.set_caption('Rain')
- pygame.init()
- def quitGame():
- pygame.quit()
- sys.exit(0)
- class Drop():
- def __init__(self):
- pass
- def randomize(self):
- self.x = random.randint(0, WIDTH-2)
- self.y = random.randint(-700, -10)
- self.speed = random.randint(1, 2)
- return self.x, self.y, self.speed
- def update(self):
- self.y += self.speed
- self.dropRect = (self.x, self.y, 1, 20)
- if self.y > HEIGHT:
- drop.randomize()
- def show(self):
- pygame.draw.rect(canvas, BLUE, self.dropRect, 1)
- drop = Drop()
- for i in range(RAIN_DENSITY):
- drop.randomize()
- rain.append(Drop())
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- quitGame()
- canvas.blit(background, (0,0))
- for i in range(len(rain)):
- drop.update()
- drop.show()
- pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment