Skip to content

Commit

Permalink
Merge pull request #22 from NoobieBubie1/main
Browse files Browse the repository at this point in the history
Lets gooooooooo!!!
  • Loading branch information
cramosk authored Oct 27, 2023
2 parents 2d93dee + 0e4e62f commit e818e43
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Teams/red_titans/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ RUN . .venv/bin/activate && pip install --upgrade Pillow
COPY src/ src/

#CMD [ "python", "./Challenge1.py"]
CMD [ "/usr/app/.venv/bin/python3", "/usr/app/src/RedBackground.py"]
#CMD [ "/usr/app/.venv/bin/python3", "/usr/app/src/RedBackground.py"]
CMD [ "/usr/app/.venv/bin/python3", "/usr/app/src/simple_client.py"]

1 change: 1 addition & 0 deletions Teams/red_titans/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ services:
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"
5 changes: 5 additions & 0 deletions Teams/red_titans/src/Challenge1.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ def blit(x, y, image):
r, g, b = image.getpixel((ix,iy))
pixel(ix,iy,r,g,b)

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))
Expand Down
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)

24 changes: 18 additions & 6 deletions Teams/red_titans/src/simple_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,22 @@ def blit(x, y, image):
r, g, b = image.getpixel((ix,iy))
pixel(ix,iy,r,g,b)

#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)
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)

s.close()
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()

0 comments on commit e818e43

Please sign in to comment.