def __init__(self, point, color=YELLOW, **kwargs): digest_config(self, kwargs) lines = VGroup() for angle in np.arange(0, TAU, TAU / self.num_lines): line = Line(ORIGIN, self.line_length * RIGHT) line.shift((self.flash_radius - self.line_length) * RIGHT) line.rotate(angle, about_point=ORIGIN) lines.add(line) lines.move_to(point) lines.set_color(color) lines.set_stroke(width=3) line_anims = [ ShowCreationThenDestruction( line, rate_func=squish_rate_func(smooth, 0, 0.5) ) for line in lines ] fade_anims = [ UpdateFromAlphaFunc( line, lambda m, a: m.set_stroke( width=self.line_stroke_width * (1 - a) ), rate_func=squish_rate_func(smooth, 0, 0.75) ) for line in lines ] AnimationGroup.__init__( self, *line_anims + fade_anims, **kwargs )
def construct(self): # Set objets theta = ValueTracker(self.theta) line_1 = Line(ORIGIN, RIGHT * self.lines_size, color=self.line_1_color) line_2 = Line(ORIGIN, RIGHT * self.lines_size, color=self.line_2_color) line_2.rotate(theta.get_value(), about_point=ORIGIN) line_2.add_updater(lambda m: m.set_angle(theta.get_value())) angle = Arc(radius=self.radius, start_angle=line_1.get_angle(), angle=line_2.get_angle(), color=self.radius_color) # Show the objects self.play(*[ShowCreation(obj) for obj in [line_1, line_2, angle]]) # Set update function to angle angle.add_updater(lambda m: m.become( Arc(radius=self.radius, start_angle=line_1.get_angle(), angle=line_2.get_angle(), color=self.radius_color))) # Remember to add the objects again to the screen # when you add the add_updater method. self.add(angle) self.play(theta.increment_value, self.increment_theta) # self.play(theta.set_value,self.final_theta) self.wait()
def get_tick(self, x, size=None): if size is None: size = self.tick_size result = Line(size * DOWN, size * UP) result.rotate(self.main_line.get_angle()) result.move_to(self.number_to_point(x)) return result
def add_tips(self): linea_referencia = Line(self[0][0].get_start(), self[0][-1].get_end()) vector_unitario = linea_referencia.get_unit_vector() punto_final1 = self[0][-1].get_end() punto_inicial1 = punto_final1 - vector_unitario * self.size_arrows punto_inicial2 = self[0][0].get_start() punto_final2 = punto_inicial2 + vector_unitario * self.size_arrows lin1_1 = Line(punto_inicial1, punto_final1).set_color(self[0].get_color()).set_stroke( None, self.stroke) lin1_2 = lin1_1.copy() lin2_1 = Line(punto_inicial2, punto_final2).set_color(self[0].get_color()).set_stroke( None, self.stroke) lin2_2 = lin2_1.copy() lin1_1.rotate(self.ang_arrows, about_point=punto_final1, about_edge=punto_final1) lin1_2.rotate(-self.ang_arrows, about_point=punto_final1, about_edge=punto_final1) lin2_1.rotate(self.ang_arrows, about_point=punto_inicial2, about_edge=punto_inicial2) lin2_2.rotate(-self.ang_arrows, about_point=punto_inicial2, about_edge=punto_inicial2) return self.add(lin1_1, lin1_2, lin2_1, lin2_2)
def get_tick(self, x: float, size: float | None = None) -> Line: if size is None: size = self.tick_size result = Line(size * DOWN, size * UP) result.rotate(self.get_angle()) result.move_to(self.number_to_point(x)) result.match_style(self) return result
def get_tick(self, x, size=None): if size is None: size = self.tick_size result = Line(size * DOWN, size * UP) result.rotate(self.get_angle()) result.move_to(self.number_to_point(x)) result.match_style(self) return result
def create_lines(self): lines = VGroup() for angle in np.arange(0, TAU, TAU / self.num_lines): line = Line(ORIGIN, self.line_length * RIGHT) line.shift((self.flash_radius - self.line_length) * RIGHT) line.rotate(angle, about_point=ORIGIN) lines.add(line) lines.set_stroke(color=self.color, width=self.line_stroke_width) lines.add_updater(lambda l: l.move_to(self.point)) return lines
def construct(self): theta = ValueTracker(PI / 2) line_1 = Line(ORIGIN, RIGHT * 3, color=RED) line_2 = Line(ORIGIN, RIGHT * 3, color=GREEN) line_2.rotate(theta.get_value(), about_point=ORIGIN) line_2.add_updater(lambda m: m.set_angle(theta.get_value())) self.add(line_1, line_2) self.play(theta.increment_value, PI / 2) self.wait()
def add_treds_to_tires(self): for tire in self.get_tires(): radius = tire.get_width() / 2 center = tire.get_center() tred = Line(0.7 * radius * RIGHT, 1.1 * radius * RIGHT, stroke_width=2, color=BLACK) tred.rotate(PI / 5, about_point=tred.get_end()) for theta in np.arange(0, 2 * np.pi, np.pi / 4): new_tred = tred.copy() new_tred.rotate(theta, about_point=ORIGIN) new_tred.shift(center) tire.add(new_tred) return self
def add_treds_to_tires(self): for tire in self.get_tires(): radius = tire.get_width() / 2 center = tire.get_center() tred = Line( 0.7 * radius * RIGHT, 1.1 * radius * RIGHT, stroke_width=2, color=BLACK ) tred.rotate(PI / 5, about_point=tred.get_end()) for theta in np.arange(0, 2 * np.pi, np.pi / 4): new_tred = tred.copy() new_tred.rotate(theta, about_point=ORIGIN) new_tred.shift(center) tire.add(new_tred) return self