Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Refactor of confetti

Grant Sanderson797def9621ca
diff --git a/old_projects/efvgt.py b/old_projects/efvgt.py
index 4564acccd..0c6831e6e 100644
--- a/old_projects/efvgt.py
+++ b/old_projects/efvgt.py
@@ -92,6 +92,30 @@ class ConfettiSpiril(Animation):
self.mobject.rotate(angle, axis = UP, about_point = start_center)
self.mobject.shift(vert_shift*DOWN)
+def get_confetti_animations(num_confetti_squares):
+ colors = [RED, YELLOW, GREEN, BLUE, PURPLE, RED]
+ confetti_squares = [
+ Square(
+ side_length = 0.2,
+ stroke_width = 0,
+ fill_opacity = 0.75,
+ fill_color = random.choice(colors),
+ )
+ for x in range(num_confetti_squares)
+ ]
+ confetti_spirils = [
+ ConfettiSpiril(
+ square,
+ x_start = 2*random.random()*SPACE_WIDTH - SPACE_WIDTH,
+ rate_func = squish_rate_func(lambda t : t, a, a+0.5)
+ )
+ for a, square in zip(
+ np.linspace(0, 0.5, num_confetti_squares),
+ confetti_squares
+ )
+ ]
+ return confetti_spirils
+
class Anniversary(TeacherStudentsScene):
CONFIG = {
"num_confetti_squares" : 50,
@@ -118,7 +142,9 @@ class Anniversary(TeacherStudentsScene):
first_video.add(formula)
hats = self.get_party_hats()
- confetti_spirils = self.get_confetti_animations()
+ confetti_spirils = get_confetti_animations(
+ self.num_confetti_squares
+ )
self.play(
Write(title, run_time = 2),
*[
@@ -186,30 +212,6 @@ class Anniversary(TeacherStudentsScene):
)
return hats
- def get_confetti_animations(self):
- colors = [RED, YELLOW, GREEN, BLUE, PURPLE, RED]
- confetti_squares = [
- Square(
- side_length = 0.2,
- stroke_width = 0,
- fill_opacity = 0.5,
- fill_color = random.choice(colors),
- )
- for x in range(self.num_confetti_squares)
- ]
- confetti_spirils = [
- ConfettiSpiril(
- square,
- x_start = 2*random.random()*SPACE_WIDTH - SPACE_WIDTH,
- rate_func = squish_rate_func(lambda t : t, a, a+0.5)
- )
- for a, square in zip(
- np.linspace(0, 0.5, self.num_confetti_squares),
- confetti_squares
- )
- ]
- return confetti_spirils
-
class HomomophismPreview(Scene):
def construct(self):
raise Exception("Meant as a place holder, not to be excecuted")