jupyter-widgets-contrib / ipycanvas

Interactive Canvas in Jupyter
https://ipycanvas.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
688 stars 64 forks source link

How to add transform to Path2D #305

Closed tongda closed 1 year ago

tongda commented 1 year ago

I am trying to build a tools that can draw, move and transform polygons on image using ipycanvas. Is there a way to add transform matrix to Path2D easily?

martinRenou commented 1 year ago

If you apply a transformation on the main canvas, do transformation do not apply on the path2d that you draw?

Did you try something that did not work?

tongda commented 1 year ago

It seems that applying a transformation on the main canvas will affect Path2D objects drawn afterwards, not the already drawn ones. However, I want to transform Path2D objects that already drawn on the canvas. Additionally, I want to transform objects individually.

martinRenou commented 1 year ago

However, I want to transform Path2D objects that already drawn on the canvas

Everything that is drawn on the canvas is not modifiable, it's completely static. You will need to clear the canvas and draw again with your transformation.

For applying individual transformations to your objects, you will have to save and restore the canvas state between draws. https://ipycanvas.readthedocs.io/en/latest/canvas_state.html

tongda commented 1 year ago

For applying individual transformations to your objects, you will have to save and restore the canvas state between draws. https://ipycanvas.readthedocs.io/en/latest/canvas_state.html

I see. Implementing an interactive polygon seems much more complex than I thought.

martinRenou commented 1 year ago

If you want to animate SVG shapes, you probably would like to have a look at https://github.com/cduck/drawSvg

tongda commented 1 year ago

Great, will look into it. Thank you.