Пример #1
0
    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()
Пример #2
0
    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)