英文:
Write in a bizzare way
问题
如何以奇特的方式?
例如,我想要这个图像(从外部开始):
答案1
得分: 2
class roundandround(Scene):
def construct(self):
text = "The wheels on the bus go round and round. The wheels on the bus go round and round all day long..."
# 将其合并为一个对象并将其缩放到特定长度
textVMobject = Text(text).scale_to_fit_height(0.3)
self.add(textVMobject)
# 现在定义一个参数螺旋线
steepness = 0.4/(2*PI)
r0 = 3.5
def fun(t):
return [-(r0-steepness*t)*np.cos(t), (r0-steepness*t)*np.sin(t), 0]
spiral = ParametricFunction(fun, t_range=[0, 16*PI, 0.1])
self.add(spiral)
i = 0
pos = 0
length = spiral.get_arc_length()
textOnSpiral = VGroup()
while ((pos/length) < 1):
dummy = textVMobject[i].copy()
point = spiral.point_from_proportion(pos/length)
angle = np.arctan2(point[1],point[0]) - 90*DEGREES
# 移动字符,但保持其垂直基线
dummy.shift(dummy.get_center()[0]*LEFT).rotate(angle=angle, about_point=ORIGIN).shift(point)
textOnSpiral += dummy
i += 1
if (i < len(textVMobject)):
pos += textVMobject[i].get_center()[0] - textVMobject[i-1].get_center()[0]
else:
pos += 0.1
i = 0
self.wait()
self.remove(textVMobject,spiral)
self.play(Write(textOnSpiral), rate_functions=rate_functions.linear, run_time=4)
self.wait()
英文:
class roundandround(Scene):
def construct(self):
text = "The wheels on the bus go round and round. The wheels on the bus go round and round all day long..."
# lets get it into one object and scale it to a certain length
textVMobject = Text(text).scale_to_fit_height(0.3)
self.add(textVMobject)
# now lets define a parametric spiral
steepness = 0.4/(2*PI)
r0 = 3.5
def fun(t):
return [-(r0-steepness*t)*np.cos(t), (r0-steepness*t)*np.sin(t), 0]
spiral = ParametricFunction(fun, t_range=[0, 16*PI, 0.1])
self.add(spiral)
i = 0
pos = 0
length = spiral.get_arc_length()
textOnSpiral = VGroup()
while ((pos/length) < 1):
dummy = textVMobject[i].copy()
point = spiral.point_from_proportion(pos/length)
angle = np.arctan2(point[1],point[0]) - 90*DEGREES
# move the character, but keep its vertical baseline
dummy.shift(dummy.get_center()[0]*LEFT).rotate(angle=angle, about_point=ORIGIN).shift(point)
textOnSpiral += dummy
i += 1
if (i < len(textVMobject)):
pos += textVMobject[i].get_center()[0] - textVMobject[i-1].get_center()[0]
else:
pos += 0.1
i = 0
self.wait()
self.remove(textVMobject,spiral)
self.play(Write(textOnSpiral), rate_functions=rate_functions.linear, run_time=4)
self.wait()
答案2
得分: 1
以下是您提供的内容的中文翻译:
"manim可以使用LaTeX,LaTeX可以使用Tikz,Tikz可以沿着路径排版文本,所以..."
class Test(Scene):
def construct(self):
s = "巴士上的车轮转" + ",".join(["一圈又一圈"]*3)
txt = " ".join(展开收缩*7)
myTexTemplate = TexTemplate()
myTexTemplate.add_to_preamble(r"\usepackage{tikz}\usetikzlibrary{decorations.text}")
tikz_code = rf"""\sffamily\scriptsize
\begin{{tikzpicture}}[
decoration={{
reverse path,
text effects along path,
text={{{txt}}},
text effects/.cd,
text along path,
}}
]
\draw [decorate] (0,0)
\foreach \i [evaluate={{\r=0.3+(\i/1500);}}] in {{0,5,...,4490}}{{ -- (\i:\r)}};
\end{{tikzpicture}}
"""
t = Tex(tikz_code, tex_template=myTexTemplate).scale(0.8)
self.play(Write(t), run_time=10)
self.wait(2)
结果:
英文:
Well, manim can use LaTeX, and LaTeX can use Tikz, and Tikz can typeset text along a path so...
class Test(Scene):
def construct(self):
s = "The wheels on the bus go " + ", ".join(["round and round"]*3)
txt = " ".join(展开收缩*7)
myTexTemplate = TexTemplate()
myTexTemplate.add_to_preamble(r"\usepackage{tikz}\usetikzlibrary{decorations.text}")
tikz_code = rf"""\sffamily\scriptsize
\begin{{tikzpicture}}[
decoration={{
reverse path,
text effects along path,
text={{{txt}}},
text effects/.cd,
text along path,
}}
]
\draw [decorate] (0,0)
\foreach \i [evaluate={{\r=0.3+(\i/1500);}}] in {{0,5,...,4490}}{{ -- (\i:\r)}};
\end{{tikzpicture}}
"""
t = Tex(tikz_code, tex_template=myTexTemplate).scale(0.8)
self.play(Write(t), run_time=10)
self.wait(2)
Result:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论