We value your privacy
This site uses cookies to improve your browsing experience, analyze site traffic, and show personalized content.
| No holders yet. | ||||||||||
import pygame import random # Initialize Pygame pygame.init() # Screen dimensions SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 # Colors BLACK = (0, 0, 0) WHITE = (255, 255, 255) STAR_COLORS = [(255, 255, 255), (255, 255, 102), (173, 216, 230)] # White, Yellow, Light Blue # Set up the display screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) pygame.display.set_caption('Grokkian Universe Simulator') class CelestialBody: def __init__(self, x, y, radius, color): self.x = x self.y = y self.radius = radius self.color = color self.speed = random.uniform(0.01, 0.1) # Random speed for some chaos def move(self): # Move in a sort of elliptical, chaotic path for fun self.x += self.speed * random.choice([-1, 1]) self.y += self.speed * random.choice([-1, 1]) self.x %= SCREEN_WIDTH # Wrap around screen self.y %= SCREEN_HEIGHT def draw(self, surface): pygame.draw.circle(surface, self.color, (int(self.x), int(self.y)), self.radius) # Create celestial bodies celestial_bodies = [CelestialBody( random.randint(0, SCREEN_WIDTH), random.randint(0, SCREEN_HEIGHT), random.randint(2, 10), # Small for 'stars', could be bigger for 'planets' random.choice(STAR_COLORS) ) for _ in range(100)] # Number of 'stars' or 'planets' # Main loop running = True clock = pygame.time.Clock() while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False screen.fill(BLACK) # The void of space for body in celestial_bodies: body.move() body.draw(screen) pygame.display.flip() clock.tick(60) # Frames per second, because even the universe has its limits pygame.quit()