Skip to content

Instantly share code, notes, and snippets.

@uwezi
Last active August 23, 2025 11:35
Show Gist options
  • Save uwezi/4c870580f5331645c811973c08740c07 to your computer and use it in GitHub Desktop.
Save uwezi/4c870580f5331645c811973c08740c07 to your computer and use it in GitHub Desktop.
[La Linea] Animation of a diamond breaking a sine wave. #manim #union #boolean
from manim import *
class possible2(Scene):
def construct(self):
phase = ValueTracker(0)
def bottom():
return VMobject().add_points_as_corners(
[
*[[x,0.5*np.sin(x-phase.get_value()),0] for x in np.linspace(-8,8,1000)],
[8,-8,0],[-8,-8,0],[-8,0,0]
]
).reverse_direction()
object = Square().rotate(45*DEGREES).move_to([0,-3,0])
wave = always_redraw(lambda:
Union(
bottom(),
object.move_to([0,-3+0.5*phase.get_value(),0])
).set_stroke(width=3,color=WHITE).set_fill(opacity=0)
)
self.add(wave)
self.play(
phase.animate.set_value(4*PI), run_time=4, rate_func=rate_functions.linear
)
self.wait()
class possible3(Scene):
def construct(self):
phase = ValueTracker(0)
def bottom():
return VMobject().add_points_as_corners(
[
*[[x,0.5*np.sin(x-phase.get_value()),0] for x in np.linspace(-8,8,1000)],
[8,-8,0],[-8,-8,0],[-8,0,0]
]
).reverse_direction()
object = Square(stroke_width=0,fill_opacity=0).set_z_index(-10).rotate(45*DEGREES).move_to([0,-3,0])
self.add(object)
wave = always_redraw(lambda:
Union(
bottom(),
object
).set_stroke(width=3,color=WHITE).set_fill(opacity=0)
)
self.add(wave)
path = Arc(radius=4,start_angle=0,angle=PI)
self.play(
MoveAlongPath(object,path),
phase.animate.set_value(4*PI), run_time=4, rate_func=rate_functions.linear
)
self.wait()
class possible4(Scene):
def construct(self):
phase = ValueTracker(0)
def bottom():
return VMobject().add_points_as_corners(
[
*[[x,0.5*np.sin(x-phase.get_value()),0] for x in np.linspace(-8,8,1000)],
[8,-8,0],[-8,-8,0],[-8,0,0]
]
).reverse_direction()
object = Square(stroke_width=0,fill_opacity=0).set_z_index(-10).rotate(45*DEGREES).move_to([0,-3,0])
self.add(object)
wave = always_redraw(lambda:
Union(
bottom(),
object
).set_stroke(width=3,color=WHITE).set_fill(opacity=0)
)
self.add(wave)
path = FunctionGraph(
lambda x: 3-0.5*x**2,
x_range=[-4,4,0.1]
).reverse_direction()
self.play(
MoveAlongPath(object,path),
phase.animate.set_value(4*PI), run_time=4, rate_func=rate_functions.linear
)
self.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment