from manim import *


class ArrowSampleWithUpdater(Scene):

    def construct(self):

        rect = Rectangle(color=WHITE, height=3, width=2.5).to_edge(UL)

        circ = Circle().to_edge(DR)

        arrow = always_redraw(lambda: Line(
            start=rect.get_bottom(), end=circ.get_top(), buff=0.2).add_tip())

        self.play(Create(VGroup(rect, circ, arrow)))
        self.wait()

        self.play(rect.animate.to_edge(UR),
                  circ.animate.scale(0.5), run_time=4)
        self.wait()

        return super().construct()


class UpdaterSample(Scene):

    def construct(self):

        formula = MathTex("ln(2)")

        box = always_redraw(lambda: SurroundingRectangle(
            formula, color=BLUE, fill_color=RED, fill_opacity=0.4, buff=0.25))

        name = always_redraw(lambda: Tex(
            "Hello World").next_to(box, DOWN, buff=0.25))

        self.play(Create(VGroup(formula, box, name)))
        self.play(formula.animate.shift(RIGHT * 2), run_time=2)
        self.wait()

        return super().construct()


class ValueTrackers(Scene):

    def construct(self):

        k = ValueTracker(value=5)

        num = always_redraw(lambda: DecimalNumber().set_value(k.get_value()))

        self.play(FadeIn(num))
        self.wait()
        self.play(k.animate.set_value(0), run_time=5, rate_functions=smooth)

        return super().construct()

from manim import *


class ArrowSampleWithUpdater(Scene):

    def construct(self):

        rect = Rectangle(color=WHITE, height=3, width=2.5).to_edge(UL)

        circ = Circle().to_edge(DR)

        arrow = always_redraw(lambda: Line(
            start=rect.get_bottom(), end=circ.get_top(), buff=0.2).add_tip())

        self.play(Create(VGroup(rect, circ, arrow)))
        self.wait()

        self.play(rect.animate.to_edge(UR),
                  circ.animate.scale(0.5), run_time=4)
        self.wait()

        return super().construct()


class UpdaterSample(Scene):

    def construct(self):

        formula = MathTex("ln(2)")

        box = always_redraw(lambda: SurroundingRectangle(
            formula, color=BLUE, fill_color=RED, fill_opacity=0.4, buff=0.25))

        name = always_redraw(lambda: Tex(
            "Hello World").next_to(box, DOWN, buff=0.25))

        self.play(Create(VGroup(formula, box, name)))
        self.play(formula.animate.shift(RIGHT * 2), run_time=2)
        self.wait()

        return super().construct()


class ValueTrackers(Scene):

    def construct(self):

        k = ValueTracker(value=5)

        num = always_redraw(lambda: DecimalNumber().set_value(k.get_value()))

        self.play(FadeIn(num))
        self.wait()
        self.play(k.animate.set_value(0), run_time=5, rate_functions=smooth)

        return super().construct()
