bounce
This commit is contained in:
18
pixelflut.py
18
pixelflut.py
@@ -32,11 +32,12 @@ effect.add_argument("--repeat", action="store_true")
|
|||||||
effect.add_argument("--animate", type=int, const=5, nargs='?', metavar="STEPSIZE")
|
effect.add_argument("--animate", type=int, const=5, nargs='?', metavar="STEPSIZE")
|
||||||
parser.add_argument("--bounce", action="store_true")
|
parser.add_argument("--bounce", action="store_true")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.bounce and not args.animate:
|
if args.bounce and not args.animate:
|
||||||
print("--bounce requires --animate")
|
print("--bounce requires --animate")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
class DrawThread(threading.Thread):
|
class DrawThread(threading.Thread):
|
||||||
def run(self):
|
def run(self):
|
||||||
@@ -118,6 +119,9 @@ if args.color:
|
|||||||
draw()
|
draw()
|
||||||
|
|
||||||
elif args.image:
|
elif args.image:
|
||||||
|
xfactor = 1
|
||||||
|
yfactor = 1
|
||||||
|
|
||||||
coordinates = (0,0)
|
coordinates = (0,0)
|
||||||
image = Image.open(str(args.image))
|
image = Image.open(str(args.image))
|
||||||
framebuffer.paste(image)
|
framebuffer.paste(image)
|
||||||
@@ -126,10 +130,20 @@ elif args.image:
|
|||||||
else:
|
else:
|
||||||
dirtybox = (0,0,min(image.size[0], sizex),min(image.size[1], sizey))
|
dirtybox = (0,0,min(image.size[0], sizex),min(image.size[1], sizey))
|
||||||
draw()
|
draw()
|
||||||
|
|
||||||
while args.animate:
|
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:
|
if coordinates[0] >= sizex or coordinates[1] >= sizey:
|
||||||
break
|
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))
|
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 = Image.new("RGBA", (sizex, sizey), (0,0,0,0))
|
||||||
framebuffer.paste(image, coordinates)
|
framebuffer.paste(image, coordinates)
|
||||||
|
|||||||
Reference in New Issue
Block a user