manim/docs/source/examples/camera_settings.rst
kolibril13 5233c598ac
Bunch of more examples for the docs (#458)
* #added some examples to the camera scene

* #added 3 ZoomedScene examples

* #removed accidentally added files

* #added updater examples

* #added text examples

* #renamed example

* #added 3d example with other light source

* #added imagemobject examples

* # added one line of code

* # small fix

* # added 3d examples

* # added one advanced project

* fixed error

* small changes

* 3d render

* another idea with the file 3d_fix.rst

* # one more change

* some more formula examples

* fix indent

* remove reference to examples/3d_fix

* change default resolution for videos in doc to 480p30

* Apply suggestions leotrs

Co-authored-by: Leo Torres <leo@leotrs.com>

* Added credits and 3d scene changes

* # removed unnecessary lines

* # implemented lots of changes suggested be leotrs

* # updated credits

* # updated scene names

* Update docs/source/examples/shapes.rst

Co-authored-by: Leo Torres <leo@leotrs.com>

* updated credits

* updated examples entery

* Update camera_settings.rst

* changed two lines

* Update shapes.rst

* Update plots.rst

Co-authored-by: Benjamin Hackl <devel@benjamin-hackl.at>
Co-authored-by: Leo Torres <leo@leotrs.com>
2020-10-02 16:06:01 +02:00

215 lines
7.7 KiB
ReStructuredText

Camera Settings
=================================
.. manim:: Example1
class Example1(MovingCameraScene):
def construct(self):
text = Text("Hello World")
self.add(text)
self.play(self.camera_frame.set_width, text.get_width() * 1.2)
self.wait()
.. manim:: Example2a
class Example2a(MovingCameraScene):
def construct(self):
text = Text("Hello World").set_color(BLUE)
self.add(text)
self.camera_frame.save_state()
self.play(self.camera_frame.set_width, text.get_width() * 1.2)
self.wait(0.3)
self.play(Restore(self.camera_frame))
.. manim:: Example2b
class Example2b(MovingCameraScene):
def construct(self):
text = Text("Hello World").set_color(BLUE)
self.add(text)
self.play(self.camera_frame.set_width, text.get_width() * 1.2)
self.wait(0.3)
self.play(self.camera_frame.set_width, 14)
.. manim:: Example3
class Example3(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.add(s, t)
self.play(self.camera_frame.move_to, s)
self.wait(0.3)
self.play(self.camera_frame.move_to, t)
.. manim:: Example4
class Example4(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.move_to, s,
self.camera_frame.set_width,s.get_width()*2)
self.wait(0.3)
self.play(self.camera_frame.move_to, t,
self.camera_frame.set_width,t.get_width()*2)
self.play(self.camera_frame.move_to, ORIGIN,
self.camera_frame.set_width,14)
.. manim:: Example5
class Example5(GraphScene, MovingCameraScene):
def setup(self):
GraphScene.setup(self)
MovingCameraScene.setup(self)
def construct(self):
self.camera_frame.save_state()
self.setup_axes(animate=False)
graph = self.get_graph(lambda x: np.sin(x),
color=WHITE,
x_min=0,
x_max=3 * PI
)
dot_at_start_graph = Dot().move_to(graph.points[0])
dot_at_end_grap = Dot().move_to(graph.points[-1])
self.add(graph, dot_at_end_grap, dot_at_start_graph)
self.play(self.camera_frame.scale, 0.5, self.camera_frame.move_to, dot_at_start_graph)
self.play(self.camera_frame.move_to, dot_at_end_grap)
self.play(Restore(self.camera_frame))
self.wait()
.. manim:: Example6
class Example6(GraphScene, MovingCameraScene):
def setup(self):
GraphScene.setup(self)
MovingCameraScene.setup(self)
def construct(self):
self.camera_frame.save_state()
self.setup_axes(animate=False)
graph = self.get_graph(lambda x: np.sin(x),
color=BLUE,
x_min=0,
x_max=3 * PI
)
moving_dot = Dot().move_to(graph.points[0]).set_color(ORANGE)
dot_at_start_graph = Dot().move_to(graph.points[0])
dot_at_end_grap = Dot().move_to(graph.points[-1])
self.add(graph, dot_at_end_grap, dot_at_start_graph, moving_dot)
self.play( self.camera_frame.scale,0.5,self.camera_frame.move_to,moving_dot)
def update_curve(mob):
mob.move_to(moving_dot.get_center())
self.camera_frame.add_updater(update_curve)
self.play(MoveAlongPath(moving_dot, graph, rate_func=linear))
self.camera_frame.remove_updater(update_curve)
self.play(Restore(self.camera_frame))
Note: ZoomedScene is derived class of MovingCameraScene,
so one can use all functionality that were used before in the MovingCameraScene examples.
.. manim:: ExampleZoom1
class ExampleZoom1(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.shift, LEFT)
.. manim:: ExampleZoom2
class ExampleZoom2(ZoomedScene):
CONFIG = {
"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,
},
}
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.shift, LEFT * 0.3)
self.play(self.zoomed_camera.frame.scale, 4)
self.play(self.zoomed_camera.frame.shift, 0.5 * DOWN)
.. manim:: ExampleZoom3
class ExampleZoom3(ZoomedScene):
# contributed by TheoremofBeethoven, www.youtube.com/c/TheoremofBeethoven
CONFIG = {
"zoom_factor": 0.3,
"zoomed_display_height": 1,
"zoomed_display_width": 6,
"image_frame_stroke_width": 20,
"zoomed_camera_config": {
"default_frame_stroke_width": 3,
},
}
def construct(self):
dot = Dot().shift(UL * 2)
image = ImageMobject(np.uint8([[0, 100, 30, 200],
[255, 0, 5, 33]]))
image.set_height(7)
frame_text = TextMobject("Frame", color=PURPLE).scale(1.4)
zoomed_camera_text = TextMobject("Zoomed camera", color=RED).scale(1.4)
self.add(image, dot)
zoomed_camera = self.zoomed_camera
zoomed_display = self.zoomed_display
frame = zoomed_camera.frame
zoomed_display_frame = zoomed_display.display_frame
frame.move_to(dot)
frame.set_color(PURPLE)
zoomed_display_frame.set_color(RED)
zoomed_display.shift(DOWN)
zd_rect = BackgroundRectangle(zoomed_display, fill_opacity=0, buff=MED_SMALL_BUFF)
self.add_foreground_mobject(zd_rect)
unfold_camera = UpdateFromFunc(zd_rect, lambda rect: rect.replace(zoomed_display))
frame_text.next_to(frame, DOWN)
self.play(ShowCreation(frame), FadeInFromDown(frame_text))
self.activate_zooming()
self.play(self.get_zoomed_display_pop_out_animation(), unfold_camera)
zoomed_camera_text.next_to(zoomed_display_frame, DOWN)
self.play(FadeInFromDown(zoomed_camera_text))
# Scale in x y z
scale_factor = [0.5, 1.5, 0]
self.play(
frame.scale, scale_factor,
zoomed_display.scale, scale_factor,
FadeOut(zoomed_camera_text),
FadeOut(frame_text)
)
self.wait()
self.play(ScaleInPlace(zoomed_display, 2))
self.wait()
self.play(frame.shift, 2.5 * DOWN)
self.wait()
self.play(self.get_zoomed_display_pop_out_animation(), unfold_camera, rate_func=lambda t: smooth(1 - t))
self.play(Uncreate(zoomed_display_frame), FadeOut(frame))
self.wait()