← circus
Complex Morphs
Morphing shapes with holes
Python Code
from svan2d import (
Astroid,
Circle,
Color,
configure_logging,
ConverterType,
Ellipse,
hold,
PerforatedCircleState,
PerforatedStarState,
Point2D,
Polygon,
Star,
VElement,
VertexRenderer,
VScene,
VSceneExporter,
)
configure_logging(level="INFO")
FILL_COLOR = Color("#FDBE02")
STROKE_COLOR = Color("#AA0000")
def main():
# Create the scene
scene = VScene(width=1024, height=1024, background=Color("#000017"))
# equivalent to a Ring but the stroke around the hole which is present here
# can smoothly morph into vertex loops without surrounding strokes
s1 = PerforatedCircleState(
radius=200,
holes=[Circle(radius=100)],
fill_color=FILL_COLOR,
stroke_color=STROKE_COLOR,
stroke_width=6,
)
s2 = PerforatedCircleState(
radius=270,
holes=[
Circle(radius=50, pos=Point2D(0, -100)),
Star(num_points=5, inner_radius=40, outer_radius=70, pos=Point2D(-120, 60)),
Astroid(radius=100, num_cusps=4, curvature=0.3, pos=Point2D(100, 60)),
],
fill_color=FILL_COLOR,
stroke_color=STROKE_COLOR,
stroke_width=6,
holes_stroke_width=0,
)
s3 = PerforatedStarState(
num_points=5,
outer_radius=400,
inner_radius=200,
holes=[
Ellipse(rx=50, ry=40, pos=Point2D(-70, -80)),
Polygon(num_sides=3, radius=80, pos=Point2D(40, 40)),
],
fill_color=FILL_COLOR,
stroke_color=STROKE_COLOR,
stroke_width=6,
holes_stroke_width=0,
)
states = [s1, s2, s3, s2, s1]
element = VElement(renderer=VertexRenderer()).segment(
hold(states=states, duration=1.0 / (3 * len(states)))
)
scene = scene.add_element(element)
# Create the exporter
exporter = VSceneExporter(
scene=scene,
converter=ConverterType.PLAYWRIGHT,
output_dir="output/",
)
# Export to PNG file
exporter.to_mp4(
filename="complex_morph.mp4",
total_frames=240,
framerate=30,
png_width_px=1024,
)
if __name__ == "__main__":
main()