Skip to content

Commit

Permalink
lets goo
Browse files Browse the repository at this point in the history
  • Loading branch information
HalfUnitato committed Oct 27, 2023
1 parent 9d7b2c8 commit 3edab48
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 15 deletions.
13 changes: 7 additions & 6 deletions Teams/white_dodgers/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM subfuzion/netcat
FROM python:3.11.4

ENV X=5
ENV Y=725
ENV COLOR=e6e3e6
RUN mkdir /app

ENTRYPOINT sh -c "echo -en 'PX ${X} ${Y} ${COLOR}\n' | nc -q1 localhost 1234"
CMD []
COPY ./src/* /app

# RUN --network=host python src/sample_client.py

ENTRYPOINT ["python", "/app/sample_client.py"]
68 changes: 68 additions & 0 deletions Teams/white_dodgers/src/task_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import socket

# with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
# sock.connect((HOST, PORT))

# ## Commands available:
# ## - Get Help: HELP
# ## - Retrieve color value of pixel at coordinate (x|y): PX <x> <y>
# ## - Color the pixel at coordinate (x|y) in color c (format rrggbb): PX <x> <y> <c>
# ## - Get canvas size: SIZE
# ## - Set offset of width w and height h for the duration of the connection: OFFSET <w> <h>


# x_max = 1920;
# sock.sendall(b"SIZE\n")
# print(sock.recv(1024))
# sock.sendall(b"HELP\n")
# print(sock.recv(1024))

# import socket

HOST = "127.0.0.1" # localhost
PORT = 1234 # pixelflut-port

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect((HOST, PORT))

## Commands available:
## - Get Help: HELP
## - Retrieve color value of pixel at coordinate (x|y): PX <x> <y>
## - Color the pixel at coordinate (x|y) in color c (format rrggbb): PX <x> <y> <c>
## - Get canvas size: SIZE
## - Set offset of width w and height h for the duration of the connection: OFFSET <w> <h>


x_max = 1920
y_max = 1080


x_width = int(x_max / 6)
off_setx = x_width * 2
y_width = int(y_max / 6)
off_sety = y_width * 0
offset = f"OFFSET {0} {0}\n"

# sock.sendall(b"SIZE\n")
# print(sock.recv(1024))
# msg = bytes(f"PX 13 37 FF0000\n", "UTF-8")
send_text = offset
for x in range(x_width):
for y in range(y_width):
r = (off_setx+x) % 255
g = (off_sety+y) % 255
b = (off_setx+x) % 255
send_text += f"PX {off_setx+x} {off_sety+y} "+ f'{r:02x}'+ f'{g:02x}'+ f'{b:02x}'+ '\n'
# text = f"PX {y} {x} "+ f'{r:02x}'+ f'{g:02x}'+ f'{b:02x}'+ '\n'
# print(text)
# print(msg)
# sock.sendall(msg)
# print(text)
# print(sock.recv(1024))

send_text = bytes(send_text, "UTF-8")
sock.sendall(send_text)

## If you want to received messages, handling might look like this
# data = sock.rcv(1024)
# print(f"{data!r}")
58 changes: 49 additions & 9 deletions sample_code/Python/src/sample_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
import socket

# with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
# sock.connect((HOST, PORT))

# ## Commands available:
# ## - Get Help: HELP
# ## - Retrieve color value of pixel at coordinate (x|y): PX <x> <y>
# ## - Color the pixel at coordinate (x|y) in color c (format rrggbb): PX <x> <y> <c>
# ## - Get canvas size: SIZE
# ## - Set offset of width w and height h for the duration of the connection: OFFSET <w> <h>


# x_max = 1920;
# sock.sendall(b"SIZE\n")
# print(sock.recv(1024))
# sock.sendall(b"HELP\n")
# print(sock.recv(1024))

# import socket

HOST = "127.0.0.1" # localhost
PORT = 1234 # pixelflut-port

Expand All @@ -13,15 +32,36 @@
## - Get canvas size: SIZE
## - Set offset of width w and height h for the duration of the connection: OFFSET <w> <h>

sock.sendall(b"SIZE\n")
print(sock.recv(1024))

sock.sendall(b"OFFSET 20 20\n")
msg = bytes(f"PX 13 37 FF0000\n", "UTF-8")
sock.sendall(msg)

sock.sendall(b"PX 13 37\n")
print(sock.recv(1024))

x_max = 500 #1920
y_max = 5000 #1080

off_setx = int(x_max / 6 * 2)
off_sety = int(y_max / 6 * 0)
offset = f"OFFSET {0} {0}\n"

# sock.sendall(b"SIZE\n")
# print(sock.recv(1024))
# msg = bytes(f"PX 13 37 FF0000\n", "UTF-8")
send_text = offset
for x in range(x_max):
for y in range(y_max):
# print("a")
# print(sock.recv(1024))
# print("b")
r = x % 255 * 0
g = y % 255 * 0
b = x % 255 * 0
send_text += f"PX {x} {y} "+ f'{r:02x}'+ f'{g:02x}'+ f'{b:02x}'+ '\n'
# text = f"PX {y} {x} "+ f'{r:02x}'+ f'{g:02x}'+ f'{b:02x}'+ '\n'
# print(text)
# print(msg)
# sock.sendall(msg)
# print(text)
# print(sock.recv(1024))

send_text = bytes(send_text, "UTF-8")
sock.sendall(send_text)

## If you want to received messages, handling might look like this
# data = sock.rcv(1024)
Expand Down

0 comments on commit 3edab48

Please sign in to comment.