示例#1
0
文件: matrix.py 项目: stschaef/LLL
def vector_coordinate_label(vector_mob,
                            integer_labels=True,
                            num_places=2,
                            n_dim=2,
                            color=WHITE):
    vect = np.array(vector_mob.get_end())
    if integer_labels:
        vect = np.round(vect).astype(int)
    else:
        vect = np.around(vect, decimals=num_places)
    vect = vect[:n_dim]
    vect = vect.reshape((n_dim, 1))
    label = Matrix(vect, add_background_rectangles_to_entries=False)
    label.scale(VECTOR_LABEL_SCALE_FACTOR)

    shift_dir = np.array(vector_mob.get_end())
    if shift_dir[0] >= 0:  # Pointing right
        shift_dir -= label.get_left(
        ) + DEFAULT_MOBJECT_TO_MOBJECT_BUFFER * LEFT
    else:  # Pointing left
        shift_dir -= label.get_right(
        ) + DEFAULT_MOBJECT_TO_MOBJECT_BUFFER * RIGHT
    label.shift(shift_dir)
    label.set_color(color)
    label.rect = BackgroundRectangle(label)
    label.add_to_back(label.rect)
    return label
示例#2
0
    def construct(self):
        square = Square(side_length=5, fill_color=YELLOW, fill_opacity=1)
        label = TextMobject("Text at an angle")
        label_bg = BackgroundRectangle(label, fill_opacity=1)
        label_group = VGroup(label_bg, label)

        label_group.rotate(TAU / 8)

        label2 = TextMobject("Boxed text", color=BLACK)
        label2_bg = SurroundingRectangle(label2,
                                         color=BLUE,
                                         fill_color=RED,
                                         fill_opacity=.5)
        label2_group = VGroup(label2, label2_bg)
        label2_group.next_to(label_group, DOWN)

        label3 = TextMobject("Rainbow")
        label3.scale(2)
        label3.set_color_by_gradient(RED, GREEN, BLUE)
        label3.to_edge(DOWN)

        self.add(square)
        self.play(FadeIn(label_group))
        self.play(FadeIn(label2_group))
        self.play(FadeIn(label3))
        self.wait(2)
示例#3
0
 def add_background_rectangle(self, color=BLACK, opacity=0.75, **kwargs):
     from manimlib.mobject.shape_matchers import BackgroundRectangle
     self.background_rectangle = BackgroundRectangle(self,
                                                     color=color,
                                                     fill_opacity=opacity,
                                                     **kwargs)
     self.add_to_back(self.background_rectangle)
     return self
示例#4
0
 def add_background_rectangle(self, color=BLACK, opacity=0.75, **kwargs):
     # TODO, this does not behave well when the mobject has points,
     # since it gets displayed on top
     from manimlib.mobject.shape_matchers import BackgroundRectangle
     self.background_rectangle = BackgroundRectangle(self,
                                                     color=color,
                                                     fill_opacity=opacity,
                                                     **kwargs)
     self.add_to_back(self.background_rectangle)
     return self