summaryrefslogtreecommitdiff
path: root/FSF-2020/calculus-of-several-variables/geometry-of-planes-and-curves/general-parametric-curves/file2_cycloid_manim.py
blob: 7b6c0d1b30f6e8559f9e1556d8415e17f0458f98 (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
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))