diff --git a/Teams/green_twins/Dockerfile b/Teams/green_twins/Dockerfile index d92a948..f2246a7 100644 --- a/Teams/green_twins/Dockerfile +++ b/Teams/green_twins/Dockerfile @@ -1,8 +1,9 @@ -FROM subfuzion/netcat +FROM python:3.11.4 -ENV X=1285 -ENV Y=5 -ENV COLOR=02d10c +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/color_spectrum.py"] diff --git a/Teams/green_twins/src/color_spectrum.py b/Teams/green_twins/src/color_spectrum.py new file mode 100644 index 0000000..311cb84 --- /dev/null +++ b/Teams/green_twins/src/color_spectrum.py @@ -0,0 +1,75 @@ +import socket +import time + +HOST = "127.0.0.1" # localhost +# HOST = "10.201.77.56" # localhost +PORT = 4321 # pixelflut-port + +def get_draw_color_command(x,y,color): + return f"PX {x} {y} {color}" + +# def rgb(i): +# r = i % 256 +# g = (i//256) % 256 +# b = (i//256**2) % 256 +# print(f"{r} {g} {b}") +# return f"{format(r,'02X')}{format(g,'02X')}{format(b,'02X')}" + +def rgb(i): + red = 255 + green = 0 + blue = 0 + + if i > 0 and i <= 255: + red = 255 + green = i + blue = 0 + elif i > 255 and i <= 255*2: + red = 255*2 - i + green = 255 + blue = 0 + elif i > 255*2 and i <= 255*3: + red = 0 + green = 255 + blue = i - 255*2 + elif i > 255*3 and i <= 255*4: + red = 0 + green = 255*4 - i + blue = 255 + elif i > 255*4 and i <= 255*5: + red = i - 255*4 + green = 0 + blue = 255 + elif i > 255*5 and i <= 255*6: + red = 255 + green = i - 255*5 + blue = 255 + + + # print(f"{red} {green} {blue}") + + return f"{format(red,'02X')}{format(green,'02X')}{format(blue,'02X')}" + +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 + ## - Color the pixel at coordinate (x|y) in color c (format rrggbb): PX + ## - Get canvas size: SIZE + ## - Set offset of width w and height h for the duration of the connection: OFFSET + + x_offset = 0 + y_offset = 0 + for x in range(320): + # print(rgb(x)) + command = "\n".join([get_draw_color_command(x + x_offset,y+y_offset, rgb(x*4)) for y in range(180)]) + # print(command) + msg = bytes(f"{command}\n", "UTF-8") + sock.sendall(msg) + time.sleep(0.001) + + ## If you want to received messages, handling might look like this + # data = sock.rcv(1024) + # print(f"{data!r}") diff --git a/Teams/purple_saints/src/second.ts b/Teams/purple_saints/src/second.ts index 313bc95..a209a52 100644 --- a/Teams/purple_saints/src/second.ts +++ b/Teams/purple_saints/src/second.ts @@ -8,8 +8,8 @@ const host: string = '10.201.77.56'; const port: number = 4321; */ -const MAX_X: number = 1919; -const MAX_Y: number = 1079; +const MAX_X: number = 0; +const MAX_Y: number = 0; export async function mainSecond() { const socket = new Socket(); diff --git a/Teams/red_titans/Dockerfile b/Teams/red_titans/Dockerfile index 59e9481..3fde5ad 100644 --- a/Teams/red_titans/Dockerfile +++ b/Teams/red_titans/Dockerfile @@ -6,17 +6,14 @@ ENV Y=725 ENV COLOR=e07224 # Any working directory can be chosen as per choice like '/' or '/home' etc # i have chosen /usr/app/src -WORKDIR /usr/app/src +WORKDIR /usr/app/ #ENTRYPOINT sh -c "echo -en 'PX ${X} ${Y} ${COLOR}\n' | nc -q1 localhost 1234" -#to COPY the remote file at working directory in container -COPY Challenge1.py ./ -COPY simple_client.py ./ -COPY rgb.png ./ -# Now the structure looks like this '/usr/app/src/test.py' +RUN python3 -m venv .venv/ +RUN . .venv/bin/activate && pip install --upgrade Pillow +COPY src/ src/ -#CMD instruction should be used to run the software -#contained by your image, along with any arguments. +#CMD [ "python", "./Challenge1.py"] +#CMD [ "/usr/app/.venv/bin/python3", "/usr/app/src/RedBackground.py"] +CMD [ "/usr/app/.venv/bin/python3", "/usr/app/src/simple_client.py"] -CMD [ "python", "./Challenge1.py"] -CMD [ "python", "./simple_client.py"] diff --git a/Teams/red_titans/docker-compose.yml b/Teams/red_titans/docker-compose.yml new file mode 100644 index 0000000..d2741db --- /dev/null +++ b/Teams/red_titans/docker-compose.yml @@ -0,0 +1,11 @@ +version: '4' +services: + flut: + build: + context: . + dockerfile: Dockerfile + network_mode: host + volumes: + - ./src/:/usr/app/src/ + #command: "/usr/app/.venv/bin/python3 /usr/app/src/simple_client.py" + command: "/usr/app/.venv/bin/python3 /usr/app/src/simple_client.py" diff --git a/Teams/red_titans/simple_client.py b/Teams/red_titans/src/Challenge1.py similarity index 76% rename from Teams/red_titans/simple_client.py rename to Teams/red_titans/src/Challenge1.py index a3874a7..4112973 100644 --- a/Teams/red_titans/simple_client.py +++ b/Teams/red_titans/src/Challenge1.py @@ -3,7 +3,12 @@ from PIL import Image s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +<<<<<<<< HEAD:Teams/red_titans/src/simple_client.py +#s.connect(("10.201.77.56", 4321)) +s.connect(("127.0.0.1", 1234)) +======== s.connect(("127.0.0.0", 1234)) +>>>>>>>> main:Teams/red_titans/src/Challenge1.py def pixel(x,y,r,g,b,a=255): if a == 255: @@ -61,11 +66,17 @@ def worm(x,y,n,r,g,b): def blit(x, y, image): for ix in range(0, image.width): for iy in range(0, image.height): - r, g, b, _ = image.getpixel((ix,iy)) + r, g, b = image.getpixel((ix,iy)) pixel(ix,iy,r,g,b) -img = Image.open('rgb.png') +def clean(xmin, xmax, ymin, ymax): + for ix in range(xmin, xmax+1): + for iy in range(ymin, ymax+1): + pixel(ix,iy,0,0,0) + +#img = Image.open('src/rgb.png') +img = Image.open('src/rgb_3d_gradient.png') smallimg = img.resize((638,358)) +#blit(641,721,smallimg) blit(641,721,smallimg) - s.close() diff --git a/Teams/red_titans/src/PixelLib.py b/Teams/red_titans/src/PixelLib.py new file mode 100644 index 0000000..6b93520 --- /dev/null +++ b/Teams/red_titans/src/PixelLib.py @@ -0,0 +1,76 @@ +import socket +import random + +class PixelClass: + def __init__(self,xmin,xmax,ymin,ymax) -> None: + self.xmin = xmin + self.xmax = xmax + self.ymin = ymin + self.ymax = ymax + self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.s.connect(("127.0.0.0", 1234)) + + def pixel(self, x,y,r,g,b, a=255): + if a == 255: + self.s.send(f"PX {x} {y} {r:02x}{g:02x}{b:02x}\n".encode("utf-8")) + else: + self.s.send(f"PX {x} {y} {r:02x}{g:02x}{b:02x}{a:02x}\n".encode("utf-8")) + + def line(self, x1,y1,x2,y2,r,g,b): + x,y = x1,y1 + dx = abs(x2 - x1) + dy = abs(y2 -y1) + + if dx == 0: + self.rect(x1,y1,dy,1,r,g,b) + return + if dy == 0: + self.rect(x1,y1,1,dx,r,g,b) + return + + gradient = dy/float(dx) + + if gradient > 1: + dx, dy = dy, dx + x, y = y, x + x1, y1 = y1, x1 + x2, y2 = y2, x2 + + p = 2*dy - dx + + for k in range(2, dx + 2): + if p > 0: + y = y + 1 if y < y2 else y - 1 + p = p + 2 * (dy - dx) + else: + p = p + 2 * dy + + x = x + 1 if x < x2 else x - 1 + + self.pixel(x,y,r,g,b) + + def rect(self,x,y,w,h,r,g,b): + for i in range(x,x+w): + for j in range(y,y+h): + self.pixel(i,j,r,g,b) + + def worm(self,x,y,n,r,g,b): + while n: + rx = random.randint(0,200)-100 + ry = random.randint(0,200)-100 + self.line(x, y, x + rx, y + ry, r, g, b) + x += rx + y += ry + n -= 1 + + def blit(self, x, y, image): + for ix in range(0, image.width): + for iy in range(0, image.height): + r, g, b = image.getpixel((ix,iy)) + self.pixel(ix,iy,r,g,b) + + def clean(self): + for ix in range(self.xmin, self.xmax+1): + for iy in range(self.ymin, self.ymax+1): + self.pixel(ix,iy,0,0,0) + diff --git a/Teams/red_titans/Challenge1.py b/Teams/red_titans/src/RedBackground.py similarity index 89% rename from Teams/red_titans/Challenge1.py rename to Teams/red_titans/src/RedBackground.py index e89b5d2..61439eb 100644 --- a/Teams/red_titans/Challenge1.py +++ b/Teams/red_titans/src/RedBackground.py @@ -7,8 +7,8 @@ sock.connect((HOST, PORT)) XMIN=641 XMAX=1279 - YMIN=721 - YMAX=1079 + YMIN=0 + YMAX=719 for y in range(YMIN, YMAX+1): for x in range(XMIN, XMAX+1): msg = bytes(f"PX {x} {y} FF0000\n", "UTF-8") diff --git a/Teams/red_titans/rgb.png b/Teams/red_titans/src/rgb.png similarity index 100% rename from Teams/red_titans/rgb.png rename to Teams/red_titans/src/rgb.png diff --git a/Teams/red_titans/src/rgb_3d_gradient.png b/Teams/red_titans/src/rgb_3d_gradient.png new file mode 100644 index 0000000..2a9e076 Binary files /dev/null and b/Teams/red_titans/src/rgb_3d_gradient.png differ diff --git a/Teams/red_titans/src/simple_client.py b/Teams/red_titans/src/simple_client.py new file mode 100644 index 0000000..19cda09 --- /dev/null +++ b/Teams/red_titans/src/simple_client.py @@ -0,0 +1,86 @@ +import socket +import random +from PIL import Image + +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +#s.connect(("10.201.77.56", 4321)) +s.connect(("127.0.0.1", 1234)) + +def pixel(x,y,r,g,b,a=255): + if a == 255: + s.send(f"PX {x} {y} {r:02x}{g:02x}{b:02x}\n".encode("utf-8")) + else: + s.send(f"PX {x} {y} {r:02x}{g:02x}{b:02x}{a:02x}\n".encode("utf-8")) + +def line(x1,y1,x2,y2,r,g,b): + x,y = x1,y1 + dx = abs(x2 - x1) + dy = abs(y2 -y1) + + if dx == 0: + rect(x1,y1,dy,1,r,g,b) + return + if dy == 0: + rect(x1,y1,1,dx,r,g,b) + return + + gradient = dy/float(dx) + + if gradient > 1: + dx, dy = dy, dx + x, y = y, x + x1, y1 = y1, x1 + x2, y2 = y2, x2 + + p = 2*dy - dx + + for k in range(2, dx + 2): + if p > 0: + y = y + 1 if y < y2 else y - 1 + p = p + 2 * (dy - dx) + else: + p = p + 2 * dy + + x = x + 1 if x < x2 else x - 1 + + pixel(x,y,r,g,b) + +def rect(x,y,w,h,r,g,b): + for i in range(x,x+w): + for j in range(y,y+h): + pixel(i,j,r,g,b) + +def worm(x,y,n,r,g,b): + while n: + rx = random.randint(0,200)-100 + ry = random.randint(0,200)-100 + line(x, y, x + rx, y + ry, r, g, b) + x += rx + y += ry + n -= 1 + +def blit(x, y, image): + for ix in range(0, image.width): + for iy in range(0, image.height): + r, g, b = image.getpixel((ix,iy)) + pixel(ix,iy,r,g,b) + +def clean(xmin, xmax, ymin, ymax): + print("clean ...") + for ix in range(xmin, xmax+1): + for iy in range(ymin, ymax+1): + pixel(ix,iy,0,0,0) + +def run(): + #img = Image.open('src/rgb.png') + img = Image.open('src/rgb_3d_gradient.png') + smallimg = img.resize((638,358)) + #blit(641,721,smallimg) + blit(641,721,smallimg) + s.close() + + +if __name__ == "__main__": + #clean(0,1000,0,1000) + run() + s.close() \ No newline at end of file diff --git a/Teams/white_dodgers/Dockerfile b/Teams/white_dodgers/Dockerfile index 7610514..8334ea2 100644 --- a/Teams/white_dodgers/Dockerfile +++ b/Teams/white_dodgers/Dockerfile @@ -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"] diff --git a/Teams/white_dodgers/Java/Dockerfile b/Teams/white_dodgers/Java/Dockerfile new file mode 100644 index 0000000..44f19a5 --- /dev/null +++ b/Teams/white_dodgers/Java/Dockerfile @@ -0,0 +1,11 @@ +FROM eclipse-temurin:17-jdk-jammy as build + +COPY src/ColorSpectrum.java /src/ +RUN javac /src/ColorSpectrum.java && ls -al /src + +FROM eclipse-temurin:17-jdk-jammy + +COPY --from=build src/*.class /app/ + +ENTRYPOINT cd app && java ColorSpectrum + diff --git a/Teams/white_dodgers/Java/src/ColorSpectrum.java b/Teams/white_dodgers/Java/src/ColorSpectrum.java new file mode 100644 index 0000000..eaa9af3 --- /dev/null +++ b/Teams/white_dodgers/Java/src/ColorSpectrum.java @@ -0,0 +1,52 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.Socket; +import java.util.List; +import java.util.Random; + +public class ColorSpectrum { + + private static final String host = "127.0.0.1"; + private static final int port = 1234; + private static final List colors = List.of("00ff00", "e28211", "ff0000", "99b259", "0000ff"); + private static final int xOffset = 10; + private static final int yOffset = 10; + private static final int cubeSize = 5; + + public static void main(String[] args) throws IOException, InterruptedException { + + try (final Socket s = new Socket(host, port)) { + + System.out.println("Connected to Pixelflut server."); + final PrintWriter writer = new PrintWriter(s.getOutputStream()); + final InputStreamReader streamReader = new InputStreamReader(s.getInputStream()); + final BufferedReader reader = new BufferedReader(streamReader); + + writer.println("SIZE"); + writer.flush(); + final String[] answer = reader.readLine().split(" "); + System.out.printf("Detected size: %s x %s%n", answer[1], answer[2]); + + int xFieldWidth = (Integer.parseInt(answer[1]) / 3) / 2; + int yFieldWidth = (Integer.parseInt(answer[2]) / 3) / 2; + + System.out.printf("Our field size: %s x %s%n", xFieldWidth, yFieldWidth); + + System.out.println("Painting..."); + StringBuilder out = new StringBuilder(); + for (int x = 725; x < 725 + xFieldWidth; x++) { + Random random = new Random(); + int nextInt = random.nextInt(0xffffff + 1); + String colorCode = String.format("#%06x", nextInt); + for (int y = 5; y < 5 + yFieldWidth; y++) { + out.append(String.format("PX %d %d %s\n", x, y, colorCode.replace("#", ""))); + System.out.printf("Paining pixel at %s x %s%n", x, y); + } + } + writer.print(out); + writer.flush(); + } + } +} diff --git a/Teams/white_dodgers/src/task_01.py b/Teams/white_dodgers/src/task_01.py new file mode 100644 index 0000000..a7a6734 --- /dev/null +++ b/Teams/white_dodgers/src/task_01.py @@ -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 +# ## - Color the pixel at coordinate (x|y) in color c (format rrggbb): PX +# ## - Get canvas size: SIZE +# ## - Set offset of width w and height h for the duration of the connection: OFFSET + + +# 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 + ## - Color the pixel at coordinate (x|y) in color c (format rrggbb): PX + ## - Get canvas size: SIZE + ## - Set offset of width w and height h for the duration of the connection: OFFSET + + + 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}") diff --git a/Teams/yellow_pirates/Dockerfile b/Teams/yellow_pirates/Dockerfile index f7bd421..32cc8c9 100644 --- a/Teams/yellow_pirates/Dockerfile +++ b/Teams/yellow_pirates/Dockerfile @@ -9,4 +9,3 @@ COPY ./src/* /app # ENTRYPOINT sh -c "echo -en 'PX ${X} ${Y} ${COLOR}\n' | nc -q1 localhost 1234" ENTRYPOINT ["python", "/app/c2.py"] - diff --git a/Teams/yellow_pirates/src/main_color_gradient.py b/Teams/yellow_pirates/src/main_color_gradient.py new file mode 100644 index 0000000..4e70835 --- /dev/null +++ b/Teams/yellow_pirates/src/main_color_gradient.py @@ -0,0 +1,92 @@ + +import socket + +IP = "127.0.0.1" +PORT = 1234 + +OFFSET_X = 1 +OFFSET_Y = 360 + +class Connection: + def __init__(self, ip, port): + self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self._ip = ip + self._port = port + + def __enter__(self): + self._socket.connect((self._ip, self._port)) + return self + + def __exit__(self, *args): + if self._socket: + self._socket.close() + self._socket = None + + def get_canvas_size(self): + self._socket.send(b"SIZE\n") + + buf = "" + while True: + data = self._socket.recv(1024) + if not data: + break + buf += data.decode() + if "\n" in buf: + break + data = buf.split(" ") + return int(data[1]), int(data[2]) + + def set_offset(self, offset_x, offset_y): + cmd = f"OFFSET {int(offset_x)} {int(offset_y)}\n" + self._socket.send(cmd.encode()) + + def send_help(self): + self._socket.send(b"HELP\n") + + def send_set_pixels(self, x, y, color): + cmd = f"PX {x} {y} {color.upper()}\n" + self._socket.send(cmd.encode()) + + +RED = (0xFF, 0x00, 0x00) +GREEN = (0x00, 0xFF, 0x00) + +def interpolate_colors(initial_color, target_color, steps): + # get the total difference between each color channel + red_difference=target_color[0]-initial_color[0] + green_difference=target_color[1]-initial_color[1] + blue_difference=target_color[2]-initial_color[2] + + # divide the difference by the number of rows, so each color changes by this amount per row + red_delta = red_difference/steps + green_delta = green_difference/steps + blue_delta = blue_difference/steps + + # display the color for each row + interpolated = [] + for i in range(0, steps): + # apply the delta to the red, green and blue channels + interpolated.append((int(initial_color[0] + (red_delta * i)), + int(initial_color[1] + (green_delta * i)), + int(initial_color[2] + (blue_delta * i)))) + + return interpolated + +def main(): + with Connection(IP, PORT) as conn: + canvas_size = conn.get_canvas_size() + segment_size = (int((canvas_size[0] - 6 )/ 6), int((canvas_size[1] - 6)/ 6)) + + colors = interpolate_colors(RED, GREEN, segment_size[0]) + + while True: + color_itor = iter(colors) + for x in range(segment_size[0]): + color = next(color_itor) + for y in range(segment_size[1]): + conn.send_set_pixels(x + OFFSET_X, y + OFFSET_Y, f"{color[0]:0{2}x}{color[1]:0{2}x}{color[2]:0{2}x}") + + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/sample_code/Python/src/sample_client.py b/sample_code/Python/src/sample_client.py index 39b6ce2..21b3bcd 100644 --- a/sample_code/Python/src/sample_client.py +++ b/sample_code/Python/src/sample_client.py @@ -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 +# ## - Color the pixel at coordinate (x|y) in color c (format rrggbb): PX +# ## - Get canvas size: SIZE +# ## - Set offset of width w and height h for the duration of the connection: OFFSET + + +# 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 @@ -13,15 +32,36 @@ ## - Get canvas size: SIZE ## - Set offset of width w and height h for the duration of the connection: OFFSET - 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)