|
| 1 | +import pygame |
| 2 | +import math |
| 3 | +import pmma |
| 4 | +import time |
| 5 | +import random |
| 6 | + |
| 7 | +# Initialize Pygame |
| 8 | +pygame.init() |
| 9 | +pmma.init() |
| 10 | + |
| 11 | +# Screen settings |
| 12 | +screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) |
| 13 | +clock = pygame.time.Clock() |
| 14 | + |
| 15 | +# Circle settings |
| 16 | +NUM_CIRCLES = 15 |
| 17 | +SPEED = 0.01 # Rotation speed |
| 18 | +CIRCLE_RADIUS = 8 # Size of each circle |
| 19 | +HEX_STEPS = 6 # Six steps for hexagonal motion |
| 20 | +radius = 0 |
| 21 | + |
| 22 | +class Circle: |
| 23 | + def __init__(self, index, radius): |
| 24 | + """Initialize a circle at a fixed distance from the center.""" |
| 25 | + self.angle = index * (2 * math.pi / NUM_CIRCLES) |
| 26 | + self.index = index # Unique index for hexagonal stepping |
| 27 | + self.color = pmma.ColorConverter() |
| 28 | + self.radius = radius |
| 29 | + radius += CIRCLE_RADIUS |
| 30 | + self.angle = random.uniform(0, 2 * math.pi) # Random starting angle |
| 31 | + |
| 32 | + def update(self): |
| 33 | + """Update position following a hexagonal path while keeping distance constant.""" |
| 34 | + step_angle = (self.index % HEX_STEPS) * (math.pi / 3) # Six-step hexagonal movement |
| 35 | + hex_offset = math.sin(self.angle * HEX_STEPS) * (self.radius * 0.1) # Small hex variation |
| 36 | + |
| 37 | + x = screen.get_width() // 2 + (self.radius + hex_offset) * math.cos(self.angle + step_angle) |
| 38 | + y = screen.get_height() // 2 + (self.radius + hex_offset) * math.sin(self.angle + step_angle) |
| 39 | + |
| 40 | + pygame.draw.circle(screen, self.color.generate_color_from_perlin_noise(now_time / 7), (int(x), int(y)), CIRCLE_RADIUS) |
| 41 | + |
| 42 | + self.angle += SPEED # Rotate around the center |
| 43 | + |
| 44 | +circles = [] |
| 45 | +# Create circles |
| 46 | +for i in range(NUM_CIRCLES): |
| 47 | + radius += CIRCLE_RADIUS * 4 |
| 48 | + circles.append(Circle(i, radius)) |
| 49 | + |
| 50 | +running = True |
| 51 | +now_time = 0 |
| 52 | +start = time.perf_counter() |
| 53 | +while running: |
| 54 | + #screen.fill((0, 0, 0)) # Clear screen |
| 55 | + |
| 56 | + for circle in circles: |
| 57 | + circle.update() |
| 58 | + |
| 59 | + # Handle events |
| 60 | + for event in pygame.event.get(): |
| 61 | + if event.type == pygame.QUIT: |
| 62 | + running = False |
| 63 | + |
| 64 | + pygame.display.flip() |
| 65 | + clock.tick(60 * 2) # 60 FPS |
| 66 | + now_time = time.perf_counter() - start |
| 67 | +pygame.quit() |
0 commit comments