mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
ImageToSound
This commit is contained in:
parent
7ab9d6ab86
commit
6a10e775b9
4 changed files with 98 additions and 9 deletions
52
animation/playground.py
Normal file
52
animation/playground.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
import numpy as np
|
||||
|
||||
from animation import Animation
|
||||
from transform import Transform
|
||||
from mobject import Mobject1D
|
||||
|
||||
from helpers import *
|
||||
|
||||
class VibratingString(Animation):
|
||||
DEFAULT_CONFIG = {
|
||||
"num_periods" : 1,
|
||||
"overtones" : 4,
|
||||
"amplitude" : 0.5,
|
||||
"radius" : SPACE_WIDTH/2,
|
||||
"center" : ORIGIN,
|
||||
"color" : "white",
|
||||
"run_time" : 3.0,
|
||||
"alpha_func" : None
|
||||
}
|
||||
def __init__(self, **kwargs):
|
||||
digest_config(self, kwargs)
|
||||
def func(x, t):
|
||||
return sum([
|
||||
(self.amplitude/((k+1)**2.5))*np.sin(2*mult*t)*np.sin(k*mult*x)
|
||||
for k in range(self.overtones)
|
||||
for mult in [(self.num_periods+k)*np.pi]
|
||||
])
|
||||
self.func = func
|
||||
Animation.__init__(self, Mobject1D(color = self.color), **kwargs)
|
||||
|
||||
def update_mobject(self, alpha):
|
||||
self.mobject.init_points()
|
||||
epsilon = self.mobject.epsilon
|
||||
self.mobject.add_points([
|
||||
[x*self.radius, self.func(x, alpha*self.run_time)+y, 0]
|
||||
for x in np.arange(-1, 1, epsilon/self.radius)
|
||||
for y in epsilon*np.arange(3)
|
||||
])
|
||||
self.mobject.shift(self.center)
|
||||
|
||||
|
||||
class TurnInsideOut(Transform):
|
||||
DEFAULT_CONFIG = {
|
||||
"interpolation_function" : path_along_arc(np.pi/2)
|
||||
}
|
||||
def __init__(self, mobject, **kwargs):
|
||||
mobject.sort_points(np.linalg.norm)
|
||||
mob_copy = mobject.copy()
|
||||
mob_copy.sort_points(lambda p : -np.linalg.norm(p))
|
||||
Transform.__init__(self, mobject, mob_copy, **kwargs)
|
||||
|
||||
|
|
@ -1,11 +1,14 @@
|
|||
from mobject import Mobject, Point
|
||||
from mobject.tex_mobject import TexMobject, TextMobject
|
||||
from mobject.image_mobject import ImageMobject
|
||||
|
||||
from scene import Scene
|
||||
|
||||
from animation import Animation
|
||||
from animation.transform import Transform, CounterclockwiseTransform, ApplyMethod
|
||||
from animation.simple_animations import ShowCreation, ShimmerIn
|
||||
from animation.meta_animations import DelayByOrder
|
||||
from animation.meta_animations import DelayByOrder, TransformAnimations
|
||||
from animation.playground import VibratingString
|
||||
|
||||
from topics.geometry import Line
|
||||
from topics.characters import ThoughtBubble
|
||||
|
@ -28,7 +31,7 @@ class AboutSpaceFillingCurves(TransformOverIncreasingOrders):
|
|||
self.bubble = ThoughtBubble().ingest_sub_mobjects()
|
||||
self.bubble.scale(1.5)
|
||||
|
||||
TransformOverIncreasingOrders.construct(self, FlowSnake, 3)
|
||||
TransformOverIncreasingOrders.construct(self, FlowSnake, 7)
|
||||
self.play(Transform(self.curve, self.bubble))
|
||||
self.show_infinite_objects()
|
||||
self.pose_question()
|
||||
|
@ -103,10 +106,43 @@ class AboutSpaceFillingCurves(TransformOverIncreasingOrders):
|
|||
|
||||
class PostponePhilosophizing(Scene):
|
||||
def construct(self):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
abstract, arrow, concrete = TextMobject([
|
||||
"Abstract", " $\\rightarrow$ ", "Concrete"
|
||||
]).scale(2).split()
|
||||
|
||||
self.add(abstract, arrow, concrete)
|
||||
self.dither()
|
||||
self.play(*[
|
||||
ApplyMethod(
|
||||
word1.replace, word2,
|
||||
interpolation_function = path_along_arc(np.pi/2)
|
||||
)
|
||||
for word1, word2 in it.permutations([abstract, concrete])
|
||||
])
|
||||
self.dither()
|
||||
|
||||
class WriteSomeSoftware(Scene):
|
||||
pass #Done viea screen capture, written here for organization
|
||||
|
||||
|
||||
|
||||
class ImageToSound(Scene):
|
||||
def construct(self):
|
||||
string = VibratingString(color = BLUE_D, run_time = 5)
|
||||
picture = ImageMobject("lion", invert = False)
|
||||
picture.scale(0.5)
|
||||
picture.sort_points(np.linalg.norm)
|
||||
string.mobject.sort_points(lambda p : -np.linalg.norm(p))
|
||||
|
||||
self.add(picture)
|
||||
self.dither()
|
||||
self.play(Transform(
|
||||
picture, string.mobject,
|
||||
run_time = 3,
|
||||
alpha_func = rush_into
|
||||
))
|
||||
self.remove(picture)
|
||||
self.play(string)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -10,10 +10,11 @@ from animation import *
|
|||
from mobject import *
|
||||
from constants import *
|
||||
from region import *
|
||||
from scene import Scene, NumberLineScene
|
||||
from script_wrapper import command_line_create_scene
|
||||
from scene import Scene
|
||||
from inventing_math import Underbrace
|
||||
|
||||
from topics.number_line import NumberLineScene
|
||||
|
||||
import random
|
||||
|
||||
MOVIE_PREFIX = "music_and_measure/"
|
||||
|
|
|
@ -40,7 +40,7 @@ class Scene(object):
|
|||
)
|
||||
self.background = self.original_background
|
||||
self.curr_frame = self.background
|
||||
self.frames = [self.curr_frame]
|
||||
self.frames = []
|
||||
self.mobjects = []
|
||||
|
||||
self.construct(*self.construct_args)
|
||||
|
|
Loading…
Add table
Reference in a new issue