summaryrefslogtreecommitdiff
path: root/FSF-2020/calculus-of-several-variables/div-curl-grad-and-all-that/Conservative fields/Conservative_file6_potential-func.py
blob: e52a03a49e892be03b36fcacdd415168e80b2f97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from manimlib.imports import *

def field_func(coordinate):
	x,y = coordinate[:2]
	return np.array([
					np.cos(x), 
					np.cos(y),
					0
				])

class Potential(ThreeDScene):
	def construct(self):
		axes = ThreeDAxes()
		self.add(axes)
		self.set_camera_orientation(phi=0*DEGREES,theta=0*DEGREES,distance=40)
		vec_field = VectorField(field_func, x_min =-3, x_max = 3, y_min =-3, y_max =3)
		surf = ParametricSurface(lambda u,v: np.array([u,v,
														np.sin(u) + np.sin(v)]),
														u_min = -3, u_max = 3, v_min = -3, v_max = 3, stroke_color = PURPLE_E, checkerboard_colors = [PURPLE_E, PURPLE_E]).fade(0.5)

		#text 
		vec = TexMobject(r"\vec F = \cos x \hat i + \cos y \hat j ").set_color(YELLOW_C).shift(3.8*UP+3.6*RIGHT).scale(0.7)
		func = TexMobject(r"\textit{has a potential function }", r"f(x,y) = \sin x + \sin y").scale(0.7).next_to(vec, DOWN, buff = 0.2)
		func[1].set_color(PURPLE_E)	

		self.play(ShowCreation(vec_field))
		self.add_fixed_in_frame_mobjects(vec)
		self.wait()
		self.play(FadeIn(surf))
		self.begin_ambient_camera_rotation()
		self.move_camera(phi=45*DEGREES,theta=60*DEGREES)
		self.add_fixed_in_frame_mobjects(func)
		self.wait(2)