-
Notifications
You must be signed in to change notification settings - Fork 0
/
bouncing_dvd_logo.py
54 lines (43 loc) · 1.22 KB
/
bouncing_dvd_logo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import random
from manim import *
colors = [
BLUE_A,
BLUE_C,
BLUE_E,
GOLD,
GREEN,
MAROON,
ORANGE,
RED,
YELLOW,
PURPLE,
TEAL,
PINK,
WHITE,
DARK_BROWN,
]
class BouncingDVDLogo(MovingCameraScene):
def construct(self):
dvd_logo = ImageMobject("dvd_logo.png").scale(0.1).set_color(WHITE)
dvd_logo.move_to([1.5, 0, 0])
velocity = 0.03 * UR
right_most, top_most, _ = self.camera.frame.get_corner(UR)
left_most, bottom_most, _ = self.camera.frame.get_corner(DL)
def update_logo(obj, velocity):
if (
obj.get_corner(UR)[0] >= right_most
or obj.get_corner(DL)[0] <= left_most
):
velocity[0] = -velocity[0]
obj.set_color(random.choice(colors))
if (
obj.get_corner(UR)[1] >= top_most
or obj.get_corner(DL)[1] <= bottom_most
):
velocity[1] = -velocity[1]
obj.set_color(random.choice(colors))
obj.shift(velocity)
self.add(dvd_logo)
self.play(
UpdateFromFunc(dvd_logo, lambda x: update_logo(x, velocity)), run_time=60
)