andreasKroepelin / polylux

A package for creating slides in Typst
https://polylux.dev/book
MIT License
1.08k stars 53 forks source link

Animate with Cetz #158

Open kescobo opened 3 months ago

kescobo commented 3 months ago

Attempting to deal with a similar use case as #157, though with some additional functionality, could it be possible to use polylux animations with cetz drawings (related discussion on cetz repo)?

I tried

#slide(title: [Packages])[
  #cetz.canvas({
    import cetz.draw: *
    content((0,0), [#only(1)[#image("assets/decision-tree_1.png")]])
    // Draw a circle and place its "west" anchor at the origin.
    circle((0,0), anchor: "west")
  }) 
]

but no dice. I don't understand the internals of either package enough to have a sense of what to do.

TakodaS commented 2 months ago
#let mycontent(show-image: true) = cetz.canvas(
  {
    if show-image {
      content((0, 0), [#image("assets/decision-tree_1.png")]) // Draw a circle and place its "west" anchor at the origin.
    };
    circle((0, 0), anchor: "west")
  },
)

//First way
#slide[
  #alternatives[#mycontent(show-image: true)][#mycontent(show-image: false)]
]

//Second way that might be too clever
#range(2).map(i =>slide[#mycontent(show-image: i == 0)]).join()

Touying allows you to insert pauses in CetZ diagrams https://github.com/touying-typ/touying

kescobo commented 2 months ago

Oh, very cool, thanks for the idea! I bet I could adapt that with a for loop to add a list of images...

And thanks for the link to touying - I see that it's also got pinit support, which I'm very keen on!