Skip to content

Instantly share code, notes, and snippets.

@nst
Last active November 15, 2024 14:38
Show Gist options
  • Save nst/b2b818c6c5c706b27ef6272a515ddc88 to your computer and use it in GitHub Desktop.
Save nst/b2b818c6c5c706b27ef6272a515ddc88 to your computer and use it in GitHub Desktop.
Reproduce an early 90s Macintosh screensaver
# Reproduce an early 90s Macintosh screensaver
# Nicolas Seriot 2024-11-13 https://seriot.ch
# https://x.com/nst021/status/1856605627264417931
import pygameimport pygame
import random
WIDTH = 800
HEIGHT = 600
NB_GROUPS = 4
NB_LINES_PER_GROUP = 6
vectors = []
lines_to_draw = []
for _ in range(NB_GROUPS):
vectors.append([random.randint(-10, 10), random.randint(-10, 10), random.randint(-10, 10), random.randint(-10, 10)])
lines_to_draw.append([random.randrange(WIDTH), random.randrange(HEIGHT), random.randrange(WIDTH), random.randrange(HEIGHT)])
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
screen.fill((0,0,0))
for g in range(NB_GROUPS):
next = lines_to_draw[2*g].copy()
v = vectors[g]
for i in range(4):
if next[i] + v[i] not in range(WIDTH if i % 2 == 0 else HEIGHT):
v[i] *= -1
next[i] += v[i]
lines_to_draw.insert(g, next)
lines_to_draw = lines_to_draw[:NB_LINES_PER_GROUP*NB_GROUPS]
for l in lines_to_draw:
pygame.draw.line(screen, (255,255,255), l[0:2], l[2:4])
pygame.display.update()
pygame.time.delay(100) # refresh ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment