mirror of
https://github.com/3b1b/manim.git
synced 2025-11-14 17:07:45 +00:00
Merge branch 'master' of github.com:3b1b/manim into kill-continual-animations
This commit is contained in:
commit
829b3d9210
4 changed files with 63 additions and 19 deletions
|
|
@ -404,13 +404,19 @@ class Line(TipableVMobject):
|
|||
def account_for_buff(self):
|
||||
if self.buff == 0:
|
||||
return
|
||||
#
|
||||
if self.path_arc == 0:
|
||||
length = self.get_length()
|
||||
else:
|
||||
length = self.get_arc_length()
|
||||
#
|
||||
if length < 2 * self.buff:
|
||||
return
|
||||
buff_proportion = self.buff / length
|
||||
self.pointwise_become_partial(
|
||||
self, buff_proportion, 1 - buff_proportion
|
||||
)
|
||||
return self
|
||||
|
||||
def set_start_and_end_attrs(self, start, end):
|
||||
# If either start or end are Mobjects, this
|
||||
|
|
@ -437,18 +443,6 @@ class Line(TipableVMobject):
|
|||
start, end = self.get_start_and_end()
|
||||
return get_norm(start - end)
|
||||
|
||||
def get_arc_length(self):
|
||||
if self.path_arc:
|
||||
points = np.array([
|
||||
self.point_from_proportion(a)
|
||||
for a in np.linspace(0, 1, 100)
|
||||
])
|
||||
diffs = points[1:] - points[:-1]
|
||||
norms = np.apply_along_axis(get_norm, 1, diffs)
|
||||
return np.sum(norms)
|
||||
else:
|
||||
return self.get_length()
|
||||
|
||||
def get_vector(self):
|
||||
return self.get_end() - self.get_start()
|
||||
|
||||
|
|
@ -658,28 +652,40 @@ class Polygon(VMobject):
|
|||
cut_off_length = radius * np.tan(angle / 2)
|
||||
# Determines counterclockwise vs. clockwise
|
||||
sign = np.sign(np.cross(vect1, vect2)[2])
|
||||
arcs.append(ArcBetweenPoints(
|
||||
arc = ArcBetweenPoints(
|
||||
v2 - unit_vect1 * cut_off_length,
|
||||
v2 + unit_vect2 * cut_off_length,
|
||||
angle=sign * angle
|
||||
))
|
||||
)
|
||||
arcs.append(arc)
|
||||
|
||||
self.clear_points()
|
||||
# To ensure that we loop through starting with last
|
||||
arcs = [arcs[-1], *arcs[:-1]]
|
||||
for arc1, arc2 in adjacent_pairs(arcs):
|
||||
self.append_points(arc1.points)
|
||||
self.add_line_to(arc2.get_start())
|
||||
line = Line(arc1.get_end(), arc2.get_start())
|
||||
# Make sure anchors are evenly distributed
|
||||
len_ratio = line.get_length() / arc1.get_arc_length()
|
||||
line.insert_n_curves(
|
||||
int(arc1.get_num_curves() * len_ratio)
|
||||
)
|
||||
self.append_points(line.get_points())
|
||||
return self
|
||||
|
||||
|
||||
class RegularPolygon(Polygon):
|
||||
CONFIG = {
|
||||
"start_angle": 0
|
||||
"start_angle": None,
|
||||
}
|
||||
|
||||
def __init__(self, n=6, **kwargs):
|
||||
digest_config(self, kwargs, locals())
|
||||
if self.start_angle is None:
|
||||
if n % 2 == 0:
|
||||
self.start_angle = 0
|
||||
else:
|
||||
self.start_angle = 90 * DEGREES
|
||||
start_vect = rotate_vector(RIGHT, self.start_angle)
|
||||
vertices = compass_directions(n, start_vect)
|
||||
Polygon.__init__(self, *vertices, **kwargs)
|
||||
|
|
|
|||
|
|
@ -6,12 +6,39 @@ from manimlib.constants import RIGHT
|
|||
from manimlib.mobject.mobject import Mobject
|
||||
|
||||
|
||||
def always(method, *args, **kwargs):
|
||||
def assert_is_mobject_method(method):
|
||||
assert(inspect.ismethod(method))
|
||||
mobject = method.__self__
|
||||
assert(isinstance(mobject, Mobject))
|
||||
|
||||
|
||||
def always(method, *args, **kwargs):
|
||||
assert_is_mobject_method(method)
|
||||
mobject = method.__self__
|
||||
func = method.__func__
|
||||
mobject.add_updater(lambda m: func(m, *args, **kwargs))
|
||||
return mobject
|
||||
|
||||
|
||||
def f_always(method, *arg_generators, **kwargs):
|
||||
"""
|
||||
More functional version of always, where insetead
|
||||
of taking in args, it takes in functions which ouput
|
||||
the relevant arguments.
|
||||
"""
|
||||
assert_is_mobject_method(method)
|
||||
mobject = method.__self__
|
||||
func = method.__func__
|
||||
|
||||
def updater(mob):
|
||||
args = [
|
||||
arg_generator()
|
||||
for arg_generator in arg_generators
|
||||
]
|
||||
func(mob, *args, **kwargs)
|
||||
|
||||
mobject.add_updater(updater)
|
||||
return mobject
|
||||
|
||||
|
||||
def always_redraw(func):
|
||||
|
|
|
|||
|
|
@ -137,7 +137,6 @@ class Cube(VGroup):
|
|||
side_length=self.side_length,
|
||||
shade_in_3d=True,
|
||||
)
|
||||
# face.make_jagged()
|
||||
face.flip()
|
||||
face.shift(self.side_length * OUT / 2.0)
|
||||
face.apply_matrix(z_to_vector(vect))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ from manimlib.utils.iterables import stretch_array_to_length
|
|||
from manimlib.utils.iterables import tuplify
|
||||
from manimlib.utils.simple_functions import clip_in_place
|
||||
from manimlib.utils.space_ops import rotate_vector
|
||||
from manimlib.utils.space_ops import get_norm
|
||||
|
||||
# TODO
|
||||
# - Change cubic curve groups to have 4 points instead of 3
|
||||
|
|
@ -668,6 +669,17 @@ class VMobject(Mobject):
|
|||
for sm in self.get_family()
|
||||
])))
|
||||
|
||||
def get_arc_length(self, n_sample_points=None):
|
||||
if n_sample_points is None:
|
||||
n_sample_points = 4 * self.get_num_curves() + 1
|
||||
points = np.array([
|
||||
self.point_from_proportion(a)
|
||||
for a in np.linspace(0, 1, n_sample_points)
|
||||
])
|
||||
diffs = points[1:] - points[:-1]
|
||||
norms = np.apply_along_axis(get_norm, 1, diffs)
|
||||
return np.sum(norms)
|
||||
|
||||
# Alignment
|
||||
def align_points(self, vmobject):
|
||||
self.align_rgbas(vmobject)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue