Add Fairydust effect

This commit is contained in:
clerie 2021-10-30 19:26:14 +02:00
parent 3faf247aca
commit 7313bcc153

87
fairydust.py Executable file
View File

@ -0,0 +1,87 @@
#!/usr/bin/env python3
import time
import socket
import random
import math
IP_ADDRESS = "2001:638:904:ffc9::2"
PORT = 1234
W = 1920
H = 1080
s_w = 60
s_w_d = 9
s_c = "F904BC"
s_c2 = "F7B9E7"
target_x = random.randint(200, W-200)
target_y = random.randint(200, H-200)
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
s.connect((IP_ADDRESS, PORT))
x = random.randint(0, W)
y = random.randint(0, H)
d_x = 0
d_y = 0
step = 1
speed_x = 1
speed_y = 1
while True:
if x < target_x:
d_x += step
else:
d_x -= step
if y < target_y:
d_y += step
else:
d_y -= step
d_x += random.randint(-1,1)
d_y += random.randint(-1,1)
x += d_x
y += d_y
if d_x > 20:
d_x = 20
if d_y > 20:
d_y = 20
if x < 100 or x > W-100:
d_x = d_y//2
if y < 100 or y > H-100:
d_y = d_y//2
s_w = int(math.sqrt(d_x**2+d_y**2)*2)
s_w += s_w_d*2
s_r = s_w//2
s_r_q = s_r**2
out = []
for i in range(s_w):
for j in range(s_w):
if (i-s_r)**2 + (j-s_r)**2 <= s_r_q:
ii = i - s_w//2
jj = j - s_w//2
if (i-s_r)**2 + (j-s_r)**2 <= s_w_d:
c = s_c
else:
c = s_c2
out.append("PX {} {} {}\n".format(x+ii,y+jj, c))
frame_end_time = time.time() + 0.1
while time.time() < frame_end_time:
s.send("".join(out).encode("utf-8"))
#time.sleep(0.1)