python 旧的MS星空屏幕保护程序(https://www.reddit.com/r/Python/comments/495pum/remember_the_old_ms_starfield_sc

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 旧的MS星空屏幕保护程序(https://www.reddit.com/r/Python/comments/495pum/remember_the_old_ms_starfield_sc相关的知识,希望对你有一定的参考价值。

# 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)
    

以上是关于python 旧的MS星空屏幕保护程序(https://www.reddit.com/r/Python/comments/495pum/remember_the_old_ms_starfield_sc的主要内容,如果未能解决你的问题,请参考以下文章

Canvas星空效果(JS面向对象)

iOS 更新后保留旧的启动屏幕和应用程序图标

Python模拟星空

用Python画星空图,并且要求有月亮

保护旧的 Web 应用程序免受 CSRF 攻击,而无需在所有表单中添加隐藏输入

满天星空的代码实现