code additions/edits

This commit is contained in:
Yannik Enss
2020-02-04 22:06:34 +01:00
parent 8ff465aa04
commit 253fe5ba91

View File

@@ -11,6 +11,8 @@ sizey = 600
XSPLIT = 5 XSPLIT = 5
YSPLIT = 5 YSPLIT = 5
threads = []
effectivex = sizex effectivex = sizex
effectivey = sizey effectivey = sizey
@@ -26,6 +28,7 @@ parser.add_argument("--port", "-p", type=int, default="3141")
parser.add_argument("--dumb", action="store_true") parser.add_argument("--dumb", action="store_true")
parser.add_argument("--yoffset", default=19, type=int) parser.add_argument("--yoffset", default=19, type=int)
parser.add_argument("--repeat", action="store_true") parser.add_argument("--repeat", action="store_true")
parser.add_argument("--animate", action="store_true")
args = parser.parse_args() args = parser.parse_args()
@@ -36,7 +39,7 @@ class DrawThread(threading.Thread):
xto = self._kwargs["xto"] xto = self._kwargs["xto"]
yto = self._kwargs["yto"] yto = self._kwargs["yto"]
print(xfrom, xto, yfrom, yto) #print(xfrom, xto, yfrom, yto)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((args.host, args.port)) s.connect((args.host, args.port))
@@ -55,6 +58,13 @@ class DrawThread(threading.Thread):
s.close() s.close()
def draw(): def draw():
global threads
for thread in threads:
thread.join()
threads = []
chunkxsize = effectivex//XSPLIT chunkxsize = effectivex//XSPLIT
chunkysize = effectivey//YSPLIT chunkysize = effectivey//YSPLIT
@@ -71,26 +81,40 @@ def draw():
remainingx -= chunkxsize remainingx -= chunkxsize
stop = effectivex - remainingx stop = effectivex - remainingx
xchunks.append((start, stop)) xchunks.append((start, stop))
xchunks.append((remainingx-effectivex, effectivex))
if remainderx != 0:
xchunks.append((effectivex-remainingx, effectivex))
while remainingy > remaindery: while remainingy > remaindery:
start = effectivey - remainingy start = effectivey - remainingy
remainingy -= chunkysize remainingy -= chunkysize
stop = effectivey - remainingy stop = effectivey - remainingy
ychunks.append((start, stop)) ychunks.append((start, stop))
ychunks.append((remainingy-effectivey, effectivey))
if remaindery != 0:
ychunks.append((effectivey-remainingy, effectivey))
for xchunk in xchunks: for xchunk in xchunks:
for ychunk in ychunks: for ychunk in ychunks:
DrawThread(kwargs={"xfrom":xchunk[0], "xto":xchunk[1], "yfrom":ychunk[0], "yto":ychunk[1]}).start() threads.append(DrawThread(kwargs={"xfrom":xchunk[0], "xto":xchunk[1], "yfrom":ychunk[0], "yto":ychunk[1]}))
for thread in threads:
thread.start()
if args.color: if args.color:
framebuffer.paste(ImageColor.getrgb(args.color), (0,0,sizex,sizey)) framebuffer.paste(ImageColor.getrgb(args.color), (0,0,sizex,sizey))
draw() draw()
elif args.image: elif args.image:
coordinates = (0,0)
image = Image.open(str(args.image)) image = Image.open(str(args.image))
framebuffer.paste(image) framebuffer.paste(image)
if not args.animate:
effectivex = min(image.size[0], sizex) effectivex = min(image.size[0], sizex)
effectivey = min(image.size[1], sizey) effectivey = min(image.size[1], sizey)
draw() draw()
while args.animate:
coordinates = (coordinates[0] + 5, coordinates[1] + 5)
framebuffer = Image.new("RGBA", (sizex, sizey), (0,0,0,0))
framebuffer.paste(image, coordinates)
draw()