Beispiel #1
0
 def add_background_rectangle(self, color=BLACK, opacity=0.75):
     self.background_rectangle = BackgroundRectangle(self,
                                                     color=color,
                                                     fill_opacity=opacity)
     letters = VMobject(*self.submobjects)
     self.submobjects = [self.background_rectangle, letters]
     return self
Beispiel #2
0
 def add_background_rectangle(self):
     #TODO, is this the best way to handle
     #background rectangles?
     self.background_rectangle = BackgroundRectangle(self)
     self.submobjects = [
         self.background_rectangle,
         VGroup(*self.submobjects)
     ]
     return self
Beispiel #3
0
    def __init__(self, number, **kwargs):
        VMobject.__init__(self, **kwargs)
        self.number = number
        ndp = self.num_decimal_points

        #Build number string
        if isinstance(number, complex):
            num_string = '%.*f%s%.*fi'%(
                ndp, number.real, 
                "-" if number.imag < 0 else "+",
                ndp, abs(number.imag)
            )
        else:
            num_string = '%.*f'%(ndp, number)
            negative_zero_string = "-%.*f"%(ndp, 0.)
            if num_string == negative_zero_string:
                num_string = num_string[1:]
        self.add(*[
            TexMobject(char, **kwargs)
            for char in num_string
        ])

        #Add non-numerical bits
        if self.show_ellipsis:
            self.add(TexMobject("\\dots"))

        if self.unit is not None:
            self.add(TexMobject(self.unit))

        self.arrange_submobjects(
            buff = self.digit_to_digit_buff,
            aligned_edge = DOWN
        )

        #Handle alignment of parts that should be aligned
        #to the bottom
        for i, c in enumerate(num_string):
            if c == "-" and len(num_string) > i+1:
                self[i].align_to(self[i+1], alignment_vect = UP)
        if self.unit == "\\circ":
            self[-1].align_to(self, UP)
        #
        if self.include_background_rectangle:
            #TODO, is this the best way to handle
            #background rectangles?
            self.background_rectangle = BackgroundRectangle(self)
            self.submobjects = [
                self.background_rectangle,
                VGroup(*self.submobjects)
            ]
Beispiel #4
0
def vector_coordinate_label(vector_mob,
                            integer_labels=True,
                            n_dim=2,
                            color=WHITE):
    vect = np.array(vector_mob.get_end())
    if integer_labels:
        vect = np.round(vect).astype(int)
    vect = vect[:n_dim]
    vect = vect.reshape((n_dim, 1))
    label = Matrix(vect, add_background_rectangles=True)
    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.highlight(color)
    label.rect = BackgroundRectangle(label)
    label.add_to_back(label.rect)
    return label