Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Add example_scenes/opengl.py

Devin Neal5e726c025add
diff --git a/example_scenes/assets/1280px-The_earth_at_night.jpg b/example_scenes/assets/1280px-The_earth_at_night.jpg
new file mode 100644
index 000000000..a253e82b0
Binary files /dev/null and b/example_scenes/assets/1280px-The_earth_at_night.jpg differ
diff --git a/example_scenes/assets/1280px-Whole_world_-_land_and_oceans.jpg b/example_scenes/assets/1280px-Whole_world_-_land_and_oceans.jpg
new file mode 100644
index 000000000..f44ad1677
Binary files /dev/null and b/example_scenes/assets/1280px-Whole_world_-_land_and_oceans.jpg differ
diff --git a/example_scenes/opengl.py b/example_scenes/opengl.py
new file mode 100644
index 000000000..befa47929
--- /dev/null
+++ b/example_scenes/opengl.py
@@ -0,0 +1,86 @@
+from manim import *
+from manim.opengl import *
+import os
+from pathlib import Path
+
+
+class SurfaceExample(Scene):
+ def construct(self):
+ # surface_text = Text("For 3d scenes, try using surfaces")
+ # surface_text.fix_in_frame()
+ # surface_text.to_edge(UP)
+ # self.add(surface_text)
+ # self.wait(0.1)
+
+ torus1 = OpenGLTorus(r1=1, r2=1)
+ torus2 = OpenGLTorus(r1=3, r2=1)
+ sphere = OpenGLSphere(radius=3, resolution=torus1.resolution)
+ # You can texture a surface with up to two images, which will
+ # be interpreted as the side towards the light, and away from
+ # the light. These can be either urls, or paths to a local file
+ # in whatever you've set as the image directory in
+ # the custom_config.yml file
+
+ script_location = Path(os.path.realpath(__file__)).parent
+ day_texture = (
+ script_location / "assets" / "1280px-Whole_world_-_land_and_oceans.jpg"
+ )
+ night_texture = script_location / "assets" / "1280px-The_earth_at_night.jpg"
+
+ surfaces = [
+ OpenGLTexturedSurface(surface, day_texture, night_texture)
+ for surface in [sphere, torus1, torus2]
+ ]
+
+ for mob in surfaces:
+ mob.shift(IN)
+ mob.mesh = OpenGLSurfaceMesh(mob)
+ mob.mesh.set_stroke(BLUE, 1, opacity=0.5)
+
+ # Set perspective
+ frame = self.renderer.camera
+ frame.set_euler_angles(
+ theta=-30 * DEGREES,
+ phi=70 * DEGREES,
+ )
+
+ surface = surfaces[0]
+
+ self.play(
+ FadeIn(surface),
+ ShowCreation(surface.mesh, lag_ratio=0.01, run_time=3),
+ )
+ for mob in surfaces:
+ mob.add(mob.mesh)
+ surface.save_state()
+ self.play(Rotate(surface, PI / 2), run_time=2)
+ for mob in surfaces[1:]:
+ mob.rotate(PI / 2)
+
+ self.play(Transform(surface, surfaces[1]), run_time=3)
+
+ self.play(
+ Transform(surface, surfaces[2]),
+ # Move camera frame during the transition
+ frame.animate.increment_phi(-10 * DEGREES),
+ frame.animate.increment_theta(-20 * DEGREES),
+ run_time=3,
+ )
+ # Add ambient rotation
+ frame.add_updater(lambda m, dt: m.increment_theta(-0.1 * dt))
+
+ # Play around with where the light is
+ # light_text = Text("You can move around the light source")
+ # light_text.move_to(surface_text)
+ # light_text.fix_in_frame()
+
+ # self.play(FadeTransform(surface_text, light_text))
+ light = self.camera.light_source
+ self.add(light)
+ light.save_state()
+ self.play(light.animate.move_to(3 * IN), run_time=5)
+ self.play(light.animate.shift(10 * OUT), run_time=5)
+
+ # drag_text = Text("Try moving the mouse while pressing d or s")
+ # drag_text.move_to(light_text)
+ # drag_text.fix_in_frame()
diff --git a/manim/mobject/opengl_mobject.py b/manim/mobject/opengl_mobject.py
index bc0e4fa59..a3a69047f 100644
--- a/manim/mobject/opengl_mobject.py
+++ b/manim/mobject/opengl_mobject.py
@@ -1147,7 +1147,7 @@ class OpenGLMobject:
return self
def get_group_class(self):
- return Group
+ return OpenGLGroup
# Alignment