Compare commits

..
4 Commits
Author SHA1 Message Date
Maya Herrscher de6736144b Reado parsing with argparse 2023-10-10 14:41:26 +02:00
Maya Herrscher bf04dfb46c Cat now says stuff 2023-10-10 14:37:37 +02:00
Maya Herrscher 17ff41b63e Add gitignore (maybe) 2023-10-10 11:52:07 +02:00
Maya Herrscher 80f871fb20 Add random cat images (untested!!) 2023-10-10 11:32:15 +02:00
4 changed files with 31 additions and 17 deletions

No files matched your search

+1
View File
@@ -0,0 +1 @@
__pycache__
Binary file not shown.
+4 -4
View File
@@ -6,13 +6,13 @@ from PIL import Image
import urllib.request import urllib.request
from io import BytesIO from io import BytesIO
def cat(h, w): def cat(w, h):
url = f'https://cataas.com/cat?width={w}&height={h}' url = f'https://cataas.com/cat/says/DOCHKATZE?size=100&width={w}?height={h}?text=cat'
resp = urllib.request.urlopen(url) resp = urllib.request.urlopen(url)
im_data = resp.read() im_data = resp.read()
im = Image.open(BytesIO(im_data)) im = Image.open(BytesIO(im_data))
im.show()
return im return im
if __name__ == "__main__": if __name__ == "__main__":
cat(1920,1080) cat = cat(1920,1080)
cat.show()
+26 -13
View File
@@ -7,23 +7,28 @@ import string
import numpy as np import numpy as np
from PIL import Image from PIL import Image
from cat import cat from cat import cat
import argparse
# open image to be sent # parser stuff
image = sys.argv[1] parser = argparse.ArgumentParser(
im = Image.open(image) prog='FluffyPixelfluter',
description='used to paint Pixelflut canvas',)
parser.add_argument('hostname')
parser.add_argument('port')
parser.add_argument('-i','--image')
parser.add_argument('-r','--random', action='store_true')
parser.add_argument('-c','--cat', action='store_true')
parser.add_argument('-wd','--width', default=0)
parser.add_argument('-ht','--height', default=0)
args = parser.parse_args()
pixels = list(im.getdata()) HOST, PORT = args.hostname, int(args.port)
width, height = im.size
pixels = [pixels[i * width:(i + 1) * width] for i in range(0,height)]
HOST, PORT = "px.oeinf.de", 1234
# change start point if requested # change start point if requested
starth, startw = 0, 0 starth = int(args.height)
if len(sys.argv) > 2: starth = int(sys.argv[2]) startw = int(args.width)
if len(sys.argv) > 3: startw = int(sys.argv[3])
rnd = False rnd = args.random
if len(sys.argv) > 4: rnd = sys.argv[4] == "rnd"
# Create a socket (SOCK_STREAM means a TCP socket) # Create a socket (SOCK_STREAM means a TCP socket)
# Connect to server and send data # Connect to server and send data
@@ -37,6 +42,14 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sizew = int(received.split(" ")[1]) sizew = int(received.split(" ")[1])
sizeh = int(received.split(" ")[2]) sizeh = int(received.split(" ")[2])
# open image to be sent or query a cat image
if args.cat: im = cat(sizew,sizeh)
elif image in args: im = Image.open(args.image)
pixels = list(im.getdata())
width, height = im.size
pixels = [pixels[i * width:(i + 1) * width] for i in range(0,height)]
# create list of stuff and shuffle if requested # create list of stuff and shuffle if requested
widthlist = list(range(0 + startw,min(int(sizew),(width+startw)))) widthlist = list(range(0 + startw,min(int(sizew),(width+startw))))
heightlist = list(range(0 + starth, min(int(sizeh),(height+starth)))) heightlist = list(range(0 + starth, min(int(sizeh),(height+starth))))