CharCreature#

[1]:
from manim import *
from char_creature import CharCreature, ShowBubble, RoundBubble

config.media_embed = True; config.media_width = "100%"
_RV = "-v WARNING -qm --progress_bar None --disable_caching Example"
_RI = "-v WARNING -s --progress_bar None --disable_caching Example"
_RV_mid = "-v WARNING -qm -r 1200,300 --progress_bar None --disable_caching Example"
_RI_mid = "-v WARNING -s -r 1200,300 --progress_bar None --disable_caching Example"
Manim Community v0.17.3

[2]:
class OmegaCreature(CharCreature):
  def __init__(self, eyes_scale=2.7,
                     eyes_prop=[0.5,0.05],
                     eyes_buff=0.09,
                     body_scale=7,
                     color=RED,
                     **kwargs):
    body = MathTex("\\Omega").scale(body_scale).set_color(color)
    super().__init__(body,
                     eyes_scale=eyes_scale,
                     eyes_prop=eyes_prop,
                     eyes_buff=eyes_buff,
                     **kwargs)
[34]:
class Example(Scene):
  def construct(self):
    omega_creature = OmegaCreature().scale(2)
    self.add(omega_creature)

%manim $_RI
_images/CHP_1_3_0.png
[33]:
class Example(Scene):
  def construct(self):
    omega = OmegaCreature().scale(2)
    self.add(omega)
    self.play(omega.blink())
    self.play(omega.look_at(LEFT))
    self.play(omega.look_at(RIGHT))
    self.play(omega.look_at(RIGHT + UP * 0.4))
    self.play(omega.blink())
    self.wait()

%manim $_RV
[29]:
class Example(Scene):
  #        x_alpha, y_alpha
  eyes_prop = [0.2, 0.4]
  eyes_buff = 0
  eyes_scale = 3
  def construct(self):
    X_ALPHA, Y_ALPHA = self.eyes_prop
    omega = OmegaCreature(
      eyes_prop=[X_ALPHA, Y_ALPHA],
      eyes_buff=self.eyes_buff,
      eyes_scale=self.eyes_scale
    ).scale(2)
    omega.to_edge(DOWN)
    nl_kwargs = {"stroke_width": 7,
                 "tick_size": 0.3,
                 "x_range": [0,1,1]}
    height = NumberLine(
      length=omega.body.height,
      **nl_kwargs
    ).rotate(-PI/2).set_color(BLUE)
    width = NumberLine(
      length=omega.body.width,
      **nl_kwargs
    ).set_color(GREEN_D)
    height.next_to(omega.body, LEFT, aligned_edge=DOWN)
    width.next_to(omega.body, UP, aligned_edge=LEFT)
    x_dot = Line(
      width.n2p(X_ALPHA) + UP*0.3,
      [width.n2p(X_ALPHA)[0], omega.get_bottom()[1], 1],
      stroke_width=6
    ).match_color(width)
    y_dot = Line(
      height.n2p(Y_ALPHA) + LEFT*0.3,
      [omega.get_right()[0], height.n2p(Y_ALPHA)[1], 1],
      stroke_width=6
    ).match_color(height)
    up_brace = BraceBetweenPoints(
      width.n2p(X_ALPHA), width.n2p(0), buff=0.4
    ).match_color(width)
    left_brace = BraceBetweenPoints(
      height.n2p(0), height.n2p(Y_ALPHA), buff=0.4
    ).match_color(height)
    x_tex = up_brace.get_tex(f"\\tt x\_alpha={X_ALPHA}")\
        .match_color(width)
    y_tex = left_brace.get_tex(f"\\tt y\_alpha={Y_ALPHA}")\
        .match_color(height)
    self.add(
        omega,
        height,   width,
        x_dot,    y_dot,
        up_brace, left_brace,
        x_tex,    y_tex
    )

%manim $_RI
_images/CHP_1_5_0.png
[31]:
class ACreature(CharCreature):
  def __init__(self, eyes_scale=2.7,
                     eyes_prop=[0.5,0.1],
                     eyes_buff=0.09,
                     body_scale=7,
                     color=TEAL,
                     **kwargs):
    body = Tex("A").scale(body_scale).set_color(color)
    super().__init__(body,
                     eyes_scale=eyes_scale,
                     eyes_prop=eyes_prop,
                     eyes_buff=eyes_buff,
                     **kwargs)

class TCreature(CharCreature):
  def __init__(self, eyes_scale=2.7,
                     eyes_prop=[0.5,0.25],
                     eyes_buff=0,
                     body_scale=7,
                     color=RED,
                     **kwargs):
    body = Tex("t").scale(body_scale).set_color(color)
    super().__init__(body,
                     eyes_scale=eyes_scale,
                     eyes_prop=eyes_prop,
                     eyes_buff=eyes_buff,
                     **kwargs)
[35]:
class Example(Scene):
  def construct(self):
    a_creature = ACreature().to_corner(DL)
    omega_creature = OmegaCreature()
    omega_creature.next_to(a_creature, UP).to_edge(RIGHT)
    t_creature = TCreature().to_corner(UL)
    a_bubble = RoundBubble(r"""\flushleft
    This is an example of how to use \\
    {\tt CharCreature}, you can define the \\
    Char and eyes position.
    """, a_creature.get_right(), RIGHT)
    o_bubble = RoundBubble(r"""\flushleft
    You can also animate the blinking of\\
    the eyes and move them to positions\\
    on the screen.
    """, omega_creature.get_left(), LEFT, flip=UP)
    t_bubble = RoundBubble("WOW, that's amazing!", t_creature.get_right())
    self.play(FadeIn(a_creature, omega_creature))
    self.play(a_creature.look_at(UP * 0.3 + RIGHT))
    self.play(a_creature.blink())
    self.play(omega_creature.look_at(DOWN * 0.3 + LEFT))
    self.play(omega_creature.blink())
    self.play(ShowBubble(a_bubble))
    self.play(omega_creature.blink())
    self.play(ShowBubble(o_bubble))
    self.wait()
    self.play(FadeIn(t_creature))
    self.play(ShowBubble(t_bubble))
    self.play(
      a_creature.look_at(UP),
      omega_creature.look_at(UP * 0.3 + LEFT),
    )
    self.play(t_creature.blink())
    self.play(a_creature.blink())
    self.play(omega_creature.blink())
    self.wait(3)

%manim $_RV