Image File¶
This demo presents the image file scene in 2D and shows how the animation state evolves over time with lib-anim. The script defines a canva, adds the corresponding items, and updates them frame by frame to produce the final motion.

Full Code¶
1'''
22D image file demo
3'''
4
5import numpy as np
6import anim
7
8# ═══ 2D Animation canva ═══════════════════════════════════════════════════
9
10class Canva(anim.plane.canva):
11
12 # ────────────────────────────────────────────────────────────────────────
13 def __init__(self, window):
14
15 super().__init__(window, pixelperunit=1000)
16
17 self.period = 50
18
19 self.item.img = anim.plane.image(
20 file = 'demo/images/corgi.png',
21 position = [0.5, 0.5],
22 dimension = self.scale(0)
23 )
24
25 # ────────────────────────────────────────────────────────────────────────
26 def scale(self, t):
27
28 s = np.sin(t/self.period)/4 + 0.75
29 return (s,s)
30
31 # ────────────────────────────────────────────────────────────────────────
32 def update(self, t):
33
34 self.item.img.dimension = self.scale(t.step)
35
36 # Confirm update
37 super().update(t)
38
39# ═══ Main ═════════════════════════════════════════════════════════════════
40
41W = anim.window('Image animation')
42
43# Add animation
44W.add(Canva)
45
46# Allow backward animation
47W.allow_backward = True
48W.allow_negative_time = True
49
50W.show()