forked from 3b1b/videos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbanner.py
137 lines (118 loc) · 3.98 KB
/
banner.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from __future__ import annotations
from manimlib.constants import *
from manimlib.mobject.coordinate_systems import NumberPlane
from manimlib.mobject.svg.tex_mobject import TexText
from manimlib.mobject.svg.text_mobject import Text
from manimlib.mobject.types.vectorized_mobject import VGroup
from manimlib.mobject.frame import FullScreenFadeRectangle
from manimlib.scene.scene import Scene
from custom.characters.pi_creature import Mortimer
from custom.characters.pi_creature import Randolph
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from manimlib.typing import Vect3
class Banner(Scene):
camera_config = dict(pixel_height=1440, pixel_width=2560)
pi_height = 1.25
pi_bottom = 0.25 * DOWN
use_date = False
message = "Animated Math"
date = "Sunday, February 3rd"
message_height = 0.4
add_supporter_note = False
pre_date_text = "Next video on "
def construct(self):
# Background
self.add(FullScreenFadeRectangle().set_fill(BLACK, 1))
plane = NumberPlane(
(-7, 7), (-5, 5),
height=10 * 1.5,
width=14 * 1.5,
axis_config=dict(stroke_color=BLUE_A),
faded_line_style=dict(
stroke_width=0.5,
stroke_opacity=0.35,
stroke_color=BLUE,
),
faded_line_ratio=4,
)
for line in plane.family_members_with_points():
line.set_stroke(width=line.get_stroke_width() / 2)
self.add(
plane,
# FullScreenFadeRectangle().set_fill(BLACK, 0.25),
)
# Pis
pis = self.get_pis()
pis.set_height(self.pi_height)
pis.arrange(RIGHT, aligned_edge=DOWN)
pis.move_to(self.pi_bottom, DOWN)
self.pis = pis
self.add(pis)
plane.move_to(pis.get_bottom() + SMALL_BUFF * DOWN)
# Message
message = self.get_message()
message.set_height(self.message_height)
message.next_to(pis, DOWN)
message.set_stroke(BLACK, 10, background=True)
self.add(message)
# Suppoerter note
if self.add_supporter_note:
note = self.get_supporter_note()
note.scale(0.5)
message.shift((MED_SMALL_BUFF - SMALL_BUFF) * UP)
note.next_to(message, DOWN, SMALL_BUFF)
self.add(note)
yellow_parts = [sm for sm in message if sm.get_color() == YELLOW]
for pi in pis:
if yellow_parts:
pi.look_at(yellow_parts[-1])
else:
pi.look_at(message)
def get_pis(self):
return VGroup(
Randolph(color=BLUE_E, mode="pondering"),
Randolph(color=BLUE_D, mode="hooray"),
Randolph(color=BLUE_C, mode="tease"),
Mortimer(color=GREY_BROWN, mode="thinking")
)
def get_message(self):
if self.message:
return Text(self.message)
if self.use_date:
return self.get_date_message()
else:
return self.get_probabalistic_message()
def get_probabalistic_message(self):
return Text(
"New video every day " + \
"(with probability 0.05)",
t2c={"Sunday": YELLOW},
)
def get_date_message(self):
return Text(
self.pre_date_text,
self.date,
t2c={self.date: YELLOW},
)
def get_supporter_note(self):
return OldTexText(
"(Available to supporters for review now)",
color="#F96854",
)
class CurrBanner(Banner):
camera_config: dict = {
"pixel_height": 1440,
"pixel_width": 2560,
}
pi_height: float = 1.25
pi_bottom: Vect3 = 0.25 * DOWN
use_date: bool = False
date: str = "Wednesday, March 15th"
message_scale_val: float = 0.9
add_supporter_note: bool = False
pre_date_text: str = "Next video on "
def construct(self):
super().construct()
for pi in self.pis:
pi.set_gloss(0.1)