mirror of
https://github.com/3b1b/manim.git
synced 2025-07-29 21:12:35 +08:00
4284
active_projects/lost_lecture.py
Normal file
4284
active_projects/lost_lecture.py
Normal file
File diff suppressed because it is too large
Load Diff
@ -144,9 +144,15 @@ class FadeIn(Transform):
|
||||
|
||||
|
||||
class FadeInAndShiftFromDirection(Transform):
|
||||
def __init__(self, mobject, direction=DOWN, **kwargs):
|
||||
CONFIG = {
|
||||
"direction": DOWN,
|
||||
}
|
||||
|
||||
def __init__(self, mobject, direction=None, **kwargs):
|
||||
digest_config(self, kwargs)
|
||||
target = mobject.copy()
|
||||
if direction is None:
|
||||
direction = self.direction
|
||||
mobject.shift(direction)
|
||||
mobject.fade(1)
|
||||
Transform.__init__(self, mobject, target, **kwargs)
|
||||
@ -161,6 +167,24 @@ class FadeInFromDown(FadeInAndShiftFromDirection):
|
||||
}
|
||||
|
||||
|
||||
class FadeOutAndShift(FadeOut):
|
||||
CONFIG = {
|
||||
"direction": DOWN,
|
||||
}
|
||||
|
||||
def __init__(self, mobject, direction=None, **kwargs):
|
||||
FadeOut.__init__(self, mobject, **kwargs)
|
||||
if direction is None:
|
||||
direction = self.direction
|
||||
self.target_mobject.shift(direction)
|
||||
|
||||
|
||||
class FadeOutAndShiftDown(FadeOutAndShift):
|
||||
CONFIG = {
|
||||
"direction": DOWN,
|
||||
}
|
||||
|
||||
|
||||
class VFadeIn(Animation):
|
||||
"""
|
||||
VFadeIn and VFadeOut only work for VMobjects, but they can be applied
|
||||
|
@ -158,6 +158,11 @@ class ScaleInPlace(ApplyMethod):
|
||||
scale_factor, **kwargs)
|
||||
|
||||
|
||||
class Restore(ApplyMethod):
|
||||
def __init__(self, mobject, **kwargs):
|
||||
ApplyMethod.__init__(self, mobject.restore, **kwargs)
|
||||
|
||||
|
||||
class ApplyFunction(Transform):
|
||||
CONFIG = {
|
||||
"submobject_mode": "all_at_once",
|
||||
|
@ -106,7 +106,8 @@ BOTTOM = FRAME_Y_RADIUS * DOWN
|
||||
LEFT_SIDE = FRAME_X_RADIUS * LEFT
|
||||
RIGHT_SIDE = FRAME_X_RADIUS * RIGHT
|
||||
|
||||
TAU = 2 * np.pi
|
||||
PI = np.pi
|
||||
TAU = 2 * PI
|
||||
DEGREES = TAU / 360
|
||||
|
||||
ANIMATIONS_DIR = os.path.join(MEDIA_DIR, "animations")
|
||||
|
@ -368,6 +368,14 @@ class Line(VMobject):
|
||||
def get_vector(self):
|
||||
return self.get_end() - self.get_start()
|
||||
|
||||
def get_unit_vector(self):
|
||||
vect = self.get_vector()
|
||||
norm = np.linalg.norm(vect)
|
||||
if norm == 0:
|
||||
# TODO, is this the behavior I want?
|
||||
return np.array(ORIGIN)
|
||||
return vect / norm
|
||||
|
||||
def get_start(self):
|
||||
return np.array(self.points[0])
|
||||
|
||||
|
@ -84,23 +84,8 @@ def squish_rate_func(func, a=0.4, b=0.6):
|
||||
def lingering(t):
|
||||
return squish_rate_func(lambda t: t, 0, 0.8)(t)
|
||||
|
||||
def exponential_decay(t, half_life = 0.1):
|
||||
# The half-life should be rather small to minimize the cut-off error at the end
|
||||
return 1 - np.exp(-t/half_life)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def exponential_decay(t, half_life=0.1):
|
||||
# The half-life should be rather small to minimize
|
||||
# the cut-off error at the end
|
||||
return 1 - np.exp(-t / half_life)
|
||||
|
@ -118,3 +118,24 @@ def complex_func_to_R3_func(complex_func):
|
||||
def center_of_mass(points):
|
||||
points = [np.array(point).astype("float") for point in points]
|
||||
return sum(points) / len(points)
|
||||
|
||||
|
||||
def line_intersection(line1, line2):
|
||||
"""
|
||||
return intersection point of two lines,
|
||||
each defined with a pair of vectors determining
|
||||
the end points
|
||||
"""
|
||||
x_diff = (line1[0][0] - line1[1][0], line2[0][0] - line2[1][0])
|
||||
y_diff = (line1[0][1] - line1[1][1], line2[0][1] - line2[1][1])
|
||||
|
||||
def det(a, b):
|
||||
return a[0] * b[1] - a[1] * b[0]
|
||||
|
||||
div = det(x_diff, y_diff)
|
||||
if div == 0:
|
||||
raise Exception("Lines do not intersect")
|
||||
d = (det(*line1), det(*line2))
|
||||
x = det(d, x_diff) / div
|
||||
y = det(d, y_diff) / div
|
||||
return np.array([x, y, 0])
|
||||
|
Reference in New Issue
Block a user