# the old MS starfield screensaver
# https://www.reddit.com/r/Python/comments/495pum/remember_the_old_ms_starfield_screensaver_its/
import cv2
import math
import numpy as np
import random
stars = []
w,h = 1920, 1080
center = w/2,h/2
while True:
img = np.zeros((h,w,3),np.uint8)
color = random.randint(0,255),random.randint(0,255),random.randint(0,255)
stars.append((center[0]+160*random.random()-80, center[1]+90*random.random()-45, color, random.randint(1,5)))
old_stars = stars
stars = []
for f in old_stars:
distance = math.sqrt((f[0]-center[0])**2+(f[1]-center[1])**2)
dx = 15*math.sin((f[0]-center[0])/distance)
dy = 15*math.sin((f[1]-center[1])/distance)
g = f[0]+dx, f[1]+dy,f[2], f[3]
if distance < 2000: stars.append(g)
for f in stars:
cv2.circle(img,(int(f[0]),int(f[1])), f[3], f[2], thickness=-1)
cv2.imshow('img', img)
cv2.waitKey(1)