Advertisement
Guest User

starfield

a guest
Mar 5th, 2016
1,642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import cv2
  2. import math
  3. import numpy as np
  4. import random
  5. stars = []
  6. w,h = 1920, 1080
  7. center = w/2,h/2
  8. while True:
  9.     img = np.zeros((h,w,3),np.uint8)
  10.     color = random.randint(0,255),random.randint(0,255),random.randint(0,255)
  11.     stars.append((center[0]+160*random.random()-80, center[1]+90*random.random()-45, color, random.randint(1,5)))
  12.     old_stars = stars
  13.     stars = []
  14.     for f in old_stars:
  15.         distance = math.sqrt((f[0]-center[0])**2+(f[1]-center[1])**2)
  16.         dx = 15*math.sin((f[0]-center[0])/distance)
  17.         dy = 15*math.sin((f[1]-center[1])/distance)
  18.         g = f[0]+dx, f[1]+dy,f[2], f[3]
  19.         if distance < 2000: stars.append(g)
  20.     for f in stars:
  21.         cv2.circle(img,(int(f[0]),int(f[1])), f[3], f[2], thickness=-1)
  22.     cv2.imshow('img', img)
  23.     cv2.waitKey(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement