Skip to content

Instantly share code, notes, and snippets.

@uwezi
Last active April 15, 2023 21:33
Show Gist options
  • Save uwezi/6c16bc38a595f09e0b57e00155b30007 to your computer and use it in GitHub Desktop.
Save uwezi/6c16bc38a595f09e0b57e00155b30007 to your computer and use it in GitHub Desktop.
[Create a zig-zag line] Inline code to create a zig-zag line using a VMobject #manim #line #zigzag #vmobject
# https://discord.com/channels/581738731934056449/1086715297928581161/1086715297928581161
from manim import *
class zig(Scene):
def construct(self):
zag = VMobject()
n=4
zag.set_points_as_corners(
[[PI/2*i,np.sin(PI/2*i),0] for i in range(4*n+1)]
).scale_to_fit_width(5).move_to([-3,0,0],aligned_edge=LEFT)
self.add(zag)
dot1 = Dot().move_to([-4,-2,0]).set_color(YELLOW)
dot2 = Dot().move_to([+3,+3.5,0]).set_color(BLUE)
line = Line(dot1.get_center(),dot2.get_center()).set_color(RED)
zline = zag.copy().scale_to_fit_width(line.get_length()).rotate(line.get_angle())
zline.shift(dot1.get_center()-zline.get_start())
self.add(dot1,dot2)
self.play(Create(zline))
self.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment