fast animation working
This commit is contained in:
62
pixelflut.py
62
pixelflut.py
@@ -8,13 +8,13 @@ import threading
|
||||
sizex = 800
|
||||
sizey = 600
|
||||
|
||||
|
||||
XSPLIT = 5
|
||||
YSPLIT = 5
|
||||
|
||||
threads = []
|
||||
|
||||
effectivex = sizex
|
||||
effectivey = sizey
|
||||
dirtybox = (0,0,sizex,sizey)
|
||||
|
||||
old_framebuffer = Image.new("RGBA", (sizex, sizey), None)
|
||||
framebuffer = Image.new("RGBA", (sizex, sizey), (0,0,0,0))
|
||||
@@ -48,8 +48,9 @@ class DrawThread(threading.Thread):
|
||||
global framebuffer
|
||||
for x in range(xfrom,xto):
|
||||
for y in range(yfrom,yto):
|
||||
value = b"%02X%02X%02X%02X"%framebuffer.getpixel((x,y))
|
||||
buf += b"PX %b %b %b\n"%(bytes(str(x), "ascii"),bytes(str(y+args.yoffset), "ascii"),value)
|
||||
if framebuffer.getpixel((x,y))[3] != 0:
|
||||
value = b"%02X%02X%02X%02X"%framebuffer.getpixel((x,y))
|
||||
buf += b"PX %d %d %b\n"%(x,y,value)
|
||||
|
||||
s.send(buf)
|
||||
while args.repeat:
|
||||
@@ -65,34 +66,41 @@ def draw():
|
||||
|
||||
threads = []
|
||||
|
||||
chunkxsize = effectivex//XSPLIT
|
||||
chunkysize = effectivey//YSPLIT
|
||||
dirtysizex = (dirtybox[2]-dirtybox[0])
|
||||
dirtysizey = (dirtybox[3]-dirtybox[1])
|
||||
|
||||
remainderx = effectivex % XSPLIT
|
||||
remaindery = effectivey % YSPLIT
|
||||
chunkxsize = dirtysizex//XSPLIT
|
||||
chunkysize = dirtysizey//YSPLIT
|
||||
|
||||
remainderx = dirtysizex % XSPLIT
|
||||
remaindery = dirtysizey % YSPLIT
|
||||
|
||||
offsetx = dirtybox[0]
|
||||
offsety = dirtybox[1]
|
||||
|
||||
xchunks = []
|
||||
ychunks = []
|
||||
remainingx = effectivex
|
||||
remainingy = effectivey
|
||||
|
||||
while remainingx > remainderx:
|
||||
start = effectivex - remainingx
|
||||
remainingx -= chunkxsize
|
||||
stop = effectivex - remainingx
|
||||
xchunks.append((start, stop))
|
||||
allocatedx = 0
|
||||
|
||||
remainingx = (dirtybox[2]-dirtybox[0])
|
||||
remainingy = (dirtybox[3]-dirtybox[0])
|
||||
|
||||
for i in range(dirtysizex//chunkxsize):
|
||||
start = offsetx + (i*chunkxsize)
|
||||
stop = offsetx + ((i+1)*chunkxsize)
|
||||
xchunks.append((start,stop))
|
||||
|
||||
if remainderx != 0:
|
||||
xchunks.append((effectivex-remainingx, effectivex))
|
||||
xchunks.append(((offsetx+dirtysizex)-remainderx, offsetx+remainderx))
|
||||
|
||||
while remainingy > remaindery:
|
||||
start = effectivey - remainingy
|
||||
remainingy -= chunkysize
|
||||
stop = effectivey - remainingy
|
||||
ychunks.append((start, stop))
|
||||
for i in range(dirtysizey//chunkysize):
|
||||
start = offsety + (i*chunkysize)
|
||||
stop = offsety + ((i+1)*chunkysize)
|
||||
ychunks.append((start,stop))
|
||||
|
||||
if remaindery != 0:
|
||||
ychunks.append((effectivey-remainingy, effectivey))
|
||||
ychunks.append(((offsety+dirtysizey)-remaindery, offsety+remaindery))
|
||||
|
||||
for xchunk in xchunks:
|
||||
for ychunk in ychunks:
|
||||
@@ -109,12 +117,16 @@ elif args.image:
|
||||
coordinates = (0,0)
|
||||
image = Image.open(str(args.image))
|
||||
framebuffer.paste(image)
|
||||
if not args.animate:
|
||||
effectivex = min(image.size[0], sizex)
|
||||
effectivey = min(image.size[1], sizey)
|
||||
if args.animate:
|
||||
dirtybox = (*coordinates, min(image.size[0]+coordinates[0], sizex), min(image.size[1]+coordinates[1], sizey))
|
||||
else:
|
||||
dirtybox = (0,0,min(image.size[0], sizex),min(image.size[1], sizey))
|
||||
draw()
|
||||
while args.animate:
|
||||
coordinates = (coordinates[0] + 5, coordinates[1] + 5)
|
||||
if coordinates[0] >= sizex or coordinates[1] >= sizey:
|
||||
break
|
||||
dirtybox = (*coordinates, min(image.size[0]+coordinates[0], sizex), min(image.size[1]+coordinates[1], sizey))
|
||||
framebuffer = Image.new("RGBA", (sizex, sizey), (0,0,0,0))
|
||||
framebuffer.paste(image, coordinates)
|
||||
draw()
|
||||
|
||||
Reference in New Issue
Block a user