78 lines
1.3 KiB
Python
Executable File
78 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import socket
|
|
import random
|
|
|
|
IP_ADDRESS = "2001:638:904:ffc9::2"
|
|
PORT = 1234
|
|
|
|
W = 1920
|
|
H = 1080
|
|
|
|
s_w = 100
|
|
s_c = "BFFFD4"
|
|
s_c2 = "FFBFEA"
|
|
|
|
def color_to_tuple(color):
|
|
return (int(color[0:2], 16), int(color[2:4], 16), int(color[4:6], 16))
|
|
|
|
def merge_tuple(a, b, o):
|
|
return (o(a[0], b[0]),o(a[1], b[1]),o(a[2], b[2]))
|
|
|
|
def tuple_to_color(tuple):
|
|
return (str(hex(tuple[0]))[2:] + str(hex(tuple[1]))[2:] +str(hex(tuple[2]))[2:]).upper()
|
|
|
|
|
|
from_c = color_to_tuple(s_c)
|
|
to_c = color_to_tuple(s_c2)
|
|
|
|
diff_c = merge_tuple(from_c, to_c, lambda a,b : (b-a) // s_w)
|
|
|
|
print(from_c)
|
|
colors = []
|
|
for i in range(s_w):
|
|
c = merge_tuple(from_c, diff_c, lambda a,b: a + (b * i))
|
|
print(c)
|
|
colors.append(tuple_to_color(c))
|
|
|
|
print(to_c)
|
|
|
|
print(from_c, to_c, diff_c, colors)
|
|
|
|
|
|
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
|
s.connect((IP_ADDRESS, PORT))
|
|
|
|
x = W//2
|
|
y = H//2
|
|
d = 0
|
|
c = 0
|
|
|
|
while True:
|
|
|
|
if c < 0:
|
|
d = (d+random.randint(-1,1)) % 4
|
|
c = random.randint(80, 100)
|
|
|
|
if d == 0:
|
|
x += 0
|
|
y += -1
|
|
elif d == 1:
|
|
x += 1
|
|
y += 0
|
|
elif d == 2:
|
|
x += 0
|
|
y += 1
|
|
elif d == 3:
|
|
x += -1
|
|
y += 0
|
|
|
|
x = x%W
|
|
y = y%H
|
|
|
|
for i in range(s_w):
|
|
j = i - s_w//2
|
|
s.send("PX {} {} {}\n".format(x+j,y+j, colors[i]).encode("utf-8"))
|
|
|
|
c -= 1
|