以一种奇怪的方式写。

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

Write in a bizzare way

问题

如何以奇特的方式?

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

以一种奇怪的方式写。

英文:

How can I a bizzare way?

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

以一种奇怪的方式写。

答案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 = &quot;The wheels on the bus go round and round. The wheels on the bus go round and round all day long...&quot;
    # 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) &lt; 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 &lt; 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 = &quot;The wheels on the bus go &quot; + &quot;, &quot;.join([&quot;round and round&quot;]*3)
        txt = &quot; &quot;.join(
展开收缩
*7)
myTexTemplate = TexTemplate() myTexTemplate.add_to_preamble(r&quot;\usepackage{tikz}\usetikzlibrary{decorations.text}&quot;) tikz_code = rf&quot;&quot;&quot;\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}} &quot;&quot;&quot; t = Tex(tikz_code, tex_template=myTexTemplate).scale(0.8) self.play(Write(t), run_time=10) 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:

确定