andreasKroepelin / polylux

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

Overlay images or absolute positioning? #157

Open kescobo opened 7 months ago

kescobo commented 7 months ago

I have a series of images that I'd like to animate in, but I'm not sure how to get them to occupy the same space. Eg, say I have

decision-tree_1

and

decision-tree_2

which together make

decision-tree_3

Is there a way to place one on top of the other in animation?

Of course, I can export the combined image (the 3rd) and do something like

#slide(title: [Decision trees])[
  #only(1)[#image("assets/decision-tree_1.png")]
  #only(2)[#image("assets/decision-tree_3.png")]
]

but that's less ideal.

andreasKroepelin commented 7 months ago

Can you look into the alternatives family of functions in the Polylux docs? They might do what you want.

kescobo commented 7 months ago

Not quite - You're right I could do that instead of the #only example at the end, but that still replaces once image with another, rather than stacking them. Eg

#slide(title: [Decision trees])[
  #alternatives[#image("assets/decision-tree_1.png")
  ][#image("assets/decision-tree_2.png")]
]

gives

image

Whereas I'd like it to be more like this on the second slide:

#slide(title: [Decision Trees])[
  #cetz.canvas({
    import cetz.draw: *
    // Your drawing code goes here
    content((0,0), [#image("assets/decision-tree_1.png")])
    content((0,0), [#image("assets/decision-tree_2.png")])
})
]

image

I've tried sticking the calls to #only and other timing functionality inside the cetz canvas, but they don't seem to do anything.

andreasKroepelin commented 7 months ago

Using alternatives-fn and then having an appropriate if block in the CeTZ code, deciding whether or not to draw the second image, might work.

kescobo commented 7 months ago

OK, I'll look into that, thanks!