motiongraphics / core /logo_animations.py
karthikeya1212's picture
Upload 26 files
7782338 verified
raw
history blame
14.4 kB
# app/core/animations/logo_animations.py
from pathlib import Path
from typing import Dict
import random
# def logo_build_lines(svg_path: Path, working_dir: Path, task_meta: Dict) -> Dict:
# scene_name = "LogoBuildLines"
# scene_code = f'''
# from manim import *
# class {scene_name}(Scene):
# def construct(self):
# # TODO: Implement logo build from lines/paths
# 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 logo_build_lines(svg_path: Path, working_dir: Path, task_meta: Dict) -> Dict:
scene_name = "LogoBuildLines"
scene_code = f'''
from manim import *
import random
class {scene_name}(Scene):
def construct(self):
# Load SVG logo
svg = SVGMobject("{svg_path.name}")
svg.set(width=6)
svg.set_stroke(width=2)
svg.set_fill(opacity=1)
svg.move_to(ORIGIN)
# Split into subpaths for individual animation
subpaths = svg.family_members_with_points()
# Start each subpath invisible & slightly smaller
for sub in subpaths:
sub.set_opacity(0.05)
sub.scale(0.98)
# Animate each path individually with cinematic timing
for sub in subpaths:
delay = random.uniform(0, 0.05) # tiny stagger for natural feel
self.wait(delay)
self.play(
Create(sub),
sub.animate.set_opacity(1).scale(1.0),
run_time=0.35,
rate_func=smooth
)
# Optional: final gentle pop to settle logo
self.play(svg.animate.scale(1.02), run_time=0.15, rate_func=there_and_back)
self.wait(0.5)
'''
return {"scene_name": scene_name, "scene_code": scene_code}
# def logo_fade_particle(svg_path: Path, working_dir: Path, task_meta: Dict) -> Dict:
# scene_name = "LogoFadeParticle"
# scene_code = f'''
# from manim import *
# class {scene_name}(Scene):
# def construct(self):
# svg = SVGMobject("{svg_path.name}")
# self.play(FadeIn(svg), run_time=0.8)
# # TODO: Add particles using small dots or flocking
# self.wait(0.5)
# '''
# return {"scene_name": scene_name, "scene_code": scene_code}
# def logo_fade_particle(svg_path: Path, working_dir: Path, task_meta: Dict) -> Dict:
# scene_name = "LogoFadeParticle"
# scene_code = f'''
# from manim import *
# import random
# class {scene_name}(Scene):
# def construct(self):
# # Load SVG logo
# svg = SVGMobject("{svg_path.name}")
# svg.set(width=6)
# svg.set_stroke(width=2)
# svg.set_fill(opacity=1)
# svg.move_to(ORIGIN)
# svg.set_opacity(0) # start invisible
# # Smooth fade-in with subtle scale pop
# self.play(svg.animate.set_opacity(1).scale(1.05), run_time=0.8, rate_func=smooth)
# self.play(svg.animate.scale(0.98), run_time=0.15, rate_func=there_and_back)
# # Particle effect from the logo edges
# points = svg.get_all_points()
# particles = VGroup(*[Dot(point, radius=0.04, color=WHITE, fill_opacity=0.6) for point in points])
# # Animate particles floating outward
# for particle in particles:
# offset = [random.uniform(-1,1), random.uniform(-1,1), 0]
# self.play(particle.animate.shift(offset).set_opacity(0), run_time=random.uniform(0.5,1.0), rate_func=smooth, lag_ratio=0.1)
# self.wait(0.5)
# '''
# return {"scene_name": scene_name, "scene_code": scene_code}
# def logo_fade_particle(svg_path: Path, working_dir: Path, task_meta: Dict) -> Dict:
# scene_name = "LogoParticleBreak"
# scene_code = f"""
# from manim import *
# import random
# class {scene_name}(Scene):
# def construct(self):
# # Load logo
# svg = SVGMobject(r"{svg_path.name}")
# svg.set(width=6)
# svg.set_stroke(width=2)
# svg.set_fill(opacity=1)
# svg.move_to(ORIGIN)
# svg.set_opacity(0)
# # Fade-in + pop
# self.play(
# svg.animate.set_opacity(1).scale(1.05),
# run_time=0.8,
# rate_func=smooth
# )
# self.play(
# svg.animate.scale(0.97),
# run_time=0.25,
# rate_func=there_and_back
# )
# # Sample SVG points
# raw_points = svg.get_all_points()
# points = raw_points[::2] # skip every 2nd for density + speed
# # Create particles on edges
# particles = VGroup(
# *[
# Dot(point, radius=0.035, color=WHITE, fill_opacity=0.9)
# for point in points
# ]
# )
# particles.set_opacity(0)
# self.add(particles)
# # Dissolve logo into particles
# self.play(
# svg.animate.set_opacity(0),
# particles.animate.set_opacity(1),
# run_time=0.6,
# rate_func=smooth
# )
# # Outward particle spread
# anims = []
# for p in particles:
# offset = [
# random.uniform(-1.2, 1.2),
# random.uniform(-1.2, 1.2),
# 0
# ]
# anims.append(p.animate.shift(offset).set_opacity(0))
# self.play(
# LaggedStart(*anims, lag_ratio=0.008),
# run_time=1.3,
# rate_func=smooth
# )
# self.wait(0.3)
# """
# return {"scene_name": scene_name, "scene_code": scene_code}
# def logo_fade_particle(svg_path: Path, working_dir: Path, task_meta: Dict) -> Dict:
# scene_name = "LogoParticleBreak"
# scene_code = f"""
# from manim import *
# import random
# class {scene_name}(Scene):
# def construct(self):
# # Load SVG as grouped paths
# svg = SVGMobject(r"{svg_path.name}")
# svg.set(width=6)
# svg.set_stroke(width=2)
# svg.set_fill(opacity=1)
# svg.move_to(ORIGIN)
# svg.set_opacity(0)
# # Fade-in + pop
# self.play(svg.animate.set_opacity(1).scale(1.05), run_time=0.8, rate_func=smooth)
# self.play(svg.animate.scale(0.97), run_time=0.25, rate_func=there_and_back)
# # Collect points & colors from subobjects
# points = []
# colors = []
# for sub in svg.family_members_with_points():
# pts = sub.get_points()
# col = sub.get_fill_color()
# for p in pts[::3]: # skip for smoother density
# points.append(p)
# colors.append(col)
# # Create cinematic glowing particles
# particles = VGroup()
# for p, col in zip(points, colors):
# part = Circle(radius=0.03, color=col, fill_color=col, fill_opacity=1)
# part.move_to(p)
# part.set_opacity(0)
# part.scale(random.uniform(0.6, 1.2)) # natural variation
# particles.add(part)
# self.add(particles)
# # Logo dissolves → particles appear
# self.play(
# svg.animate.set_opacity(0),
# particles.animate.set_opacity(1),
# run_time=0.5,
# rate_func=smooth,
# )
# # Particle outward scatter
# anims = []
# for p in particles:
# offset = [
# random.uniform(-1.3, 1.3),
# random.uniform(-1.3, 1.3),
# 0
# ]
# anims.append(
# p.animate.shift(offset)
# .scale(random.uniform(0.6, 1.8))
# .set_opacity(0)
# )
# self.play(
# LaggedStart(*anims, lag_ratio=0.006),
# run_time=1.4,
# rate_func=smooth
# )
# self.wait(0.3)
# """
# return {"scene_name": scene_name, "scene_code": scene_code}
# def logo_fade_particle(svg_path: Path, working_dir: Path, task_meta: Dict) -> Dict:
# scene_name = "LogoParticlesFullPoints"
# scene_code = f"""
# from manim import *
# import numpy as np
# import random
# class {scene_name}(Scene):
# def construct(self):
# # Load SVG
# svg = SVGMobject(r"{svg_path.name}")
# svg.set(width=6)
# svg.set_stroke(width=2)
# svg.set_fill(opacity=1)
# svg.move_to(ORIGIN)
# svg.scale(0.8) # start smaller for pop effect
# svg.set_opacity(0)
# # Smooth fade-in with tiny pop
# self.play(
# svg.animate.set_opacity(1).scale(1.05),
# run_time=0.8,
# rate_func=smooth
# )
# self.play(svg.animate.scale(0.97), run_time=0.2, rate_func=smooth)
# # Use all points from the entire SVG
# points, colors = [], []
# for sub in svg.family_members_with_points():
# pts = sub.get_all_points() # all points of the subpath
# if len(pts) == 0:
# continue
# col = sub.get_fill_color()
# for p in pts:
# points.append(p)
# colors.append(col)
# # Create particles at all points
# particles = VGroup()
# for p, col in zip(points, colors):
# part = Dot(point=p, radius=0.03, color=col)
# part.set_opacity(1) # start visible
# particles.add(part)
# self.add(particles)
# # Transform SVG into particles (SVG fades as particles scatter)
# scatter_anims = []
# for part in particles:
# offset = np.array([
# random.uniform(-1.5, 1.5),
# random.uniform(-1.5, 1.5),
# 0
# ])
# scatter_anims.append(
# part.animate.shift(offset)
# .scale(random.uniform(0.5, 1.5))
# .set_opacity(0)
# )
# self.play(
# svg.animate.set_opacity(0),
# LaggedStart(*scatter_anims, lag_ratio=0.003),
# run_time=1.5,
# rate_func=smooth
# )
# self.wait(0.5)
# """
# return {"scene_name": scene_name, "scene_code": scene_code}
def logo_fade_particle(svg_path: Path, working_dir: Path, task_meta: Dict) -> Dict:
scene_name = "LogoParticlesBlast"
scene_code = f"""
from manim import *
import numpy as np
import random
class {scene_name}(Scene):
def construct(self):
# Load SVG
svg = SVGMobject(r"{svg_path.name}")
svg.set(width=6)
svg.set_stroke(width=2)
svg.set_fill(opacity=1)
svg.move_to(ORIGIN)
svg.scale(0.8) # start smaller for pop effect
svg.set_opacity(0)
# Smooth fade-in with tiny pop
self.play(
svg.animate.set_opacity(1).scale(1.05),
run_time=0.8,
rate_func=smooth
)
self.play(svg.animate.scale(0.97), run_time=0.2, rate_func=smooth)
# Use all points from the SVG
points, colors = [], []
for sub in svg.family_members_with_points():
pts = sub.get_all_points()
if len(pts) == 0:
continue
col = sub.get_fill_color()
for p in pts:
points.append(p)
colors.append(col)
# Create particles at all points
particles = VGroup()
for p, col in zip(points, colors):
part = Dot(point=p, radius=0.03, color=col)
part.set_opacity(1)
particles.add(part)
self.add(particles)
# SVG transforms into particles with blast effect
blast_anims = []
for part in particles:
# Random direction vector
angle = random.uniform(0, 2 * np.pi)
distance = random.uniform(1.0, 3.0) # how far it flies
offset = np.array([distance * np.cos(angle),
distance * np.sin(angle),
random.uniform(-0.3, 0.3)])
# Particle animation: move, fade, and scale
blast_anims.append(
part.animate.shift(offset)
.scale(random.uniform(0.5, 1.5))
.set_opacity(0)
)
# Play SVG fade + particle blast together
self.play(
svg.animate.set_opacity(0),
LaggedStart(*blast_anims, lag_ratio=0.002),
run_time=2.0, # slow motion blast
rate_func=smooth
)
self.wait(0.5)
"""
return {"scene_name": scene_name, "scene_code": scene_code}
def logo_spin_scale(svg_path: Path, working_dir: Path, task_meta: Dict) -> Dict:
scene_name = "LogoSpinScale"
scene_code = f'''
from manim import *
class {scene_name}(Scene):
def construct(self):
svg = SVGMobject("{svg_path.name}")
svg.scale(0.5)
self.play(Rotate(svg, angle=TAU), svg.animate.scale(1.2), run_time=1)
self.wait(0.5)
'''
return {"scene_name": scene_name, "scene_code": scene_code}
def logo_stroke_draw(svg_path: Path, working_dir: Path, task_meta: Dict) -> Dict:
scene_name = "LogoStrokeDraw"
scene_code = f'''
from manim import *
class {scene_name}(Scene):
def construct(self):
# TODO: Animate stroke drawing by tracing paths
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 logo_glitch(svg_path: Path, working_dir: Path, task_meta: Dict) -> Dict:
scene_name = "LogoGlitch"
scene_code = f'''
from manim import *
class {scene_name}(Scene):
def construct(self):
svg = SVGMobject("{svg_path.name}")
self.play(FadeIn(svg), run_time=0.4)
# TODO: Implement quick offset copies to simulate glitch
self.wait(0.5)
'''
return {"scene_name": scene_name, "scene_code": scene_code}