summaryrefslogtreecommitdiff
path: root/FSF-2020/calculus-of-several-variables/geometry-of-planes-and-curves/general-parametric-curves/file2_cycloid_manim.py
diff options
context:
space:
mode:
Diffstat (limited to 'FSF-2020/calculus-of-several-variables/geometry-of-planes-and-curves/general-parametric-curves/file2_cycloid_manim.py')
-rw-r--r--FSF-2020/calculus-of-several-variables/geometry-of-planes-and-curves/general-parametric-curves/file2_cycloid_manim.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/FSF-2020/calculus-of-several-variables/geometry-of-planes-and-curves/general-parametric-curves/file2_cycloid_manim.py b/FSF-2020/calculus-of-several-variables/geometry-of-planes-and-curves/general-parametric-curves/file2_cycloid_manim.py
new file mode 100644
index 0000000..7b6c0d1
--- /dev/null
+++ b/FSF-2020/calculus-of-several-variables/geometry-of-planes-and-curves/general-parametric-curves/file2_cycloid_manim.py
@@ -0,0 +1,46 @@
+from manimlib.imports import *
+
+t_offset = 0
+c_t = 0
+
+class cycloid(Scene):
+ def construct(self):
+
+ cycl = ParametricFunction(
+ lambda t: np.array([
+ t - np.sin(t),
+ 1 - np.cos(t),
+ 0
+ ]), t_min = -2.75*np.pi, t_max = 3*np.pi, color = BLUE
+ ).shift(0.73*RIGHT)
+ wheel_radius = 1
+ wheel_function_path = lambda x : 0 + wheel_radius
+
+ line = FunctionGraph(lambda x : 0, color = BLACK)
+ wheel_path = FunctionGraph(wheel_function_path)
+
+ velocity_factor = 0.25
+ frame_rate = self.camera.frame_rate
+ self.dt = 1 / frame_rate
+
+ wheel = Circle(color = BLACK, radius = 1)
+ dot = Dot(radius = 0.16, color = RED)
+ #dot.move_to(wheel.get_arc_center() + np.array([0,2,0]))
+
+ def update_dot(mob,dt):
+ global t_offset,c_t
+ if dt == 0 and c_t == 0:
+ rate= - velocity_factor * self.dt
+ c_t += 1
+ else:
+ rate = - dt*velocity_factor
+ if dt > 0:
+ c_t = 0
+ mob.move_to(wheel.point_from_proportion(((t_offset + rate))%1))
+ t_offset += rate
+ #self.add(mob.copy())
+
+ #dot.move_to(wheel.get_arc_center() + np.array([0,2,0]))
+ dot.add_updater(update_dot)
+ self.add(wheel,dot, line, cycl)
+ self.play(MoveAlongPath(wheel, wheel_path, run_time = 9, rate_func = linear))