classCount(Animation): def__init__(self, number: DecimalNumber, start: float, end: float, **kwargs) -> None: # Pass number as the mobject of the animation super().__init__(number, **kwargs) # Set start and end self.start = start self.end = end
definterpolate_mobject(self, alpha: float) -> None: # Set value of DecimalNumber according to alpha value = self.start + (alpha * (self.end - self.start)) self.mobject.set_value(value)
classCountingScene(Scene): defconstruct(self): # Create Decimal Number and add it to scene number = DecimalNumber().set_color(WHITE).scale(5) # Add an updater to keep the DecimalNumber centered as its value changes number.add_updater(lambda number: number.move_to(ORIGIN))
self.add(number)
self.wait()
# Play the Count Animation to count from 0 to 100 in 4 seconds self.play(Count(number, 0, 100), run_time=4, rate_func=linear)
self.add(Dot(a.get_start()).set_color(YELLOW).scale(2)) self.add(Dot(a.get_end()).set_color(RED).scale(2)) self.add(Dot(a.get_top()).set_color(GREEN_A).scale(2)) self.add(Dot(a.get_bottom()).set_color(GREEN_D).scale(2)) self.add(Dot(a.get_center()).set_color(BLUE).scale(2)) self.add(Dot(a.point_from_proportion(0.5)).set_color(ORANGE).scale(2)) self.add(*[Dot(x) for x in a.points]) self.add(a)