Browse Source

Add random cat images (untested!!)

main
Maya Herrscher 2 years ago
parent
commit
80f871fb20
  1. BIN
      __pycache__/cat.cpython-39.pyc
  2. 3
      cat.py
  3. 18
      pixelflut.py

BIN
__pycache__/cat.cpython-39.pyc

Binary file not shown.

3
cat.py

@ -6,12 +6,11 @@ from PIL import Image
import urllib.request
from io import BytesIO
def cat(h, w):
def cat(w, h):
url = f'https://cataas.com/cat?width={w}&height={h}'
resp = urllib.request.urlopen(url)
im_data = resp.read()
im = Image.open(BytesIO(im_data))
im.show()
return im
if __name__ == "__main__":

18
pixelflut.py

@ -8,13 +8,6 @@ import numpy as np
from PIL import Image
from cat import cat
# open image to be sent
image = sys.argv[1]
im = Image.open(image)
pixels = list(im.getdata())
width, height = im.size
pixels = [pixels[i * width:(i + 1) * width] for i in range(0,height)]
HOST, PORT = "px.oeinf.de", 1234
@ -37,6 +30,17 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sizew = int(received.split(" ")[1])
sizeh = int(received.split(" ")[2])
# open image to be sent or query a cat image
if sys.argv[1] == 'cat':
im = cat(sizew,sizeh)
else:
image = sys.argv[1]
im = Image.open(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
widthlist = list(range(0 + startw,min(int(sizew),(width+startw))))
heightlist = list(range(0 + starth, min(int(sizeh),(height+starth))))

Loading…
Cancel
Save