From 5f08380e94085270964a72c59f8502d3863e9989 Mon Sep 17 00:00:00 2001 From: Yannik Enss Date: Wed, 5 Feb 2020 13:37:03 +0100 Subject: [PATCH] bounce --- pixelflut.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pixelflut.py b/pixelflut.py index 5fabc09..1f3c0d6 100755 --- a/pixelflut.py +++ b/pixelflut.py @@ -32,11 +32,12 @@ effect.add_argument("--repeat", action="store_true") effect.add_argument("--animate", type=int, const=5, nargs='?', metavar="STEPSIZE") parser.add_argument("--bounce", action="store_true") +args = parser.parse_args() + if args.bounce and not args.animate: print("--bounce requires --animate") exit(1) -args = parser.parse_args() class DrawThread(threading.Thread): def run(self): @@ -118,6 +119,9 @@ if args.color: draw() elif args.image: + xfactor = 1 + yfactor = 1 + coordinates = (0,0) image = Image.open(str(args.image)) framebuffer.paste(image) @@ -126,10 +130,20 @@ elif args.image: else: dirtybox = (0,0,min(image.size[0], sizex),min(image.size[1], sizey)) draw() + while args.animate: - coordinates = (coordinates[0] + args.animate, coordinates[1] + args.animate) + coordinates = (coordinates[0] + args.animate * xfactor, coordinates[1] + args.animate * yfactor) if coordinates[0] >= sizex or coordinates[1] >= sizey: break + if args.bounce: + if coordinates[0] + image.size[0] >= sizex: + xfactor *= -1 + if coordinates[1] + image.size[1] >= sizey: + yfactor *= -1 + if coordinates[0] <= 0: + xfactor *= -1 + if coordinates[1] <= 0: + yfactor *= -1 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)