def get_number_mobject(self, x, direction=None, buff=None, scale_val=None, # number_config=None, **number_config): number_config = merge_dicts_recursively( self.decimal_number_config, number_config or {}, ) if scale_val is None: scale_val = self.number_scale_val if direction is None: direction = self.line_to_number_direction #direction = self.label_direction if buff is None: buff = self.line_to_number_buff #buff = buff or self.line_to_number_buff num_mob = DecimalNumber(x, **number_config) num_mob.scale(scale_val) num_mob.next_to( self.number_to_point(x), direction=direction, buff=buff ) if x < 0 and self.line_to_number_direction[0] == 0: # Align without the minus sign num_mob.shift(num_mob[0].get_width() * LEFT / 2) return num_mob
def __init__(self, mobject_or_chars): TextMobject.__init__(self) if mobject_or_chars == None or (isinstance(mobject_or_chars, Mobject) and mobject_or_chars.name == "Mobject"): mobject = Mobject() elif isinstance(mobject_or_chars, (list)): mobject = ImageMobject(mobject_or_chars[0]) self.add(mobject) self = mobject.copy() elif isinstance(mobject_or_chars, Mobject) and mobject_or_chars.name == "ImageMobject": mobject = mobject_or_chars self.add(mobject) self = mobject_or_chars[0].copy() else: if isinstance(mobject_or_chars, str): #mobject =MTex(mobject_or_chars) mobject = TextMobject(mobject_or_chars) elif isinstance(mobject_or_chars, int): mobject = Integer(mobject_or_chars) elif isinstance(mobject_or_chars, float): mobject = DecimalNumber(mobject_or_chars) elif isinstance(mobject_or_chars, (tuple)): mobject = TextMobject(*mobject_or_chars) else: mobject = mobject_or_chars self.become(mobject) self.name = mobject.name self.__class__ = mobject.__class__
def get_number_mobject( self, number, # input number should be a origin_x number_config=None, scale_val=None, direction=None, buff=None, number_is_origin_x=True): number_config = merge_dicts_recursively( self.decimal_number_config, number_config or {}, ) if scale_val is None: scale_val = self.number_scale_val if direction is None: direction = self.label_direction buff = buff or self.line_to_number_buff num_mob = DecimalNumber(self.log_factor * (self.log_base**(number)), **number_config) num_mob.scale(scale_val) num_mob.next_to(self.number_to_point(number, number_is_origin_x), direction=direction, buff=buff) return num_mob
def get_number_mobject( self, x: float, direction: np.ndarray | None = None, buff: float | None = None, **number_config ) -> DecimalNumber: number_config = merge_dicts_recursively( self.decimal_number_config, number_config ) if direction is None: direction = self.line_to_number_direction if buff is None: buff = self.line_to_number_buff num_mob = DecimalNumber(x, **number_config) num_mob.next_to( self.number_to_point(x), direction=direction, buff=buff ) if x < 0 and direction[0] == 0: # Align without the minus sign num_mob.shift(num_mob[0].get_width() * LEFT / 2) return num_mob
def construct(self): number_line = NumberLine(x_min=-1, x_max=1) triangle = RegularPolygon(3, start_angle=-PI / 2) \ .scale(0.2) \ .next_to(number_line.get_left(), UP, buff=SMALL_BUFF) decimal = DecimalNumber( 0, num_decimal_places=3, include_sign=True, unit="\\rm cm", # Change this with None ) decimal.add_updater(lambda d: d.next_to(triangle, UP * 0.1)) decimal.add_updater(lambda d: d.set_value(triangle.get_center()[0])) # You can get the value of decimal with: .get_value() self.add(number_line, triangle, decimal) self.play( triangle.shift, RIGHT * 2, rate_func=there_and_back, # Change this with: linear,smooth run_time=5) self.wait()
def get_number_mobject(self, number, number_config=None, scale_val=None, direction=None, buff=None): number_config = merge_dicts_recursively( self.decimal_number_config, number_config or {}, ) if scale_val is None: scale_val = self.number_scale_val if direction is None: direction = self.label_direction buff = buff or self.line_to_number_buff num_mob = DecimalNumber(number, **number_config) num_mob.scale(scale_val) num_mob.next_to( self.number_to_point(number), direction=direction, buff=buff ) return num_mob
def get_cursor_location_label(self): decimals = VGroup(*(DecimalNumber(**self.cursor_location_config) for n in range(3))) def update_coords(decimals): for mob, coord in zip(decimals, self.mouse_point.get_location()): mob.set_value(coord) decimals.arrange(RIGHT, buff=decimals.get_height()) decimals.to_corner(DR, buff=SMALL_BUFF) decimals.fix_in_frame() return decimals decimals.add_updater(update_coords) return decimals
def get_information_label(self): loc_label = VGroup(*(DecimalNumber(**self.cursor_location_config) for n in range(3))) def update_coords(loc_label): for mob, coord in zip(loc_label, self.mouse_point.get_location()): mob.set_value(coord) loc_label.arrange(RIGHT, buff=loc_label.get_height()) loc_label.to_corner(DR, buff=SMALL_BUFF) loc_label.fix_in_frame() return loc_label loc_label.add_updater(update_coords) time_label = DecimalNumber(0, **self.time_label_config) time_label.to_corner(DL, buff=SMALL_BUFF) time_label.fix_in_frame() time_label.add_updater(lambda m, dt: m.increment_value(dt)) return VGroup(loc_label, time_label)
def get_number_mobjects(self, *numbers, **kwargs): # TODO, handle decimals if len(numbers) == 0: numbers = self.default_numbers_to_display() result = VGroup() for number in numbers: mob = DecimalNumber(number, **self.decimal_number_config) mob.scale(self.number_scale_val) mob.next_to( self.number_to_point(number), self.label_direction, self.line_to_number_buff, ) result.add(mob) return result
def get_number_mobject(self, number, number_config=None, scale_val=None, direction=None, buff=None): number_config = merge_dicts_recursively( self.decimal_number_config, number_config or {}, ) scale_val = scale_val or self.number_scale_val direction = direction or self.label_direction buff = buff or self.line_to_number_buff num_mob = DecimalNumber(number, **number_config) num_mob.scale(scale_val) num_mob.next_to(self.number_to_point(number), direction=direction, buff=buff) return num_mob