-
Notifications
You must be signed in to change notification settings - Fork 1
async_rotate()
In addition to CanvasPlus.rotate(), asynchronous rotation is also possible, using the asyncio library.
from numbers import Real
from typing import Union, Tuple
async def async_rotate(self,
tagOrId: Union[int, str], x: Real, y: Real, time: float, amount: Real,
unit: str = "rad", warn: bool = True, fps: int = 24, update: bool = True
) -> Tuple[Union[float, int]]Asynchronously rotate tagOrId on axis x, y by amount in degrees or radians clockwise (use negaitves for counter-clockwise) fps: frames per second, time: specify the amount of time the animation shall take to complete, update: call update() method within loop
from CanvasPlus import CanvasPlus
from tkinter import Tk
import math
import asyncio
#set up canvas
root = Tk()
canvas = CanvasPlus(root, width = 800, height = 800, background = "white")
canvas.pack()
rect1 = canvas.create_polygon(300, 300, 300, 500, 500, 500, 500, 300, fill = "blue")
rect2 = canvas.clone(rect1)
rect3 = canvas.clone(rect1)
rect4 = canvas.clone(rect1)
async def _test():
await asyncio.gather(
canvas.async_rotate(rect1, 300, 300, 1, 2*math.pi, unit = "r", fps = 24),
canvas.async_rotate(rect2, 500, 500, 1, 2*math.pi, unit = "rad", fps = 24),
canvas.async_rotate(rect3, 300, 500, 1, 360, unit = "d", fps = 24),
canvas.async_rotate(rect4, 500, 300, 1, 360, unit = "deg", fps = 24)
)
await asyncio.gather(
canvas.async_rotate(rect1, 200, 200, .25, .5*math.pi, unit = "r", fps = 24),
canvas.async_rotate(rect2, 600, 600, .25, .5*math.pi, unit = "rad", fps = 24),
canvas.async_rotate(rect3, 200, 600, .25, 90, unit = "d", fps = 24),
canvas.async_rotate(rect4, 600, 200, .25, 90, unit = "deg", fps = 24)
)
await asyncio.gather(
canvas.async_rotate(rect1, 200, 200, .25, -.5*math.pi, unit = "r", fps = 24),
canvas.async_rotate(rect2, 600, 600, .25, -.5*math.pi, unit = "rad", fps = 24),
canvas.async_rotate(rect3, 200, 600, .25, -90, unit = "d", fps = 24),
canvas.async_rotate(rect4, 600, 200, .25, -90, unit = "deg", fps = 24)
)
asyncio.run(_test())
canvas.mainloop()
Note: The frame rates in this GIF do not accurately represent the actual frame rates, due to the nature of GIF images
Copyright (C) 2020 Luke Zhang
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the conditions at https://github.com/Luke-zhang-04/CanvasPlus/blob/master/LICENSE.