-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
559 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
Oops, something went wrong.