Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thug cat #25

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Teams/yellow_pirates/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
FROM python:3.11.4

RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir numpy pillow

RUN mkdir /app

COPY ./src/* /app

ENTRYPOINT ["python", "/app/main_color_gradient.py"]
# ENTRYPOINT sh -c "echo -en 'PX ${X} ${Y} ${COLOR}\n' | nc -q1 localhost 1234"
ENTRYPOINT ["python", "/app/c2.py"]
101 changes: 101 additions & 0 deletions Teams/yellow_pirates/src/c2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import socket
import sys
import numpy as np
from PIL import Image


HOST = "10.201.77.56" # localhost
PORT = 4321 # pixelflut-port

OFFSET_X=5
OFFSET_Y=365

CAT="images/cats.jpg"
THUG="images/thug.jpg"

def main():
img = openImage(CAT)
thug = openImage(THUG)
# withThug = addThug(img, thug, (50,0))
withThug = addThug(img, thug, (50,170))

images = []

for i in range(0, 170, 25):
images.append(addThug(img, thug, (50,i)))

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

fullSize = readSize(sock)
width, height = fullSize
offset = (OFFSET_X, OFFSET_Y)

for im in images:
writePx(offset, im, sock)

def addThug(img, thug, offset):
img2 = np.copy(img)
ox, oy = offset
for iy, ix, _ in np.ndindex(thug.shape):
color = thug[iy, ix]
if color[0] > 200 and color[1] > 200 and color[2] > 200:
continue
img2[iy+oy, ix+ox] = thug[iy, ix]
return img2


def openImage(path):
image = Image.open(path)
imgNumpy = np.asarray(image)
return imgNumpy


def readSize(sock):
msg = bytes(f"SIZE\n".encode("utf-8"))
sock.sendall(msg)
data = str(sock.recv(1024), "utf-8")
splits = data.split()
return (int(splits[1]), int(splits[2]))

def writePx(offset, canvas, sock):
msg = ""
for iy, ix, zz in np.ndindex(canvas.shape):
c = colorStr(canvas[iy, ix])
iy = iy + offset[1]
ix = ix + offset[0]
msg += writePxCmd(ix, iy, c)

msg = bytes(msg.encode('utf-8'))
sock.sendall(msg)

def writePxCmd(x: int, y: int, color) -> str:
return f"PX {x} {y} {color}\n"

def createColorGradient(size):
width, height = size
startColor = [255, 0, 0] # Red
endColor = [0, 0, 255] # Blue
canvas = createGradient(startColor, endColor, width, height)
return canvas

def colorStr(color):
r, g, b = color
return '%02x%02x%02x' % (r, g, b)

def createGradient(startColor, endColor, width, height):
start_rgb = np.array(startColor)
end_rgb = np.array(endColor)
gradient = np.zeros((height, width, 3), dtype=np.uint8)
for y in range(height):
for x in range(width):
factor = x / (width - 1)
color = (1 - factor) * start_rgb + factor * end_rgb
gradient[y, x, :] = color

return gradient



if __name__ == '__main__':
sys.exit(main())
Binary file added Teams/yellow_pirates/src/images/cats.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Teams/yellow_pirates/src/images/thug.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Loading