예제 #1
0
파일: node.py 프로젝트: myhololens/manim
    def generate_mobject(self, dic, labels):
        # generate mobject attributes from component attributes
        # update number of labels for scaling
        num_labels = len(self.labels)
        for key in labels:
            if key not in self.labels:
                num_labels += 1
            if key in self.labels and labels[key] is None:
                num_labels -= 1

        if "scale_factor" not in dic:
            if hasattr(self, "mobject") and \
               hasattr(self.mobject, "scale_factor"):
                dic["scale_factor"] = self.mobject.scale_factor
            else:
                print("Attempted to initialize Node without scale_factor")
                breakpoint(context=7)

        if "radius" in dic:
            pass
        elif num_labels > 0:
            dic["radius"] = LABELED_NODE_RADIUS * dic["scale_factor"]
        elif num_labels == 0:
            dic["radius"] = UNLABELED_NODE_RADIUS * dic["scale_factor"]
        else:
            dic["radius"] = self.mobject.radius

        if "stroke_width" not in dic:
            if hasattr(self, "mobject") and \
               hasattr(self.mobject, "stroke_width"):
                dic["stroke_width"] = self.mobject.stroke_width
            else:
                print("Attempted to initialize Node without stroke_width")
                breakpoint(context=7)

        if "color" not in dic:
            if hasattr(self, "mobject") and \
               hasattr(self.mobject, "color"):
                dic["color"] = self.mobject.color
            else:
                print("Attempted to initialize Node without color")
                breakpoint(context=7)

        mobject_class = dic.get("mobject_class", None)
        if mobject_class is None:
            new_mob = Circle(**dic)
        else:
            new_mob = mobject_class(**dic)

        # the component is first initialized without a mobject attr
        if not hasattr(self, "mobject"):
            new_mob.move_to(self.key)
        else:
            new_mob.move_to(self.mobject.get_center())

        return new_mob
예제 #2
0
 def __init__(self, focal_point, **kwargs):
     digest_config(self, kwargs)
     circles = VGroup()
     for x in range(self.n_circles):
         circle = Circle(
             radius=self.big_radius,
             stroke_color=BLACK,
             stroke_width=0,
         )
         circle.move_to(focal_point)
         circle.save_state()
         circle.set_width(self.small_radius * 2)
         circle.set_stroke(self.color, self.start_stroke_width)
         circles.add(circle)
     LaggedStart.__init__(self, ApplyMethod, circles, lambda c:
                          (c.restore, ), **kwargs)
예제 #3
0
    def increment(self, run_time_per_anim=1):
        moving_dot = Dot(
            self.counting_dot_starting_position,
            radius=self.count_dot_starting_radius,
            color=self.digit_place_colors[0],
        )
        moving_dot.generate_target()
        moving_dot.set_fill(opacity=0)
        kwargs = {
            "run_time": run_time_per_anim
        }

        continue_rolling_over = True
        first_move = True
        place = 0
        while continue_rolling_over:
            added_anims = []
            if first_move:
                added_anims += self.get_digit_increment_animations()
                first_move = False
            moving_dot.target.replace(
                self.dot_template_iterators[place].next()
            )
            self.play(MoveToTarget(moving_dot), *added_anims, **kwargs)
            self.curr_configurations[place].add(moving_dot)

            if len(self.curr_configurations[place].split()) == self.get_place_max(place):
                full_configuration = self.curr_configurations[place]
                self.curr_configurations[place] = VGroup()
                place += 1
                center = full_configuration.get_center_of_mass()
                radius = 0.6 * max(
                    full_configuration.get_width(),
                    full_configuration.get_height(),
                )
                circle = Circle(
                    radius=radius,
                    stroke_width=0,
                    fill_color=self.digit_place_colors[place],
                    fill_opacity=0.5,
                )
                circle.move_to(center)
                moving_dot = VGroup(circle, full_configuration)
                moving_dot.generate_target()
                moving_dot[0].set_fill(opacity=0)
            else:
                continue_rolling_over = False
예제 #4
0
 def __init__(self, focal_point, **kwargs):
     digest_config(self, kwargs)
     circles = VGroup()
     for x in range(self.n_circles):
         circle = Circle(
             radius=self.big_radius,
             stroke_color=BLACK,
             stroke_width=0,
         )
         circle.move_to(focal_point)
         circle.save_state()
         circle.scale_to_fit_width(self.small_radius * 2)
         circle.set_stroke(self.color, self.start_stroke_width)
         circles.add(circle)
     LaggedStart.__init__(
         self, ApplyMethod, circles,
         lambda c: (c.restore,),
         **kwargs
     )