summaryrefslogtreecommitdiff
path: root/FSF-2020/calculus-of-several-variables/div-curl-grad-and-all-that/Curl and Div/DivCurl_file9_formal-def.py
blob: ecafca4e37275f9c8f4ddf3b895bd61fb67dbd54 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from manimlib.imports import *
import numpy as np



def func(coordinate):
	x,y = coordinate[:2]
	return np.array([
			1.9*np.cos(x+2*y),
			1.5*np.sin(x-2*y),
			0
	])

def coord(x,y,z=0):
	return np.array([x,y,z])

class Instrument(Scene):
	CONFIG = {
		"x_coords": ([1, 2.2, 3.9, 3, -0, -0.2, 1]),
		"y_coords": ([1.5, 1, -0.5, -2.0, -1.4, 0.5, 1.5]),
	}

	def setup(self):
		self.tuples = list(zip(self.x_coords,self.y_coords))
		dots = self.get_all_mobs()

	def get_dots(self, coords):
		dots = VGroup(*[Dot(coord(x,y)) for x,y in coords])
		return dots
	
	def get_all_mobs(self):
		dots = self.get_dots(self.tuples)
		return dots


class Curl_one(MovingCameraScene, Instrument):
	def setup(self):
		MovingCameraScene.setup(self)
		Instrument.setup(self)


	def construct(self):
		vec = VectorField(func)


		frame_one = Circle(radius = 0.5).move_to(np.array([4, 2, 0]))
		dot = Dot(frame_one.get_center()).scale(0.5)
		surface = VMobject()
		surface.set_points_smoothly([*[coord(x,y) for x,y in self.tuples]])
		surface.move_to(dot.get_center()).set_stroke(width = 0.5)
		
		label = TexMobject(r"A").scale(0.5).next_to(dot, LEFT+UP, buff = SMALL_BUFF)
		#self.add(frame_one)
		self.camera_frame.save_state()
		self.play(
			self.camera_frame.set_width,frame_one.get_width()*7.0,
			self.camera_frame.move_to,frame_one)


	

		self.add(vec, dot, label)
		lines = StreamLines(
			func,
			virtual_time=7,
			min_magnitude=0,
			max_magnitude=8,
		)
		lines1 = AnimatedStreamLines(
			lines,
			line_anim_class=ShowPassingFlashWithThinningStrokeWidth
		)

		self.add(lines1)
		self.wait(3)
		self.play(Restore(self.camera_frame))
		self.wait(2)
		self.add(surface)
		self.wait(3)
		self.play(ApplyMethod(surface.scale, 0.01), run_time = 2)
		self.remove(surface)
		self.wait(2)