From d35b0f54d465cadec10e842bc1d7e309a54f497a Mon Sep 17 00:00:00 2001 From: bibin Date: Fri, 21 Oct 2022 18:44:06 +0200 Subject: [PATCH 1/2] small refactoring --- segment_tree/segment_tree.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/segment_tree/segment_tree.py b/segment_tree/segment_tree.py index cae3a91..93610c2 100644 --- a/segment_tree/segment_tree.py +++ b/segment_tree/segment_tree.py @@ -1,8 +1,6 @@ from manim import * -import networkx as nx - -class Tree(Scene): +class Main(Scene): def construct(self): n = 2**6 l, r = 42, 59 From 036680d6109a7dfd3ef1d0727f87362e4b1bc91d Mon Sep 17 00:00:00 2001 From: bibin Date: Fri, 21 Oct 2022 18:44:27 +0200 Subject: [PATCH 2/2] add initial drawing balls from a urn animation --- math/combinatorics.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 math/combinatorics.py diff --git a/math/combinatorics.py b/math/combinatorics.py new file mode 100644 index 0000000..57a0c46 --- /dev/null +++ b/math/combinatorics.py @@ -0,0 +1,39 @@ +from manim import * +import random + +class Urn(Square): + def __init__(self): + Square.__init__(self, side_length=1.0, fill_color=GREY, fill_opacity=1.0) + +class Balls(VGroup): + colors = [BLUE, GREEN, YELLOW, PURPLE, RED, GRAY, MAROON, ORANGE, TEAL] + + def __init__(self, n): + cols = Balls.colors + random.shuffle(cols) + cols = cols[:n] + super().__init__(*[LabeledDot(str(l), color=c) for l, c in zip(list(range(n)), cols)]) + +class Main(Scene): + def construct(self): + + urn = Urn().shift(3*LEFT) + + n = 9 + k = 6 + balls = Balls(n) + + left = list(range(n)) + random.shuffle(left) + left = left[:k] + for d in left: + + self.add(balls[d].move_to(urn), urn) + self.play(balls[d].animate.shift(DOWN)) + + self.play(urn.animate.shift(RIGHT)) + + + self.wait(2) + +