Updated example scenes

This commit is contained in:
Grant Sanderson 2018-08-12 19:06:08 -07:00
parent 9e534fb78f
commit 8033bee533
3 changed files with 32 additions and 116 deletions

View file

@ -37,6 +37,7 @@ from continual_animation.from_animation import *
from continual_animation.numbers import *
from continual_animation.update import *
from mobject.coordinate_systems import *
from mobject.frame import *
from mobject.functions import *
from mobject.geometry import *

View file

@ -1,7 +1,6 @@
#!/usr/bin/env python
from .big_ol_pile_of_manim_imports import *
from big_ol_pile_of_manim_imports import *
# To watch one of these scenes, run the following:
# python extract_scene.py file_name <SceneName> -p
@ -18,6 +17,7 @@ class SquareToCircle(Scene):
square = Square()
square.flip(RIGHT)
square.rotate(-3 * TAU / 8)
circle.set_fill(PINK, opacity=0.5)
self.play(ShowCreation(square))
self.play(Transform(square, circle))
@ -28,7 +28,7 @@ class WarpSquare(Scene):
def construct(self):
square = Square()
self.play(ApplyPointwiseFunction(
lambda x_y_z: complex_to_R3(np.exp(complex(x_y_z[0], x_y_z[1]))),
lambda point: complex_to_R3(np.exp(R3_to_complex(point))),
square
))
self.wait()
@ -36,125 +36,40 @@ class WarpSquare(Scene):
class WriteStuff(Scene):
def construct(self):
self.play(Write(TextMobject("Stuff").scale(3)))
example_text = TextMobject(
"This is a some text",
tex_to_color_map={"text": YELLOW}
)
example_tex = TexMobject(
"\\sum_{k=1}^\\infty {1 \\over k^2} = {\\pi^2 \\over 6}",
)
group = VGroup(example_text, example_tex)
group.arrange_submobjects(DOWN)
group.set_width(FRAME_WIDTH - 2 * LARGE_BUFF)
class Rotation3d(ThreeDScene):
def construct(self):
# STEP 1
# Build two cube in the 3D scene, one for around the origin,
# the other shifted along the vector RIGHT + UP + OUT
cube_origin = Cube(fill_opacity=0.8, stroke_width=1.,
side_length=1., fill_color=WHITE)
# RIGHT side: Red
# UP side: Green
# OUT side: Blue
orientations = [IN, OUT, LEFT, RIGHT, UP, DOWN]
for face, orient in zip(cube_origin.family_members_with_points(), orientations):
if np.array_equal(orient, RIGHT):
face.set_style_data(fill_color=RED)
elif np.array_equal(orient, UP):
face.set_style_data(fill_color=GREEN)
elif np.array_equal(orient, OUT):
face.set_style_data(fill_color=BLUE)
cube_shifted = Cube(fill_opacity=0.8, stroke_width=1.,
side_length=1., fill_color=BLUE)
shift_vec = 2 * (RIGHT + UP + OUT)
cube_shifted.shift(shift_vec)
# STEP 2
# Add the cubes in the 3D scene
self.add(cube_origin)
self.add(cube_shifted)
# STEP 3
# Setup the camera position
phi, theta, distance = ThreeDCamera().get_spherical_coords()
angle_factor = 0.9
phi += 2 * np.pi / 4 * angle_factor
theta += 3 * 2 * np.pi / 8
self.set_camera_position(phi, theta, distance)
self.play(Write(example_text))
self.play(Write(example_tex))
self.wait()
# STEP 4
# Animation
# Animation 1: rotation around the Z-axis with the ORIGIN of the space
# as center of rotation
theta += 2 * np.pi
self.move_camera(phi, theta, distance,
run_time=5)
# Animation 2: shift the space in order of to get the center of the shifted cube
# as the next center of rotation
cube_center = cube_shifted.get_center()
self.move_camera(center_x=cube_center[0],
center_y=cube_center[1],
center_z=cube_center[2],
run_time=2)
# Animation 3: rotation around the Z-axis with the center of the shifted cube
# as center of rotation
theta += 2 * np.pi
self.move_camera(phi, theta, distance,
run_time=5)
class SpinAroundCube(ThreeDScene):
# Take a look at ThreeDSCene in three_dimensions.py.
# This has a few methods on it like set_camera_position
# and move_camera that will be useful. The main thing to
# know about these is that the camera position is thought
# of as having spherical coordinates, phi and theta.
# In general, the nature of how this 3d camera works
# is not always robust, you might discover little
# quirks here or there
class UdatersExample(Scene):
def construct(self):
axes = ThreeDAxes()
cube = Cube(
fill_opacity=1,
stroke_color=LIGHT_GREY,
stroke_width=1,
decimal = DecimalNumber(
0,
show_ellipsis=True,
num_decimal_places=3,
include_sign=True,
)
# The constant OUT is np.array([0, 0, 1])
cube.next_to(ORIGIN, UP + RIGHT + OUT)
self.add(axes, cube)
square = Square().to_edge(UP)
# The camera starts positioned with phi=0, meaning it
# is directly above the xy-plane, and theta = -TAU/4,
# which makes the "down" direction of the screen point
# in the negative y direction.
# This animates a camera movement
self.move_camera(
# Tilted 20 degrees off xy plane (70 degrees off the vertical)
phi=(70. / 360.) * TAU,
# Positioned above the third quadrant of
# the xy-plane
theta=(-110. / 360.) * TAU,
# pass in animation config just like a .play call
run_time=3
decimal.add_updater(lambda d: d.next_to(square, RIGHT))
decimal.add_updater(lambda d: d.set_value(square.get_center()[1]))
self.add(square, decimal)
self.play(
square.to_edge, DOWN,
rate_func=there_and_back,
run_time=5,
)
self.wait()
# If you want the camera to slowly rotate about
# the z-axis
self.begin_ambient_camera_rotation()
self.wait(4)
self.play(FadeOut(cube))
text = TextMobject("Your ad here")
text.rotate(TAU / 4, axis=RIGHT)
text.next_to(cube, OUT)
self.play(Write(text))
# If you want to play animations while moving the camera,
# include them in an "added_anims" list to move_camera
self.move_camera(
theta=-0.2 * TAU,
added_anims=[
text.shift, 3 * OUT,
text.set_fill, {"opacity": 1},
]
)
self.wait(4)
# See old_projects folder for many, many more

View file

@ -471,9 +471,9 @@ class Scene(Container):
static_image = self.get_frame()
total_run_time = 0
for t in self.get_animation_time_progression(animations):
self.continual_update(dt=t - total_run_time)
for animation in animations:
animation.update(t / animation.run_time)
self.continual_update(dt=t - total_run_time)
self.update_frame(moving_mobjects, static_image)
self.add_frames(self.get_frame())
total_run_time = t