Skip to content

Instantly share code, notes, and snippets.

@sorrell
Created April 1, 2020 20:14
Show Gist options
  • Save sorrell/b8ff936a6f1ab8c1446943487959b1a9 to your computer and use it in GitHub Desktop.
Save sorrell/b8ff936a6f1ab8c1446943487959b1a9 to your computer and use it in GitHub Desktop.
First hack at manim
from manimlib.imports import *
class makeText(Scene):
def createArrowAndDesc(self, mobj_next_to, desc, dir=UP):
arrow = Vector(direction=dir)
arrow.next_to(mobj_next_to, dir*-1)
desc = TextMobject(desc)
desc.next_to(arrow, dir*-1)
group = VGroup(arrow, desc)
return arrow, desc, group
def showAndWriteGroup(self, group):
arrow = group.submobjects[0]
text = group.submobjects[1]
self.play(GrowArrow(arrow))
self.wait(1)
self.play(Write(text))
self.wait(1)
def construct(self):
user = TextMobject("\\texttt{runner}", color=BLUE)
at = TextMobject("\\texttt{@}")
host = TextMobject("\\texttt{e0bb35481dc9}", color=RED)
colon = TextMobject(":")
cwd = TextMobject("\\textapprox\\texttt{/LinuxTut-env-1}", color=GREEN)
dollar = TextMobject("\\texttt{\$}")
prompt = VGroup(user, at, host, colon, cwd, dollar)
prompt.arrange()
user_arrow, user_desc, user_group = self.createArrowAndDesc(user, "user")
host_arrow, host_desc, host_group = self.createArrowAndDesc(host, "host")
cwd_arrow, cwd_desc, cwd_group = self.createArrowAndDesc(cwd, "current directory")
dollar_arrow, dollar_desc, dollar_group = self.createArrowAndDesc(dollar, "user type")
self.wait(1)
self.play(Write(prompt))
self.wait(1)
self.play(FadeOut(at), FadeOut(host), FadeOut(colon), FadeOut(cwd), FadeOut(dollar))
self.showAndWriteGroup(user_group)
self.play(FadeIn(at), FadeIn(host), FadeOut(user_desc), FadeOut(user_arrow))
self.showAndWriteGroup(host_group)
self.play(FadeIn(colon), FadeIn(cwd), FadeOut(host_desc), FadeOut(host_arrow))
self.showAndWriteGroup(cwd_group)
self.play(FadeIn(dollar), FadeOut(cwd_desc), FadeOut(cwd_arrow))
self.showAndWriteGroup(dollar_group)
# debug_group = VGroup(user_arrow, user_desc, host_arrow, host_desc, cwd_arrow, cwd_desc, dollar_arrow, dollar_desc)
# attrs = vars(debug_group.submobjects[1])
# print(', '.join("%s: %s" % item for item in attrs.items()))
#self.play(Write(debug_group))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment