clerie-flut/snake.py

50 lines
711 B
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 = 10
s_c = "FFC0CB"
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, s_c).encode("utf-8"))
c -= 1