Alternating between Slides and ThreeDSlides #211
-
I want to do a presentation in which I have some animations that are 2D and some that are 3D is there a way to alter the types of slides or is it just enough to use ThreeDSlides throughout the whole presentation and how does that affect the slides in which I'll mainly use text? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hello @ArturDomingues! If you can do it only with However, Manim Slides supports concatenating multiple "Slides" (Scenes) with the syntax Note that I am aware of some issues when presenting multipling slides with I hope it helps :-) |
Beta Was this translation helpful? Give feedback.
-
It is a little big, what I'm trying to create are some slides to use for an explanation of Quantum State Tomography, I think I cleared all the possible related Quantum terms, but if something is miss labeled, that is the reason, I'm still testing the animations, so some definitions might be wrong, but the main idea is here from manim import *
from manim_slides import ThreeDSlide
class TestAlternating_2D_3D(ThreeDSlide):
def tinywait(self):
"""
Adds a small delay in the animation.
"""
self.wait(0.1)
def add_slide_number(self, slide_number_text: str, scale: float = 0.3, position: list = [6, -3.75, 0]):
"""
Adds a slide number to the slide.
Args:
slide_number_text (str): The text to display as the slide number.
scale (float, optional): The scale of the slide number. Defaults to 0.3.
position (list, optional): The position of the slide number. Defaults to [6, -3.75, 0].
"""
if slide_number_text is not None:
slide_number = MarkupText(slide_number_text)
slide_number.scale(scale)
slide_number.move_to(position)
self.add(slide_number)
def add_title(self, text: str, slide_number_text: str=None, font_size: float = 58, scale_numb: float = 0.3):
"""
Adds a title to the slide.
Args:
text (str): The text to display as the title.
font_size (float, optional): The font size of the title. Defaults to 48.
Returns:
manim.mobject.title.Title: The added title object.
"""
title = Title(text, font_size=font_size)
self.add(title)
self.add_slide_number(slide_number_text, scale=scale_numb)
self.tinywait()
return title
def create_plane(self, point, side_vec, up_vec, color):
"""
Creates a plane surface object based on the given parameters.
Parameters:
point (np.array): The base point of the plane.
side_vec (np.array): The vector indicating the direction and length of the plane along the x-axis.
up_vec (np.array): The vector indicating the direction and length of the plane along the y-axis.
color (str): The color of the plane.
Returns:
Surface: The plane surface object.
Example:
point = np.array([0, 0, 0])
side_vec = np.array([1, 0, 0])
up_vec = np.array([0, 1, 0])
color = BLUE
plane = create_plane(point, side_vec, up_vec, color=color)
"""
plane_func = lambda u, v: point + u * side_vec + v * up_vec
plane = Surface(plane_func, u_range=(-4, 4), v_range=(-4, 4), fill_opacity=0.2, color=color)
return plane
def construct(self):
# This adds a title to the X,Y Plane
# (It's not difficult to make this go over the Z axis, I just didn't want to waste time doing it)
title = self.add_title("Sphere + Line and Rotating Line Test")
scale = 2 # Some scale to make things bigger
# Add the Axes with labels
axes = ThreeDAxes(x_range=(-6,6,2), y_range=(-6,6,2), z_range=(-6,6,2), color=WHITE)
labels = axes.get_axis_labels(
Tex("X").scale(0.6), Text("Y").scale(0.6), Text("Z").scale(0.6)
)
labeled_axes=VGroup(axes, labels) # Make it a group to move it together
labeled_axes.next_to(title, DOWN) # Make it go just underneath the title
# Create Sphere centered in the labeled axes
sphere = Sphere(center=labeled_axes.get_center(), fill_opacity=0.2, color=TEAL).scale(scale)
# Create a point shifted the same amount the axes where shifted (I hope)
point=np.array([1, 1, 1])/np.sqrt(3) + DOWN
# Create it's antipode for the creation of a 2 color rod I'll use for rotations
antipode=np.array([-1, -1, -1])/np.sqrt(3) + DOWN
# Create the rod used for the animations
rod = Line3D(start=labeled_axes.get_center(), end=point, thickness=0.04, color=BLUE).scale(scale)
antipodal_rod = Line3D(start=labeled_axes.get_center(), end=antipode, thickness=0.04, color=RED).scale(scale)
full_rod=VGroup(rod, antipodal_rod)
# THIS IS ONE OF THE IMPORTANT PARTS (FOR THIS EXAMPLE)
self.move_camera(phi=PI/3, theta=-PI/4, distance=7) # Set the camera where you want to see the 3D Slide
# Create planes perpendicular to each axis and passing through the point (the label indicates which axes
# the created plane is perpendicular to and not which plane is parallel to - if I defined the parametrization
# correctly up there)
plane_x = self.create_plane(point, UP, OUT, color=GREEN)
plane_y = self.create_plane(point, OUT, RIGHT, color=GREEN)
plane_z = self.create_plane(point, RIGHT, UP, color=GREEN)
# Creates the line in the intersection of 2 planes and point in the intersection of 3 planes.
# The use of RIGHT, LEFT; UP, DOWN or OUT, IN depends on what are the 2 planes you choose to show first
intersection_line = Line3D(start=point+2*RIGHT,end=point+2*LEFT,thickness=0.03, color=ORANGE)
intersection_dot = Dot3D(point=point, radius=0.05, color=YELLOW)
# Shows the Axes and the Sphere
self.play(Create(labeled_axes))
self.play(Create(sphere))
self.next_slide() # Wait for command before including more objects in the Slide
# Show the things in the order you prefer
self.play(Create(full_rod))
self.next_slide()
self.play(Create(plane_z))
self.next_slide()
self.play(Create(plane_y))
self.next_slide()
self.play(Create(intersection_line))
self.play(FadeOut(plane_z),FadeOut(plane_y)) # Remove some objects that will not be used anymore
self.next_slide()
self.play(Create(plane_x))
self.next_slide()
self.play(Create(intersection_dot))
self.play(FadeOut(plane_x),FadeOut(intersection_line))
self.next_slide()
self.play(FadeOut(intersection_dot))
self.next_slide()
# Rotate the Rod around the Sphere
self.play(Rotate(full_rod, angle=TAU/4, axis=OUT, run_time=2))
self.next_slide()
self.play(Rotate(full_rod, angle=TAU/8, axis=RIGHT, run_time=2))
self.next_slide()
self.play(Rotate(full_rod, angle=TAU/6, axis=OUT, run_time=2))
self.next_slide()
# THIS IS THE OTHER IMPORTANT PART (FOR THIS EXAMPLE)
self.move_camera(phi=0,theta=-PI/2) # Reset the camera to the X,Y Plane
self.clear() # Cleans the slide before advancing to the next one
# Intro Slide (text)
title = self.add_title("Intro Slide")
text = "Intro Text"
justified_text = MarkupText(text, justify=True).scale(0.8)
self.play(FadeIn(justified_text))
self.next_slide()
self.clear()
# Slide 1: First Slide Of Content (text)
title = self.add_title("Title of the Content",slide_number_text="1|N") |
Beta Was this translation helpful? Give feedback.
Hello @ArturDomingues! If you can do it only with
ThreeDSlides
, then that's the easy way.However, Manim Slides supports concatenating multiple "Slides" (Scenes) with the syntax
manim-slides [present|convert] Slide1 Slide2...
.This may be recommended if you don't want to re-build all the animations whenever you make a change, so you split your whole presentation into multiple slide classes.
Note that I am aware of some issues when presenting multipling slides with
present
command (see #205).I hope it helps :-)