motiongraphics / core /shape_animations.py
karthikeya1212's picture
Upload 26 files
7782338 verified
raw
history blame
1.9 kB
# app/core/animations/shape_animations.py
from pathlib import Path
from typing import Dict
def line_draw(svg_path: Path, working_dir: Path, task_meta: Dict) -> Dict:
scene_name = "LineDraw"
scene_code = f'''
from manim import *
class {scene_name}(Scene):
def construct(self):
# TODO: Draw strokes of shapes (convert svg paths to strokes)
svg = SVGMobject("{svg_path.name}")
self.play(Write(svg), run_time=1)
self.wait(0.5)
'''
return {"scene_name": scene_name, "scene_code": scene_code}
def shape_morph(svg_path: Path, working_dir: Path, task_meta: Dict) -> Dict:
scene_name = "ShapeMorph"
scene_code = f'''
from manim import *
class {scene_name}(Scene):
def construct(self):
# TODO: Morph shapes — will require matching points
svg = SVGMobject("{svg_path.name}")
self.play(FadeIn(svg), run_time=0.8)
self.wait(0.5)
'''
return {"scene_name": scene_name, "scene_code": scene_code}
def grow_center(svg_path: Path, working_dir: Path, task_meta: Dict) -> Dict:
scene_name = "GrowFromCenter"
scene_code = f'''
from manim import *
class {scene_name}(Scene):
def construct(self):
svg = SVGMobject("{svg_path.name}").scale(0.2)
self.play(svg.animate.scale(5), run_time=1)
self.wait(0.5)
'''
return {"scene_name": scene_name, "scene_code": scene_code}
def floating_bounce(svg_path: Path, working_dir: Path, task_meta: Dict) -> Dict:
scene_name = "FloatingBounce"
scene_code = f'''
from manim import *
class {scene_name}(Scene):
def construct(self):
svg = SVGMobject("{svg_path.name}")
self.play(svg.animate.shift(UP*0.3), run_time=0.6)
self.play(svg.animate.shift(DOWN*0.3), run_time=0.6)
self.wait(0.5)
'''
return {"scene_name": scene_name, "scene_code": scene_code}