-4

How can I a bizzare way?

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

enter image description here

C.S.
  • 105
  • 4

2 Answers2

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..."
    # 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()
    

enter image description here

uwezi
  • 551
  • 2
  • 3
1

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([s+".", s+", all the day long! ..."]*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:

Result

JLDiaz
  • 1,248
  • 9
  • 21