trying-manim/enter-scene.py

88 lines
2.5 KiB
Python

#!/usr/bin/env python3
from manimlib.imports import *
from math import sin
class EnterScene(Scene):
def construct(self):
square = Square()
circle = Circle()
anno = TextMobject("Fade In")
anno.shift(2 * DOWN)
self.add(anno)
self.play(FadeIn(square))
self.remove(anno)
anno = TextMobject("Fade Out")
anno.shift(2 * DOWN)
self.add(anno)
self.play(FadeOut(square))
self.remove(anno)
back_in = TextMobject("Back In")
back_in.shift(4 * LEFT + 3 * UP)
self.play(Transform(anno, back_in), FadeIn(square))
back_in = anno
lets_play = TextMobject("Let's Play")
lets_play.shift(4 * RIGHT + 3 * UP)
self.play(Transform(back_in, lets_play))
circle.surround(square)
circle2 = Circle()
circle2.surround(square)
self.play(GrowFromEdge(circle, LEFT_SIDE), GrowFromEdge(circle2, RIGHT_SIDE))
self.wait(4)
self.play(ShrinkToCenter(circle), ShrinkToCenter(circle2), ShrinkToCenter(square), ShrinkToCenter(back_in), ShrinkToCenter(lets_play))
self.wait(1)
def function(self, x):
return x**2
class Graphing(GraphScene):
def construct(self):
self.setup_axes(animate=True)
func_graph = self.get_graph(self.function, WHITE, -1, 8, x_leftmost_tick=-20, x_axis_width=40)
graph_lab = self.get_graph_label(func_graph, label = "6sin(\\theta)")
self.play(ShowCreation(func_graph), Write(graph_lab))
self.wait(3)
def function(self, x):
return sin(x) * 6
class GoThreeD(ThreeDScene):
CONFIG = {
"plane_kwargs" : {
"color" : RED_B
},
"point_charge_loc" : 0.5*RIGHT-1.5*UP,
}
def construct(self):
self.set_camera_orientation(0, -np.pi/2)
plane = NumberPlane(**self.plane_kwargs)
plane.add(plane.get_axis_labels())
self.add(plane)
field3D = VGroup(*[self.calc_field3D(x*RIGHT+y*UP+z*UP)
for x in np.arange(-9,9,1)
for y in np.arange(-5,5,1)
for z in np.arange(-5,5,1)
])
self.play(ShowCreation(field3D))
self.wait()
self.move_camera(0.8*np.pi/2, -0.45*np.pi)
self.begin_ambient_camera_rotation()
self.wait(6)
def calc_field2D(self,point):
x,y = point[:2]
Rx,Ry = self.point_charge_loc[:2]
r = math.sqrt((x-Rx)**2 + (y-Ry)**2)
efield = (point - self.point_charge_loc)/r**3
return Vector(efield).shift(point)