mirror of
https://github.com/ManimCommunity/manim.git
synced 2026-06-22 10:01:47 +00:00
remove scenes depending on cairo camera subclasses
This commit is contained in:
parent
9c40838fcb
commit
b411dbd298
3 changed files with 0 additions and 323 deletions
|
|
@ -73,12 +73,10 @@ from .mobject.types.vectorized_mobject import *
|
|||
from .mobject.value_tracker import *
|
||||
from .mobject.vector_field import *
|
||||
from .renderer.cairo_renderer import *
|
||||
from .scene.moving_camera_scene import *
|
||||
from .scene.scene import *
|
||||
from .scene.scene_file_writer import *
|
||||
from .scene.section import *
|
||||
from .scene.vector_space_scene import *
|
||||
from .scene.zoomed_scene import *
|
||||
from .utils import color, rate_functions, unit
|
||||
from .utils.bezier import *
|
||||
from .utils.color import *
|
||||
|
|
|
|||
|
|
@ -1,112 +0,0 @@
|
|||
"""A scene whose camera can be moved around.
|
||||
|
||||
.. SEEALSO::
|
||||
|
||||
:mod:`.moving_camera`
|
||||
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
.. manim:: ChangingCameraWidthAndRestore
|
||||
|
||||
class ChangingCameraWidthAndRestore(MovingCameraScene):
|
||||
def construct(self):
|
||||
text = Text("Hello World").set_color(BLUE)
|
||||
self.add(text)
|
||||
self.camera.frame.save_state()
|
||||
self.play(self.camera.frame.animate.set(width=text.width * 1.2))
|
||||
self.wait(0.3)
|
||||
self.play(Restore(self.camera.frame))
|
||||
|
||||
|
||||
.. manim:: MovingCameraCenter
|
||||
|
||||
class MovingCameraCenter(MovingCameraScene):
|
||||
def construct(self):
|
||||
s = Square(color=RED, fill_opacity=0.5).move_to(2 * LEFT)
|
||||
t = Triangle(color=GREEN, fill_opacity=0.5).move_to(2 * RIGHT)
|
||||
self.wait(0.3)
|
||||
self.add(s, t)
|
||||
self.play(self.camera.frame.animate.move_to(s))
|
||||
self.wait(0.3)
|
||||
self.play(self.camera.frame.animate.move_to(t))
|
||||
|
||||
|
||||
.. manim:: MovingAndZoomingCamera
|
||||
|
||||
class MovingAndZoomingCamera(MovingCameraScene):
|
||||
def construct(self):
|
||||
s = Square(color=BLUE, fill_opacity=0.5).move_to(2 * LEFT)
|
||||
t = Triangle(color=YELLOW, fill_opacity=0.5).move_to(2 * RIGHT)
|
||||
self.add(s, t)
|
||||
self.play(self.camera.frame.animate.move_to(s).set(width=s.width*2))
|
||||
self.wait(0.3)
|
||||
self.play(self.camera.frame.animate.move_to(t).set(width=t.width*2))
|
||||
|
||||
self.play(self.camera.frame.animate.move_to(ORIGIN).set(width=14))
|
||||
|
||||
.. manim:: MovingCameraOnGraph
|
||||
|
||||
class MovingCameraOnGraph(MovingCameraScene):
|
||||
def construct(self):
|
||||
self.camera.frame.save_state()
|
||||
|
||||
ax = Axes(x_range=[-1, 10], y_range=[-1, 10])
|
||||
graph = ax.plot(lambda x: np.sin(x), color=WHITE, x_range=[0, 3 * PI])
|
||||
|
||||
dot_1 = Dot(ax.i2gp(graph.t_min, graph))
|
||||
dot_2 = Dot(ax.i2gp(graph.t_max, graph))
|
||||
self.add(ax, graph, dot_1, dot_2)
|
||||
|
||||
self.play(self.camera.frame.animate.scale(0.5).move_to(dot_1))
|
||||
self.play(self.camera.frame.animate.move_to(dot_2))
|
||||
self.play(Restore(self.camera.frame))
|
||||
self.wait()
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
__all__ = ["MovingCameraScene"]
|
||||
|
||||
from manim.animation.animation import Animation
|
||||
|
||||
from ..camera.moving_camera import MovingCamera
|
||||
from ..scene.scene import Scene
|
||||
from ..utils.family import extract_mobject_family_members
|
||||
from ..utils.iterables import list_update
|
||||
|
||||
|
||||
class MovingCameraScene(Scene):
|
||||
"""
|
||||
This is a Scene, with special configurations and properties that
|
||||
make it suitable for cases where the camera must be moved around.
|
||||
|
||||
.. SEEALSO::
|
||||
|
||||
:class:`.MovingCamera`
|
||||
"""
|
||||
|
||||
def __init__(self, camera_class=MovingCamera, **kwargs):
|
||||
super().__init__(camera_class=camera_class, **kwargs)
|
||||
|
||||
def get_moving_mobjects(self, *animations: Animation):
|
||||
"""
|
||||
This method returns a list of all of the Mobjects in the Scene that
|
||||
are moving, that are also in the animations passed.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
*animations
|
||||
The Animations whose mobjects will be checked.
|
||||
"""
|
||||
moving_mobjects = super().get_moving_mobjects(*animations)
|
||||
all_moving_mobjects = extract_mobject_family_members(moving_mobjects)
|
||||
movement_indicators = self.renderer.camera.get_mobjects_indicating_movement()
|
||||
for movement_indicator in movement_indicators:
|
||||
if movement_indicator in all_moving_mobjects:
|
||||
# When one of these is moving, the camera should
|
||||
# consider all mobjects to be moving
|
||||
return list_update(self.mobjects, moving_mobjects)
|
||||
return moving_mobjects
|
||||
|
|
@ -1,209 +0,0 @@
|
|||
"""A scene supporting zooming in on a specified section.
|
||||
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
.. manim:: UseZoomedScene
|
||||
|
||||
class UseZoomedScene(ZoomedScene):
|
||||
def construct(self):
|
||||
dot = Dot().set_color(GREEN)
|
||||
self.add(dot)
|
||||
self.wait(1)
|
||||
self.activate_zooming(animate=False)
|
||||
self.wait(1)
|
||||
self.play(dot.animate.shift(LEFT))
|
||||
|
||||
.. manim:: ChangingZoomScale
|
||||
|
||||
class ChangingZoomScale(ZoomedScene):
|
||||
def __init__(self, **kwargs):
|
||||
ZoomedScene.__init__(
|
||||
self,
|
||||
zoom_factor=0.3,
|
||||
zoomed_display_height=1,
|
||||
zoomed_display_width=3,
|
||||
image_frame_stroke_width=20,
|
||||
zoomed_camera_config={
|
||||
"default_frame_stroke_width": 3,
|
||||
},
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def construct(self):
|
||||
dot = Dot().set_color(GREEN)
|
||||
sq = Circle(fill_opacity=1, radius=0.2).next_to(dot, RIGHT)
|
||||
self.add(dot, sq)
|
||||
self.wait(1)
|
||||
self.activate_zooming(animate=False)
|
||||
self.wait(1)
|
||||
self.play(dot.animate.shift(LEFT * 0.3))
|
||||
|
||||
self.play(self.zoomed_camera.frame.animate.scale(4))
|
||||
self.play(self.zoomed_camera.frame.animate.shift(0.5 * DOWN))
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
__all__ = ["ZoomedScene"]
|
||||
|
||||
|
||||
from ..animation.transform import ApplyMethod
|
||||
from ..camera.moving_camera import MovingCamera
|
||||
from ..camera.multi_camera import MultiCamera
|
||||
from ..constants import *
|
||||
from ..mobject.types.image_mobject import ImageMobjectFromCamera
|
||||
from ..scene.moving_camera_scene import MovingCameraScene
|
||||
|
||||
# Note, any scenes from old videos using ZoomedScene will almost certainly
|
||||
# break, as it was restructured.
|
||||
|
||||
|
||||
class ZoomedScene(MovingCameraScene):
|
||||
"""
|
||||
This is a Scene with special configurations made for when
|
||||
a particular part of the scene must be zoomed in on and displayed
|
||||
separately.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
camera_class=MultiCamera,
|
||||
zoomed_display_height=3,
|
||||
zoomed_display_width=3,
|
||||
zoomed_display_center=None,
|
||||
zoomed_display_corner=UP + RIGHT,
|
||||
zoomed_display_corner_buff=DEFAULT_MOBJECT_TO_EDGE_BUFFER,
|
||||
zoomed_camera_config={
|
||||
"default_frame_stroke_width": 2,
|
||||
"background_opacity": 1,
|
||||
},
|
||||
zoomed_camera_image_mobject_config={},
|
||||
zoomed_camera_frame_starting_position=ORIGIN,
|
||||
zoom_factor=0.15,
|
||||
image_frame_stroke_width=3,
|
||||
zoom_activated=False,
|
||||
**kwargs,
|
||||
):
|
||||
self.zoomed_display_height = zoomed_display_height
|
||||
self.zoomed_display_width = zoomed_display_width
|
||||
self.zoomed_display_center = zoomed_display_center
|
||||
self.zoomed_display_corner = zoomed_display_corner
|
||||
self.zoomed_display_corner_buff = zoomed_display_corner_buff
|
||||
self.zoomed_camera_config = zoomed_camera_config
|
||||
self.zoomed_camera_image_mobject_config = zoomed_camera_image_mobject_config
|
||||
self.zoomed_camera_frame_starting_position = (
|
||||
zoomed_camera_frame_starting_position
|
||||
)
|
||||
self.zoom_factor = zoom_factor
|
||||
self.image_frame_stroke_width = image_frame_stroke_width
|
||||
self.zoom_activated = zoom_activated
|
||||
super().__init__(camera_class=camera_class, **kwargs)
|
||||
|
||||
def setup(self):
|
||||
"""
|
||||
This method is used internally by Manim to
|
||||
setup the scene for proper use.
|
||||
"""
|
||||
super().setup()
|
||||
# Initialize camera and display
|
||||
zoomed_camera = MovingCamera(**self.zoomed_camera_config)
|
||||
zoomed_display = ImageMobjectFromCamera(
|
||||
zoomed_camera, **self.zoomed_camera_image_mobject_config
|
||||
)
|
||||
zoomed_display.add_display_frame()
|
||||
for mob in zoomed_camera.frame, zoomed_display:
|
||||
mob.stretch_to_fit_height(self.zoomed_display_height)
|
||||
mob.stretch_to_fit_width(self.zoomed_display_width)
|
||||
zoomed_camera.frame.scale(self.zoom_factor)
|
||||
|
||||
# Position camera and display
|
||||
zoomed_camera.frame.move_to(self.zoomed_camera_frame_starting_position)
|
||||
if self.zoomed_display_center is not None:
|
||||
zoomed_display.move_to(self.zoomed_display_center)
|
||||
else:
|
||||
zoomed_display.to_corner(
|
||||
self.zoomed_display_corner,
|
||||
buff=self.zoomed_display_corner_buff,
|
||||
)
|
||||
|
||||
self.zoomed_camera = zoomed_camera
|
||||
self.zoomed_display = zoomed_display
|
||||
|
||||
def activate_zooming(self, animate: bool = False):
|
||||
"""
|
||||
This method is used to activate the zooming for
|
||||
the zoomed_camera.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
animate
|
||||
Whether or not to animate the activation
|
||||
of the zoomed camera.
|
||||
"""
|
||||
self.zoom_activated = True
|
||||
self.renderer.camera.add_image_mobject_from_camera(self.zoomed_display)
|
||||
if animate:
|
||||
self.play(self.get_zoom_in_animation())
|
||||
self.play(self.get_zoomed_display_pop_out_animation())
|
||||
self.add_foreground_mobjects(
|
||||
self.zoomed_camera.frame,
|
||||
self.zoomed_display,
|
||||
)
|
||||
|
||||
def get_zoom_in_animation(self, run_time: float = 2, **kwargs):
|
||||
"""
|
||||
Returns the animation of camera zooming in.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
run_time
|
||||
The run_time of the animation of the camera zooming in.
|
||||
**kwargs
|
||||
Any valid keyword arguments of ApplyMethod()
|
||||
|
||||
Returns
|
||||
-------
|
||||
ApplyMethod
|
||||
The animation of the camera zooming in.
|
||||
"""
|
||||
frame = self.zoomed_camera.frame
|
||||
full_frame_height = self.camera.frame_height
|
||||
full_frame_width = self.camera.frame_width
|
||||
frame.save_state()
|
||||
frame.stretch_to_fit_width(full_frame_width)
|
||||
frame.stretch_to_fit_height(full_frame_height)
|
||||
frame.center()
|
||||
frame.set_stroke(width=0)
|
||||
return ApplyMethod(frame.restore, run_time=run_time, **kwargs)
|
||||
|
||||
def get_zoomed_display_pop_out_animation(self, **kwargs):
|
||||
"""
|
||||
This is the animation of the popping out of the
|
||||
mini-display that shows the content of the zoomed
|
||||
camera.
|
||||
|
||||
Returns
|
||||
-------
|
||||
ApplyMethod
|
||||
The Animation of the Zoomed Display popping out.
|
||||
"""
|
||||
display = self.zoomed_display
|
||||
display.save_state()
|
||||
display.replace(self.zoomed_camera.frame, stretch=True)
|
||||
return ApplyMethod(display.restore)
|
||||
|
||||
def get_zoom_factor(self):
|
||||
"""
|
||||
Returns the Zoom factor of the Zoomed camera.
|
||||
Defined as the ratio between the height of the
|
||||
zoomed camera and the height of the zoomed mini
|
||||
display.
|
||||
Returns
|
||||
-------
|
||||
float
|
||||
The zoom factor.
|
||||
"""
|
||||
return self.zoomed_camera.frame.height / self.zoomed_display.height
|
||||
Loading…
Add table
Add a link
Reference in a new issue