以一种奇怪的方式写。

huangapple go评论98阅读模式
英文:

Write in a bizzare way

问题

如何以奇特的方式?

例如,我想要这个图像(从外部开始):

以一种奇怪的方式写。

英文:

How can I a bizzare way?

For example, I want this figure (start from outside):

以一种奇怪的方式写。

答案1

得分: 2

  1. class roundandround(Scene):
  2. def construct(self):
  3. text = "The wheels on the bus go round and round. The wheels on the bus go round and round all day long..."
  4. # 将其合并为一个对象并将其缩放到特定长度
  5. textVMobject = Text(text).scale_to_fit_height(0.3)
  6. self.add(textVMobject)
  7. # 现在定义一个参数螺旋线
  8. steepness = 0.4/(2*PI)
  9. r0 = 3.5
  10. def fun(t):
  11. return [-(r0-steepness*t)*np.cos(t), (r0-steepness*t)*np.sin(t), 0]
  12. spiral = ParametricFunction(fun, t_range=[0, 16*PI, 0.1])
  13. self.add(spiral)
  14. i = 0
  15. pos = 0
  16. length = spiral.get_arc_length()
  17. textOnSpiral = VGroup()
  18. while ((pos/length) < 1):
  19. dummy = textVMobject[i].copy()
  20. point = spiral.point_from_proportion(pos/length)
  21. angle = np.arctan2(point[1],point[0]) - 90*DEGREES
  22. # 移动字符,但保持其垂直基线
  23. dummy.shift(dummy.get_center()[0]*LEFT).rotate(angle=angle, about_point=ORIGIN).shift(point)
  24. textOnSpiral += dummy
  25. i += 1
  26. if (i < len(textVMobject)):
  27. pos += textVMobject[i].get_center()[0] - textVMobject[i-1].get_center()[0]
  28. else:
  29. pos += 0.1
  30. i = 0
  31. self.wait()
  32. self.remove(textVMobject,spiral)
  33. self.play(Write(textOnSpiral), rate_functions=rate_functions.linear, run_time=4)
  34. self.wait()
英文:
  1. class roundandround(Scene):
  2. def construct(self):
  3. text = &quot;The wheels on the bus go round and round. The wheels on the bus go round and round all day long...&quot;
  4. # lets get it into one object and scale it to a certain length
  5. textVMobject = Text(text).scale_to_fit_height(0.3)
  6. self.add(textVMobject)
  7. # now lets define a parametric spiral
  8. steepness = 0.4/(2*PI)
  9. r0 = 3.5
  10. def fun(t):
  11. return [-(r0-steepness*t)*np.cos(t), (r0-steepness*t)*np.sin(t), 0]
  12. spiral = ParametricFunction(fun, t_range=[0, 16*PI, 0.1])
  13. self.add(spiral)
  14. i = 0
  15. pos = 0
  16. length = spiral.get_arc_length()
  17. textOnSpiral = VGroup()
  18. while ((pos/length) &lt; 1):
  19. dummy = textVMobject[i].copy()
  20. point = spiral.point_from_proportion(pos/length)
  21. angle = np.arctan2(point[1],point[0]) - 90*DEGREES
  22. # move the character, but keep its vertical baseline
  23. dummy.shift(dummy.get_center()[0]*LEFT).rotate(angle=angle, about_point=ORIGIN).shift(point)
  24. textOnSpiral += dummy
  25. i += 1
  26. if (i &lt; len(textVMobject)):
  27. pos += textVMobject[i].get_center()[0] - textVMobject[i-1].get_center()[0]
  28. else:
  29. pos += 0.1
  30. i = 0
  31. self.wait()
  32. self.remove(textVMobject,spiral)
  33. self.play(Write(textOnSpiral), rate_functions=rate_functions.linear, run_time=4)
  34. self.wait()

以一种奇怪的方式写。

答案2

得分: 1

以下是您提供的内容的中文翻译:

"manim可以使用LaTeX,LaTeX可以使用Tikz,Tikz可以沿着路径排版文本,所以..."

  1. class Test(Scene):
  2. def construct(self):
  3. s = "巴士上的车轮转" + ",".join(["一圈又一圈"]*3)
  4. txt = " ".join(
    展开收缩
    *7)
  5. myTexTemplate = TexTemplate()
  6. myTexTemplate.add_to_preamble(r"\usepackage{tikz}\usetikzlibrary{decorations.text}")
  7. tikz_code = rf"""\sffamily\scriptsize
  8. \begin{{tikzpicture}}[
  9. decoration={{
  10. reverse path,
  11. text effects along path,
  12. text={{{txt}}},
  13. text effects/.cd,
  14. text along path,
  15. }}
  16. ]
  17. \draw [decorate] (0,0)
  18. \foreach \i [evaluate={{\r=0.3+(\i/1500);}}] in {{0,5,...,4490}}{{ -- (\i:\r)}};
  19. \end{{tikzpicture}}
  20. """
  21. t = Tex(tikz_code, tex_template=myTexTemplate).scale(0.8)
  22. self.play(Write(t), run_time=10)
  23. self.wait(2)

结果:

以一种奇怪的方式写。

英文:

Well, manim can use LaTeX, and LaTeX can use Tikz, and Tikz can typeset text along a path so...

  1. class Test(Scene):
  2. def construct(self):
  3. s = &quot;The wheels on the bus go &quot; + &quot;, &quot;.join([&quot;round and round&quot;]*3)
  4. txt = &quot; &quot;.join(
    展开收缩
    *7)
  5. myTexTemplate = TexTemplate()
  6. myTexTemplate.add_to_preamble(r&quot;\usepackage{tikz}\usetikzlibrary{decorations.text}&quot;)
  7. tikz_code = rf&quot;&quot;&quot;\sffamily\scriptsize
  8. \begin{{tikzpicture}}[
  9. decoration={{
  10. reverse path,
  11. text effects along path,
  12. text={{{txt}}},
  13. text effects/.cd,
  14. text along path,
  15. }}
  16. ]
  17. \draw [decorate] (0,0)
  18. \foreach \i [evaluate={{\r=0.3+(\i/1500);}}] in {{0,5,...,4490}}{{ -- (\i:\r)}};
  19. \end{{tikzpicture}}
  20. &quot;&quot;&quot;
  21. t = Tex(tikz_code, tex_template=myTexTemplate).scale(0.8)
  22. self.play(Write(t), run_time=10)
  23. self.wait(2)

Result:

以一种奇怪的方式写。

huangapple
  • 本文由 发表于 2023年5月30日 08:24:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76360949.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定