본문 바로가기

카테고리 없음

[009]set_color/set_color_by_gradient

반응형

set_color

class ColorTest(Scene):
    def construct(self):
        self.set_color_test()
        # self.display_color_map()
        # self.gradient_test()

    def set_color_test(self):
        dot = Dot()
        rect = Rectangle()
        line = Line(ORIGIN, RIGHT)
        text = Text("Hello")

        group = VGroup(dot,rect,line, text).arrange(DOWN)

        #default color
        self.add(group)
        self.wait()

        #change color to red
        group.set_color(RED)
        self.play(ShowCreation(group))
        self.wait()  
      
        group.set_color(YELLOW)
        self.play(ShowCreation(group))
        self.wait()

        self.remove(group)

 


set_color: Color Map

class ColorTest(Scene):
    def construct(self):       
        self.display_color_map()     

    def display_color_map(self):
        def make_color(str,val):
            t = Text(str, font='Arial', stroke_width=0, size=0.2)
            rect = Rectangle(width=0.5, height=0.4, fill_opacity=1, fill_color=val).set_color(val)
            return VGroup(rect,t).arrange(DOWN,buff=0.08)

        map_size = len(COLOR_MAP)
        group = VGroup(*[make_color(str,val) for str,val in COLOR_MAP.items()])      
     
        group.arrange_in_grid(6, 10, buff=0.4)
        self.add(group)
        self.wait(2)

        self.remove(group)

 


set_color_by_gradient

class ColorTest(Scene):
    def construct(self):       
        self.gradient_test()
        
    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)        

 

 

반응형