Last active
January 1, 2025 20:14
-
-
Save nst/65c1d4dbe207ec5ae269b767bbdd4a15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
import random | |
WIDTH, HEIGHT = 800, 600 | |
NB_GROUPS, NB_LINES_PER_GROUP = 4, 6 | |
vectors, lines = [], [] | |
def next(l, v): | |
for i in range(4): | |
v[i] *= -1 if l[i] + v[i] not in range(WIDTH if i % 2 == 0 else HEIGHT) else 1 | |
return [l[i] + v[i] for i in range(4)] | |
for _ in range(NB_GROUPS): | |
vectors.append([random.randint(-10, 10)]*4) | |
lines.append([random.randrange(x) for x in [WIDTH, HEIGHT, WIDTH, HEIGHT]]) | |
pygame.init() | |
screen = pygame.display.set_mode((WIDTH, HEIGHT)) | |
while True: | |
new_lines = [next(lines[g], vectors[g]) for g in range(NB_GROUPS)] | |
lines = new_lines + lines[:(NB_LINES_PER_GROUP-1)*NB_GROUPS] | |
screen.fill((0,0,0)) | |
for l in lines: | |
pygame.draw.line(screen, (255,255,255), l[0:2], l[2:4]) | |
pygame.display.update() | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
pygame.quit() | |
pygame.time.delay(100) # refresh ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment