You can specify the color of the object. Specifying a single color is set_color, giving a gradient, and specifying it is set_color_by_gradient.
set_color
manimlib.mobject.mobject.Mobject.set_color(self, color=YELLOW_C, family=True)
Changes the object color to the specified value. For the color value, you can use the constant defined in constants.py file, or you can directly specify the color value in the form of "#rrggbb", where 'rr' means hexadecimal value of red color, 'gg' is for green and 'bb' is for blue color.
In the case of shape type object(Rectangle, Circel, ect), only the outline is affected by the set_color method, and the color of the entire inside of the shape object is affected by the fill_color argument of the object.
Parameters: color=YELLOW_C
the color to be set.
constants difined in the manimlib/constants.py file are used to set the color value
Parameters: family=True
in case of group object consist of multiple sub-objects,
if 'family=True', change the the entire color of sub-objects
Returns: the object itself that the color is changed
Among the color constants defined in constants.py file, values such as YELLOW, BLUE, and RED are not visible, and only values such as YELLOW_E, BLUE_D, and RED_A are shown.
However in practice, YELLOW, BLUE, and RED can be used. This is because there is the following code when looking at the bottom of the constants.
for name in [s for s in list(COLOR_MAP.keys()) if s.endswith("_C")]:
locals()[name.replace("_C", "")] = locals()[name]
Refer to the figure below for the actual color for the entire color value.
set_color_by_gradient
manimlib.mobject.mobject.Mobject.set_color_by_gradient(self, *colors)
Gradiently (gradually) changes the color of an object.
Parameters: *colors
Color values to sepcify.
If there is no value in this method, an Exception will be occured.
If color is only one, it is same with set_color.
If there is more than one, use these colors to gradually change the color of the object
Returns: The object itself has changed color
Changes the color gradually for group objects where multiple objects are gathered.
You can't have a shape change color gradually but only for the goup of object is possible.
In the case of text, since a sentence is composed of several objects, the color can be gradually changed for the entire sentence.
The usage example below shows the result of applying a gradient to a text object and a group object consisting of multiple dots.
def gradient_test(self):
#dots
dots = VGroup(*[Dot(radius=0.15) for i in range(20)])
dots.arrange(RIGHT)
dots.set_color_by_gradient(PINK, BLUE, YELLOW)
#text
text = TextMobject("Gradient Color")
text.set_color_by_gradient(RED,YELLOW)
text.next_to(dots, UP)
#play
self.play(
FadeIn(dots),
Write(text),
run_time=2,
)
self.wait()
self.remove(dots, text)
Next: [05-1-E]Shape changing methods: scale, rotate
Go To: [99] Table of Contents
'Programming > Manim Lectures' 카테고리의 다른 글
[05-1-F]Status methods: copy, save_state, restore (0) | 2020.06.05 |
---|---|
[05-1-E]Shape changing methods: scale, rotate (0) | 2020.06.05 |
[05-1-C]Aligning methods: align_to, arrange, arrange_in_grid (0) | 2020.06.05 |
[05-1-B]Dimensional methods: get_width/height/top, set_width/height (0) | 2020.06.05 |
[05-1-A]Moving methods (0) | 2020.06.05 |