Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
KJoke70 authored Oct 27, 2023
2 parents 0335fd0 + bcaca8d commit 7d5162b
Show file tree
Hide file tree
Showing 18 changed files with 559 additions and 39 deletions.
13 changes: 7 additions & 6 deletions Teams/green_twins/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=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"]
75 changes: 75 additions & 0 deletions Teams/green_twins/src/color_spectrum.py
Original file line number Diff line number Diff line change
@@ -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 <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_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}")
4 changes: 2 additions & 2 deletions Teams/purple_saints/src/second.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 7 additions & 10 deletions Teams/red_titans/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
11 changes: 11 additions & 0 deletions Teams/red_titans/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
76 changes: 76 additions & 0 deletions Teams/red_titans/src/PixelLib.py
Original file line number Diff line number Diff line change
@@ -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)

Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
File renamed without changes
Binary file added Teams/red_titans/src/rgb_3d_gradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions Teams/red_titans/src/simple_client.py
Original file line number Diff line number Diff line change
@@ -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()
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"]
11 changes: 11 additions & 0 deletions Teams/white_dodgers/Java/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Loading

0 comments on commit 7d5162b

Please sign in to comment.