Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- pygame.init()
- width = 1280
- height = 720
- screen = pygame.display.set_mode((width,height))
- white = (255,255,255)
- black = (0,0,0)
- running = True
- stars = []
- center_x = width//2
- center_y = height//2
- radius = 10
- class Star:
- def __init__(self):
- self.x = random.randint(-width,width)
- self.y = random.randint(-height,height)
- self.z = random.randint(center_y,width)
- self.pz = self.z
- def update(self):
- self.z -= 10
- if self.z < 1: # when our z is reduced too much instead of crashing we remake the points to be at random new spots, this also saves us from having to make a new star too
- self.x = random.randint(-width, width)
- self.y = random.randint(-height, height)
- self.z = random.randint(center_y, width)
- self.pz = self.z
- def show(self):
- sx = self.x / self.z * center_y + center_x
- sy = self.y / self.z * center_y + center_y
- pygame.draw.circle(screen, white, (sx,sy), radius)
- for i in range(0,26):
- stars.append(Star()) # add 100 random stars to our list
- while running:
- screen.fill(black)
- for star in stars:
- star.update()
- star.show()
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement