Beispiel #1
0
    def construct(self):
        number_line = NumberLine(
            numerical_radius = 5,
            number_at_center = 5,
            leftmost_tick = 0,
            density = 2*DEFAULT_POINT_DENSITY_1D
        )
        number_line.shift(2*RIGHT)
        number_line.add_numbers()
        number_line.scale(2)
        brace = Brace(Mobject(
            *number_line.sub_mobjects[:2]
        ))

        self.add(number_line)
        for n in range(0, 10, 2):
            if n == 0:
                brace_anim = GrowFromCenter(brace)
            else:
                brace_anim = ApplyMethod(brace.shift, 2*RIGHT)
            self.play(
                ApplyMethod(
                    number_line.highlight,
                    RED,
                    lambda p : p[0] > n-6.2 and p[0] < n-4 and p[1] > -0.4
                ),
                brace_anim
            )
Beispiel #2
0
def get_time_line():
    length = 5.2*SPACE_WIDTH
    year_range = 400
    time_line = NumberLine(
        numerical_radius = year_range/2,
        unit_length_to_spatial_width = length/year_range,
        tick_frequency = 10,
        leftmost_tick = 1720,
        number_at_center = 1870,
        numbers_with_elongated_ticks = range(1700, 2100, 100)
    )
    time_line.sort_points(lambda p : p[0])        
    time_line.gradient_highlight(
        PeanoCurve.DEFAULT_CONFIG["start_color"], 
        PeanoCurve.DEFAULT_CONFIG["end_color"]
    )
    time_line.add_numbers(
        2020, *range(1800, 2050, 50)
    )
    return time_line
Beispiel #3
0
    def setup_axes(self, animate = False):
        x_num_range = float(self.x_max - self.x_min)
        self.space_unit_to_x = self.x_axis_width/x_num_range
        self.x_labeled_nums = self.x_labeled_nums or []
        x_axis = NumberLine(
            x_min = self.x_min,
            x_max = self.x_max,
            space_unit_to_num = self.space_unit_to_x,
            tick_frequency = self.x_tick_frequency,
            leftmost_tick = self.x_leftmost_tick or self.x_min,
            numbers_with_elongated_ticks = self.x_labeled_nums,
            color = self.axes_color
        )
        x_axis.shift(self.graph_origin - x_axis.number_to_point(0))        
        if len(self.x_labeled_nums) > 0:
            if self.exclude_zero_label:
                self.x_labeled_nums = filter(
                    lambda x : x != 0,
                    self.x_labeled_nums
                )
            x_axis.add_numbers(*self.x_labeled_nums)
        x_label = TextMobject(self.x_axis_label)
        x_label.next_to(
            x_axis.get_tick_marks(), UP+RIGHT, 
            buff = SMALL_BUFF
        )
        x_label.shift_onto_screen()
        x_axis.add(x_label)
        self.x_axis_label_mob = x_label

        y_num_range = float(self.y_max - self.y_min)
        self.space_unit_to_y = self.y_axis_height/y_num_range
        self.y_labeled_nums = self.y_labeled_nums or []
        y_axis = NumberLine(
            x_min = self.y_min,
            x_max = self.y_max,
            space_unit_to_num = self.space_unit_to_y,
            tick_frequency = self.y_tick_frequency,
            leftmost_tick = self.y_bottom_tick or self.y_min,
            numbers_with_elongated_ticks = self.y_labeled_nums,
            color = self.axes_color
        )
        y_axis.shift(self.graph_origin-y_axis.number_to_point(0))
        y_axis.rotate(np.pi/2, about_point = y_axis.number_to_point(0))
        if len(self.y_labeled_nums) > 0:
            if self.exclude_zero_label:
                self.y_labeled_nums = filter(
                    lambda y : y != 0,
                    self.y_labeled_nums
                )
            y_axis.add_numbers(*self.y_labeled_nums)
            for mob in y_axis.numbers:
                mob.next_to(mob.get_center(), LEFT, MED_SMALL_BUFF)
                mob.shift(self.y_axis_numbers_nudge)
        y_label = TextMobject(self.y_axis_label)
        y_label.next_to(
            y_axis.get_tick_marks(), UP+RIGHT, 
            buff = SMALL_BUFF
        )
        y_label.shift_onto_screen()
        y_axis.add(y_label)
        self.y_axis_label_mob = y_label

        if animate:
            self.play(Write(VGroup(x_axis, y_axis)))
        else:
            self.add(x_axis, y_axis)
        self.x_axis, self.y_axis = self.axes = VGroup(x_axis, y_axis)
        self.default_graph_colors = it.cycle(self.default_graph_colors)
Beispiel #4
0
    def setup_axes(self, animate = True):
        x_num_range = float(self.x_max - self.x_min)
        x_axis = NumberLine(
            x_min = self.x_min,
            x_max = self.x_max,
            space_unit_to_num = self.x_axis_width/x_num_range,
            tick_frequency = self.x_tick_frequency,
            leftmost_tick = self.x_leftmost_tick or self.x_min,
            numbers_with_elongated_ticks = self.x_labeled_nums,
            color = self.axes_color
        )
        x_axis.shift(self.graph_origin - x_axis.number_to_point(0))
        if self.x_labeled_nums:
            x_axis.add_numbers(*self.x_labeled_nums)
        x_label = TextMobject(self.x_axis_label)
        x_label.next_to(x_axis, RIGHT+UP, buff = SMALL_BUFF)
        x_label.shift_onto_screen()
        x_axis.add(x_label)
        self.x_axis_label_mob = x_label

        y_num_range = float(self.y_max - self.y_min)
        y_axis = NumberLine(
            x_min = self.y_min,
            x_max = self.y_max,
            space_unit_to_num = self.y_axis_height/y_num_range,
            tick_frequency = self.y_tick_frequency,
            leftmost_tick = self.y_bottom_tick or self.y_min,
            numbers_with_elongated_ticks = self.y_labeled_nums,
            color = self.axes_color
        )
        y_axis.shift(self.graph_origin-y_axis.number_to_point(0))
        y_axis.rotate(np.pi/2, about_point = y_axis.number_to_point(0))
        if self.y_labeled_nums:
            y_axis.add_numbers(*self.y_labeled_nums)
            y_axis.numbers.shift(self.y_axis_numbers_nudge)
        y_label = TextMobject(self.y_axis_label)
        y_label.next_to(y_axis.get_top(), RIGHT, buff = 2*MED_BUFF)
        y_label.shift_onto_screen()
        y_axis.add(y_label)
        self.y_axis_label_mob = y_label

        if animate:
            self.play(Write(VGroup(x_axis, y_axis)))
        else:
            selfe.add(x_axis, y_axis_label)
        self.x_axis, self.y_axis = x_axis, y_axis
    def setup_axes(self, animate = False):
        ##TODO, once eoc is done, refactor this to be less redundant.
        x_num_range = float(self.x_max - self.x_min)
        self.space_unit_to_x = self.x_axis_width/x_num_range
        if self.x_labeled_nums is None:
            self.x_labeled_nums = []
        if self.x_leftmost_tick is None:
            self.x_leftmost_tick = self.x_min
        x_axis = NumberLine(
            x_min = self.x_min,
            x_max = self.x_max,
            unit_size = self.space_unit_to_x,
            tick_frequency = self.x_tick_frequency,
            leftmost_tick = self.x_leftmost_tick,
            numbers_with_elongated_ticks = self.x_labeled_nums,
            color = self.axes_color
        )
        x_axis.shift(self.graph_origin - x_axis.number_to_point(0))        
        if len(self.x_labeled_nums) > 0:
            if self.exclude_zero_label:
                self.x_labeled_nums = filter(
                    lambda x : x != 0,
                    self.x_labeled_nums
                )
            x_axis.add_numbers(*self.x_labeled_nums)
        if self.x_axis_label:
            x_label = TextMobject(self.x_axis_label)
            x_label.next_to(
                x_axis.get_tick_marks(), UP+RIGHT, 
                buff = SMALL_BUFF
            )
            x_label.shift_onto_screen()
            x_axis.add(x_label)
            self.x_axis_label_mob = x_label

        y_num_range = float(self.y_max - self.y_min)
        self.space_unit_to_y = self.y_axis_height/y_num_range

        if self.y_labeled_nums is None:
            self.y_labeled_nums = []
        if self.y_bottom_tick is None:
            self.y_bottom_tick = self.y_min
        y_axis = NumberLine(
            x_min = self.y_min,
            x_max = self.y_max,
            unit_size = self.space_unit_to_y,
            tick_frequency = self.y_tick_frequency,
            leftmost_tick = self.y_bottom_tick,
            numbers_with_elongated_ticks = self.y_labeled_nums,
            color = self.axes_color,
            line_to_number_vect = LEFT,
        )
        y_axis.shift(self.graph_origin-y_axis.number_to_point(0))
        y_axis.rotate(np.pi/2, about_point = y_axis.number_to_point(0))
        if len(self.y_labeled_nums) > 0:
            if self.exclude_zero_label:
                self.y_labeled_nums = filter(
                    lambda y : y != 0,
                    self.y_labeled_nums
                )
            y_axis.add_numbers(*self.y_labeled_nums)
        if self.y_axis_label:
            y_label = TextMobject(self.y_axis_label)
            y_label.next_to(
                y_axis.get_tick_marks(), UP+RIGHT, 
                buff = SMALL_BUFF
            )
            y_label.shift_onto_screen()
            y_axis.add(y_label)
            self.y_axis_label_mob = y_label

        if animate:
            self.play(Write(VGroup(x_axis, y_axis)))
        else:
            self.add(x_axis, y_axis)
        self.x_axis, self.y_axis = self.axes = VGroup(x_axis, y_axis)
        self.default_graph_colors = it.cycle(self.default_graph_colors)
Beispiel #6
0
    def setup_axes(self, animate=False):
        x_num_range = float(self.x_max - self.x_min)
        self.space_unit_to_x = self.x_axis_width / x_num_range
        self.x_labeled_nums = self.x_labeled_nums or []
        x_axis = NumberLine(x_min=self.x_min,
                            x_max=self.x_max,
                            space_unit_to_num=self.space_unit_to_x,
                            tick_frequency=self.x_tick_frequency,
                            leftmost_tick=self.x_leftmost_tick or self.x_min,
                            numbers_with_elongated_ticks=self.x_labeled_nums,
                            color=self.axes_color)
        x_axis.shift(self.graph_origin - x_axis.number_to_point(0))
        if len(self.x_labeled_nums) > 0:
            if self.exclude_zero_label:
                self.x_labeled_nums = filter(lambda x: x != 0,
                                             self.x_labeled_nums)
            x_axis.add_numbers(*self.x_labeled_nums)
        x_label = TextMobject(self.x_axis_label)
        x_label.next_to(x_axis.get_tick_marks(), UP + RIGHT, buff=SMALL_BUFF)
        x_label.shift_onto_screen()
        x_axis.add(x_label)
        self.x_axis_label_mob = x_label

        y_num_range = float(self.y_max - self.y_min)
        self.space_unit_to_y = self.y_axis_height / y_num_range
        self.y_labeled_nums = self.y_labeled_nums or []
        y_axis = NumberLine(x_min=self.y_min,
                            x_max=self.y_max,
                            space_unit_to_num=self.space_unit_to_y,
                            tick_frequency=self.y_tick_frequency,
                            leftmost_tick=self.y_bottom_tick or self.y_min,
                            numbers_with_elongated_ticks=self.y_labeled_nums,
                            color=self.axes_color)
        y_axis.shift(self.graph_origin - y_axis.number_to_point(0))
        y_axis.rotate(np.pi / 2, about_point=y_axis.number_to_point(0))
        if len(self.y_labeled_nums) > 0:
            if self.exclude_zero_label:
                self.y_labeled_nums = filter(lambda y: y != 0,
                                             self.y_labeled_nums)
            y_axis.add_numbers(*self.y_labeled_nums)
            for mob in y_axis.numbers:
                mob.next_to(mob.get_center(), LEFT, MED_SMALL_BUFF)
                mob.shift(self.y_axis_numbers_nudge)
        y_label = TextMobject(self.y_axis_label)
        y_label.next_to(y_axis.get_tick_marks(), UP + RIGHT, buff=SMALL_BUFF)
        y_label.shift_onto_screen()
        y_axis.add(y_label)
        self.y_axis_label_mob = y_label

        if animate:
            self.play(Write(VGroup(x_axis, y_axis)))
        else:
            self.add(x_axis, y_axis)
        self.x_axis, self.y_axis = self.axes = VGroup(x_axis, y_axis)
        self.default_graph_colors = it.cycle(self.default_graph_colors)