mirror of
https://github.com/3b1b/manim.git
synced 2025-08-20 05:14:12 +00:00
Merge branch 'lighthouse2' of github.com:3b1b/manim into lighthouse2
This commit is contained in:
commit
148c808b76
4 changed files with 741 additions and 163 deletions
File diff suppressed because it is too large
Load diff
|
@ -96,6 +96,57 @@ class Arc(VMobject):
|
|||
|
||||
return self
|
||||
|
||||
|
||||
|
||||
class ArcBetweenPoints(Arc):
|
||||
|
||||
def __init__(self, start_point, end_point, angle = TAU/4, **kwargs):
|
||||
if angle == 0:
|
||||
raise Exception("Arc with zero curve angle: use Line instead.")
|
||||
|
||||
midpoint = 0.5 * (start_point + end_point)
|
||||
distance_vector = end_point - start_point
|
||||
normal_vector = np.array([-distance_vector[1], distance_vector[0],0])
|
||||
distance = np.linalg.norm(normal_vector)
|
||||
normal_vector /= distance
|
||||
if angle < 0:
|
||||
normal_vector *= -1
|
||||
|
||||
radius = distance/2 / np.sin(0.5 * np.abs(angle))
|
||||
l = distance/2 / np.tan(0.5 * np.abs(angle))
|
||||
arc_center = midpoint + l * normal_vector
|
||||
w = start_point - arc_center
|
||||
if w[0] != 0:
|
||||
start_angle = np.arctan2(w[1],w[0])
|
||||
else:
|
||||
start_angle = np.pi/2
|
||||
|
||||
Arc.__init__(self, angle,
|
||||
radius = radius,
|
||||
start_angle = start_angle,
|
||||
**kwargs)
|
||||
|
||||
self.move_arc_center_to(arc_center)
|
||||
|
||||
class CurvedArrow(ArcBetweenPoints):
|
||||
|
||||
def __init__(self, start_point, end_point, angle = TAU/4, **kwargs):
|
||||
# I know this is in reverse, but it works
|
||||
if angle >= 0:
|
||||
ArcBetweenPoints.__init__(self, start_point, end_point, angle = angle, **kwargs)
|
||||
self.add_tip(at_start = True, at_end = False)
|
||||
else:
|
||||
ArcBetweenPoints.__init__(self, end_point, start_point, angle = -angle, **kwargs)
|
||||
self.add_tip(at_start = False, at_end = True)
|
||||
|
||||
|
||||
class CurvedDoubleArrow(ArcBetweenPoints):
|
||||
|
||||
def __init__(self, start_point, end_point, angle = TAU/4, **kwargs):
|
||||
ArcBetweenPoints.__init__(self, start_point, end_point, angle = angle, **kwargs)
|
||||
self.add_tip(at_start = True, at_end = True)
|
||||
|
||||
|
||||
class Circle(Arc):
|
||||
CONFIG = {
|
||||
"color" : RED,
|
||||
|
|
|
@ -29,10 +29,10 @@ NUM_LEVELS = 30
|
|||
NUM_CONES = 7 # in first lighthouse scene
|
||||
NUM_VISIBLE_CONES = 5 # ibidem
|
||||
ARC_TIP_LENGTH = 0.2
|
||||
AMBIENT_FULL = 0.5
|
||||
AMBIENT_DIMMED = 0.2
|
||||
SPOTLIGHT_FULL = 0.9
|
||||
SPOTLIGHT_DIMMED = 0.2
|
||||
AMBIENT_FULL = 0.8
|
||||
AMBIENT_DIMMED = 0.5
|
||||
SPOTLIGHT_FULL = 0.8
|
||||
SPOTLIGHT_DIMMED = 0.5
|
||||
LIGHTHOUSE_HEIGHT = 0.8
|
||||
|
||||
DEGREES = TAU/360
|
||||
|
@ -57,7 +57,7 @@ class LightSource(VMobject):
|
|||
"source_point": VectorizedPoint(location = ORIGIN, stroke_width = 0, fill_opacity = 0),
|
||||
"color": LIGHT_COLOR,
|
||||
"num_levels": 10,
|
||||
"radius": 5,
|
||||
"radius": 10.0,
|
||||
"screen": None,
|
||||
"opacity_function": inverse_quadratic(1,2,1),
|
||||
"max_opacity_ambient": AMBIENT_FULL,
|
||||
|
@ -143,7 +143,9 @@ class LightSource(VMobject):
|
|||
num_levels = self.num_levels,
|
||||
radius = self.radius,
|
||||
screen = new_screen,
|
||||
camera_mob = self.camera_mob
|
||||
camera_mob = self.camera_mob,
|
||||
opacity_function = self.opacity_function,
|
||||
max_opacity = self.max_opacity_spotlight,
|
||||
)
|
||||
self.spotlight.move_source_to(self.get_source_point())
|
||||
|
||||
|
@ -371,7 +373,7 @@ class AmbientLight(VMobject):
|
|||
"color" : LIGHT_COLOR,
|
||||
"max_opacity" : 1.0,
|
||||
"num_levels" : 10,
|
||||
"radius" : 5.0
|
||||
"radius" : 10.0
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
|
@ -452,7 +454,7 @@ class Spotlight(VMobject):
|
|||
"color" : GREEN, # LIGHT_COLOR,
|
||||
"max_opacity" : 1.0,
|
||||
"num_levels" : 10,
|
||||
"radius" : 5.0,
|
||||
"radius" : 10.0,
|
||||
"screen" : None,
|
||||
"camera_mob": None
|
||||
}
|
||||
|
|
|
@ -120,6 +120,9 @@ class NumberLine(VMobject):
|
|||
result.add(mob)
|
||||
return result
|
||||
|
||||
def get_labels(self):
|
||||
return self.get_number_mobjects()
|
||||
|
||||
def add_numbers(self, *numbers, **kwargs):
|
||||
self.numbers = self.get_number_mobjects(
|
||||
*numbers, **kwargs
|
||||
|
@ -219,29 +222,7 @@ class Axes(VGroup):
|
|||
return graph
|
||||
|
||||
def input_to_graph_point(self, x, graph):
|
||||
if hasattr(graph, "underlying_function"):
|
||||
return self.coords_to_point(x, graph.underlying_function(x))
|
||||
else:
|
||||
#binary search
|
||||
lh, rh = 0, 1
|
||||
while abs(lh - rh) > 0.001:
|
||||
mh = np.mean([lh, rh])
|
||||
hands = [lh, mh, rh]
|
||||
points = map(graph.point_from_proportion, hands)
|
||||
lx, mx, rx = map(self.x_axis.point_to_number, points)
|
||||
if lx <= x and rx >= x:
|
||||
if mx > x:
|
||||
rh = mh
|
||||
else:
|
||||
lh = mh
|
||||
elif lx <= x and rx <= x:
|
||||
return points[2]
|
||||
elif lx >= x and rx >= x:
|
||||
return points[0]
|
||||
elif lx > x and rx < x:
|
||||
lh, rh = rh, lh
|
||||
return points[1]
|
||||
|
||||
return self.coords_to_point(x, graph.underlying_function(x))
|
||||
|
||||
class ThreeDAxes(Axes):
|
||||
CONFIG = {
|
||||
|
|
Loading…
Add table
Reference in a new issue