Circle¶
This demo presents the circle 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 circle 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, **kwargs):
14
15 super().__init__(window,
16 boundaries = [[0, 1],[0,1]],
17 display_boundaries = True,
18 **kwargs)
19
20 # Number of ellipse per axis
21 self.a = 10
22
23 # Mesh size
24 self.b = 1/(self.a-1)
25
26 for i in range(self.a):
27 for j in range(self.a):
28
29 self.item[f'circle_{i}_{j}'] = anim.plane.circle(
30 position = [i*self.b, j*self.b],
31 radius = 0,
32 color = 'cyan' if (i+j)%2 else 'blue'
33 )
34
35
36 # ────────────────────────────────────────────────────────────────────────
37 def update(self, t):
38
39 for i in range(self.a):
40 for j in range(self.a):
41
42 shift = ((i + j) % 2)*np.pi/2
43 self.item[f'circle_{i}_{j}'].radius = self.b*(np.cos(t.step/30 + shift)*np.sqrt(2))/2
44
45 # Confirm update
46 super().update(t)
47
48# ═══ Main ═════════════════════════════════════════════════════════════════
49
50W = anim.window('Circle animation')
51
52# Add animation
53W.add(Canva)
54
55# Allow backward animation
56W.allow_backward = True
57W.allow_negative_time = True
58
59W.show()