mirror of
https://github.com/3b1b/manim.git
synced 2025-11-01 15:08:59 +00:00
Rename generate_points to init_points
This commit is contained in:
parent
c7a99769ce
commit
9835813679
34 changed files with 129 additions and 84 deletions
|
|
@ -1605,7 +1605,7 @@ class HasItsLimitations(Scene):
|
|||
|
||||
curved_arrow = Arc(0, color = MAROON_E)
|
||||
curved_arrow.set_bound_angles(np.pi, 0)
|
||||
curved_arrow.generate_points()
|
||||
curved_arrow.init_points()
|
||||
curved_arrow.add_tip()
|
||||
curved_arrow.move_arc_center_to(base_point + RIGHT)
|
||||
# Could do something smoother, with arrowhead moving along partial arc?
|
||||
|
|
@ -1629,7 +1629,7 @@ class HasItsLimitations(Scene):
|
|||
|
||||
new_curved_arrow = Arc(0).match_style(curved_arrow)
|
||||
new_curved_arrow.set_bound_angles(np.pi * 3/4, 0)
|
||||
new_curved_arrow.generate_points()
|
||||
new_curved_arrow.init_points()
|
||||
new_curved_arrow.add_tip()
|
||||
|
||||
input_diff = input_dot.get_center() - curved_arrow.points[0]
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ class AngleUpdater(ContinualAnimation):
|
|||
start = self.spotlight.start_angle(),
|
||||
stop = self.spotlight.stop_angle()
|
||||
)
|
||||
new_arc.generate_points()
|
||||
new_arc.init_points()
|
||||
new_arc.move_arc_center_to(self.spotlight.get_source_point())
|
||||
self.angle_arc.points = new_arc.points
|
||||
self.angle_arc.add_tip(tip_length = ARC_TIP_LENGTH,
|
||||
|
|
@ -120,7 +120,7 @@ class LightIndicator(VMobject):
|
|||
"light_source": None
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.background = Circle(color=BLACK, radius = self.radius)
|
||||
self.background.set_fill(opacity=1.0)
|
||||
self.foreground = Circle(color=self.color, radius = self.radius)
|
||||
|
|
@ -997,7 +997,7 @@ class MorphIntoSunScene(PiCreatureScene):
|
|||
#self.sun.move_source_to(sun_position)
|
||||
#self.sun.set_radius(120)
|
||||
|
||||
self.sun.spotlight.generate_points()
|
||||
self.sun.spotlight.init_points()
|
||||
|
||||
self.wait()
|
||||
|
||||
|
|
@ -1295,7 +1295,7 @@ class ScreenShapingScene(ThreeDScene):
|
|||
|
||||
self.slanted_brightness_rect = self.brightness_rect.copy()
|
||||
self.slanted_brightness_rect.width *= 2
|
||||
self.slanted_brightness_rect.generate_points()
|
||||
self.slanted_brightness_rect.init_points()
|
||||
self.slanted_brightness_rect.set_fill(opacity = 0.25)
|
||||
|
||||
self.slanted_screen = Line(lower_slanted_screen_point,upper_slanted_screen_point,
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class AngleUpdater(ContinualAnimation):
|
|||
start = self.spotlight.start_angle(),
|
||||
stop = self.spotlight.stop_angle()
|
||||
)
|
||||
new_arc.generate_points()
|
||||
new_arc.init_points()
|
||||
new_arc.move_arc_center_to(self.spotlight.get_source_point())
|
||||
self.angle_arc.points = new_arc.points
|
||||
self.angle_arc.add_tip(
|
||||
|
|
@ -92,7 +92,7 @@ class LightIndicator(Mobject):
|
|||
"light_source": None
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.background = Circle(color=BLACK, radius = self.radius)
|
||||
self.background.set_fill(opacity = 1.0)
|
||||
self.foreground = Circle(color=self.color, radius = self.radius)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class Jewel(VMobject):
|
|||
"num_equator_points" : 5,
|
||||
"sun_vect" : OUT+LEFT+UP,
|
||||
}
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
for vect in OUT, IN:
|
||||
compass_vects = list(compass_directions(self.num_equator_points))
|
||||
if vect is IN:
|
||||
|
|
@ -46,7 +46,7 @@ class Necklace(VMobject):
|
|||
random.shuffle(result)
|
||||
return result
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
jewels = VGroup(*[
|
||||
Jewel(color = color)
|
||||
for color in self.colors
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ class LeviSolution(CycloidScene):
|
|||
def construct(self):
|
||||
CycloidScene.construct(self)
|
||||
self.add(self.ceiling)
|
||||
self.generate_points()
|
||||
self.init_points()
|
||||
methods = [
|
||||
self.draw_cycloid,
|
||||
self.roll_into_position,
|
||||
|
|
@ -176,7 +176,7 @@ class LeviSolution(CycloidScene):
|
|||
self.wait()
|
||||
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
index = int(self.cycloid_fraction*self.cycloid.get_num_points())
|
||||
p_point = self.cycloid.points[index]
|
||||
p_dot = Dot(p_point)
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ class Lens(Arc):
|
|||
digest_config(self, kwargs)
|
||||
Arc.__init__(self, self.angle, **kwargs)
|
||||
|
||||
def generate_points(self):
|
||||
Arc.generate_points(self)
|
||||
def init_points(self):
|
||||
Arc.init_points(self)
|
||||
self.rotate(-np.pi/4)
|
||||
self.shift(-self.get_left())
|
||||
self.add_points(self.copy().rotate(np.pi).points)
|
||||
|
|
@ -566,7 +566,7 @@ class Spring(Line):
|
|||
"color" : GREY
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
## self.start, self.end
|
||||
length = get_norm(self.end-self.start)
|
||||
angle = angle_of_vector(self.end-self.start)
|
||||
|
|
|
|||
|
|
@ -377,6 +377,7 @@ class BlocksAndWallScene(Scene):
|
|||
return self
|
||||
|
||||
def tear_down(self):
|
||||
super().tear_down()
|
||||
if self.include_sound:
|
||||
self.add_clack_sounds(self.clack_data)
|
||||
|
||||
|
|
|
|||
|
|
@ -560,7 +560,7 @@ class Ladder(VMobject):
|
|||
"width" : 1,
|
||||
"n_rungs" : 7,
|
||||
}
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
left_line, right_line = [
|
||||
Line(ORIGIN, self.height*UP).shift(self.width*vect/2.0)
|
||||
for vect in (LEFT, RIGHT)
|
||||
|
|
|
|||
|
|
@ -254,7 +254,7 @@ class HyperCube(VMobject):
|
|||
"color2" : BLUE_D,
|
||||
"dims" : 4,
|
||||
}
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
corners = np.array(list(map(np.array, it.product(*[(-1, 1)]*self.dims))))
|
||||
def project(four_d_array):
|
||||
result = four_d_array[:3]
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ class StockLine(VMobject):
|
|||
"num_points" : 15,
|
||||
"step_range" : 2
|
||||
}
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
points = [ORIGIN]
|
||||
for x in range(self.num_points):
|
||||
step_size = self.step_range*(random.random() - 0.5)
|
||||
|
|
|
|||
|
|
@ -664,7 +664,7 @@ class Quadrant(VMobject):
|
|||
"density" : 50,
|
||||
"density_exp" : 2.0,
|
||||
}
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
points = [r*RIGHT for r in np.arange(0, self.radius, 1./self.density)]
|
||||
points += [
|
||||
self.radius*(np.cos(theta)*RIGHT + np.sin(theta)*UP)
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ def zero_to_one_interval():
|
|||
return interval
|
||||
|
||||
class LeftParen(Mobject):
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.add(TexMobject("("))
|
||||
self.center()
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ class LeftParen(Mobject):
|
|||
return Mobject.get_center(self) + 0.04*LEFT
|
||||
|
||||
class RightParen(Mobject):
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.add(TexMobject(")"))
|
||||
self.center()
|
||||
|
||||
|
|
@ -478,7 +478,7 @@ class PlaySimpleRatio(Scene):
|
|||
self.play(string1, string2)
|
||||
|
||||
class LongSine(Mobject1D):
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.add_points([
|
||||
(x, np.sin(2*np.pi*x), 0)
|
||||
for x in np.arange(0, 100, self.epsilon/10)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class ArcLengthChange(Animation):
|
|||
def interpolate_mobject(self,alpha):
|
||||
angle = interpolate(self.old_angle, self.new_angle, alpha)
|
||||
self.mobject.angle = angle
|
||||
self.mobject.generate_points()
|
||||
self.mobject.init_points()
|
||||
|
||||
|
||||
class LabelTracksLine(Animation):
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class Stars(Mobject1D):
|
|||
"radius" : FRAME_X_RADIUS,
|
||||
"num_points" : 1000,
|
||||
}
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
radii, phis, thetas = [
|
||||
scalar*np.random.random(self.num_points)
|
||||
for scalar in [self.radius, np.pi, 2*np.pi]
|
||||
|
|
@ -26,7 +26,7 @@ class Stars(Mobject1D):
|
|||
])
|
||||
|
||||
class CubeWithFaces(Mobject2D):
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.add_points([
|
||||
sgn * np.array(coords)
|
||||
for x in np.arange(-1, 1, self.epsilon)
|
||||
|
|
@ -41,7 +41,7 @@ class CubeWithFaces(Mobject2D):
|
|||
return np.array([1 if abs(x) == 1 else 0 for x in coords])
|
||||
|
||||
class Cube(Mobject1D):
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.add_points([
|
||||
([a, b, c][p[0]], [a, b, c][p[1]], [a, b, c][p[2]])
|
||||
for p in [(0, 1, 2), (2, 0, 1), (1, 2, 0)]
|
||||
|
|
@ -51,7 +51,7 @@ class Cube(Mobject1D):
|
|||
self.set_color(YELLOW)
|
||||
|
||||
class Octohedron(Mobject1D):
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
x = np.array([1, 0, 0])
|
||||
y = np.array([0, 1, 0])
|
||||
z = np.array([0, 0, 1])
|
||||
|
|
@ -68,7 +68,7 @@ class Octohedron(Mobject1D):
|
|||
self.set_color(MAROON_D)
|
||||
|
||||
class Dodecahedron(Mobject1D):
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
phi = (1 + np.sqrt(5)) / 2
|
||||
x = np.array([1, 0, 0])
|
||||
y = np.array([0, 1, 0])
|
||||
|
|
@ -95,7 +95,7 @@ class Dodecahedron(Mobject1D):
|
|||
self.set_color(GREEN)
|
||||
|
||||
class Sphere(Mobject2D):
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.add_points([
|
||||
(
|
||||
np.sin(phi) * np.cos(theta),
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ class TOP(VMobject):
|
|||
digest_config(self, kwargs, locals())
|
||||
VMobject.__init__(self, **kwargs)
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
vertices = [
|
||||
self.radius*rotate_vector(RIGHT, 7*np.pi/6 - i*2*np.pi/3)
|
||||
for i in range(3)
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ class BrickRowScene(PiCreatureScene):
|
|||
|
||||
half_merged_row = row.copy()
|
||||
half_merged_row.subdiv_level += 1
|
||||
half_merged_row.generate_points()
|
||||
half_merged_row.init_points()
|
||||
half_merged_row.move_to(row)
|
||||
|
||||
self.play(FadeIn(half_merged_row))
|
||||
|
|
@ -191,7 +191,7 @@ class BrickRowScene(PiCreatureScene):
|
|||
|
||||
merged_row = row.copy()
|
||||
merged_row.coloring_level += 1
|
||||
merged_row.generate_points()
|
||||
merged_row.init_points()
|
||||
merged_row.move_to(row)
|
||||
|
||||
self.play(FadeIn(merged_row))
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class BuildNewPascalRow(Transform):
|
|||
|
||||
new_pt = mobject.copy()
|
||||
new_pt.nrows += 1
|
||||
new_pt.generate_points()
|
||||
new_pt.init_points()
|
||||
# align with original (copy got centered on screen)
|
||||
c1 = new_pt.coords_to_mobs[0][0].get_center()
|
||||
c2 = mobject.coords_to_mobs[0][0].get_center()
|
||||
|
|
@ -117,7 +117,7 @@ class SimplePascal(Scene):
|
|||
new_pt.height = new_pt.nrows * cell_height
|
||||
new_pt.width = new_pt.nrows * cell_width
|
||||
|
||||
new_pt.generate_points()
|
||||
new_pt.init_points()
|
||||
# align with original (copy got centered on screen)
|
||||
c1 = new_pt.coords_to_mobs[0][0].get_center()
|
||||
c2 = old_pt.coords_to_mobs[0][0].get_center()
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class BrickRow(VMobject):
|
|||
VMobject.__init__(self, **kwargs)
|
||||
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
|
||||
self.submobjects = []
|
||||
self.rects = self.get_rects_for_level(self.coloring_level)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class PiCreatureCoin(VMobject):
|
|||
"fill_opacity": 0.7,
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
outer_rect = Rectangle(
|
||||
width = self.diameter,
|
||||
height = self.thickness,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class CoinStack(VGroup):
|
|||
"face": FlatCoin,
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
for n in range(self.size):
|
||||
coin = self.face(thickness = self.coin_thickness)
|
||||
coin.shift(n * self.coin_thickness * UP)
|
||||
|
|
@ -55,7 +55,7 @@ class TallyStack(VGroup):
|
|||
self.anchor = anchor
|
||||
VGroup.__init__(self,**kwargs)
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
stack1 = HeadsStack(size = self.nb_heads, coin_thickness = self.coin_thickness)
|
||||
stack2 = TailsStack(size = self.nb_tails, coin_thickness = self.coin_thickness)
|
||||
stack1.next_to(self.anchor, LEFT, buff = 0.5 * SMALL_BUFF)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class RowOfDice(VGroup):
|
|||
"direction": RIGHT,
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
for value in self.values:
|
||||
new_die = DieFace(value)
|
||||
new_die.submobjects[0].set_fill(opacity = 0)
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class Histogram(VMobject):
|
|||
|
||||
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
|
||||
self.process_values()
|
||||
for submob in self.submobjects:
|
||||
|
|
@ -130,7 +130,7 @@ class Histogram(VMobject):
|
|||
)
|
||||
if bar.height == 0:
|
||||
bar.height = 0.01
|
||||
bar.generate_points()
|
||||
bar.init_points()
|
||||
|
||||
t = float(x - self.x_min)/(self.x_max - self.x_min)
|
||||
bar_color = interpolate_color(
|
||||
|
|
@ -273,7 +273,7 @@ class FlashThroughHistogram(Animation):
|
|||
cell = self.cell_for_index(i,j)
|
||||
self.prototype_cell.width = cell.get_width()
|
||||
self.prototype_cell.height = cell.get_height()
|
||||
self.prototype_cell.generate_points()
|
||||
self.prototype_cell.init_points()
|
||||
self.prototype_cell.move_to(cell.get_center())
|
||||
|
||||
if t == 1:
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ from manimlib.mobject.geometry import Rectangle
|
|||
from manimlib.utils.config_ops import digest_config
|
||||
|
||||
|
||||
# TODO, put CameraFrame in here?
|
||||
|
||||
|
||||
class ScreenRectangle(Rectangle):
|
||||
CONFIG = {
|
||||
"aspect_ratio": 16.0 / 9.0,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class ParametricFunction(VMobject):
|
|||
"t_max": 1,
|
||||
"step_size": 0.01, # Use "auto" (lowercase) for automatic step size
|
||||
"dt": 1e-8,
|
||||
# TODO, be smarter about figuring these out?
|
||||
# TODO, automatically figure out discontinuities
|
||||
"discontinuities": [],
|
||||
}
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ class ParametricFunction(VMobject):
|
|||
else:
|
||||
return self.step_size
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
t_min, t_max = self.t_min, self.t_max
|
||||
dt = self.dt
|
||||
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ class Arc(TipableVMobject):
|
|||
self.angle = angle
|
||||
VMobject.__init__(self, **kwargs)
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.set_pre_positioned_points()
|
||||
self.scale(self.radius, about_point=ORIGIN)
|
||||
self.shift(self.arc_center)
|
||||
|
|
@ -348,7 +348,7 @@ class AnnularSector(Arc):
|
|||
"color": WHITE,
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
inner_arc, outer_arc = [
|
||||
Arc(
|
||||
start_angle=self.start_angle,
|
||||
|
|
@ -382,7 +382,7 @@ class Annulus(Circle):
|
|||
"mark_paths_closed": False,
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.radius = self.outer_radius
|
||||
outer_circle = Circle(radius=self.outer_radius)
|
||||
inner_circle = Circle(radius=self.inner_radius)
|
||||
|
|
@ -404,7 +404,7 @@ class Line(TipableVMobject):
|
|||
self.set_start_and_end_attrs(start, end)
|
||||
VMobject.__init__(self, **kwargs)
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
if self.path_arc:
|
||||
arc = ArcBetweenPoints(
|
||||
self.start, self.end,
|
||||
|
|
@ -417,7 +417,7 @@ class Line(TipableVMobject):
|
|||
|
||||
def set_path_arc(self, new_value):
|
||||
self.path_arc = new_value
|
||||
self.generate_points()
|
||||
self.init_points()
|
||||
|
||||
def account_for_buff(self):
|
||||
if self.buff == 0:
|
||||
|
|
@ -464,7 +464,7 @@ class Line(TipableVMobject):
|
|||
# these attrs?
|
||||
self.start = start
|
||||
self.end = end
|
||||
self.generate_points()
|
||||
self.init_points()
|
||||
return super().put_start_and_end_on(start, end)
|
||||
|
||||
def get_vector(self):
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ from manimlib.utils.space_ops import rotation_matrix
|
|||
|
||||
|
||||
# TODO: Explain array_attrs
|
||||
# TODO: Incorporate shader defaults
|
||||
|
||||
class Mobject(Container):
|
||||
"""
|
||||
|
|
@ -45,7 +46,7 @@ class Mobject(Container):
|
|||
self.updaters = []
|
||||
self.updating_suspended = False
|
||||
self.reset_points()
|
||||
self.generate_points()
|
||||
self.init_points() # TODO, rename this to "init_points?"
|
||||
self.init_colors()
|
||||
|
||||
def __str__(self):
|
||||
|
|
@ -58,7 +59,7 @@ class Mobject(Container):
|
|||
# For subclasses
|
||||
pass
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
# Typically implemented in subclass, unless purposefully left blank
|
||||
pass
|
||||
|
||||
|
|
@ -1111,6 +1112,12 @@ class Mobject(Container):
|
|||
sm1.interpolate_color(sm1, sm2, 1)
|
||||
return self
|
||||
|
||||
def prepare_for_animation(self):
|
||||
pass
|
||||
|
||||
def cleanup_from_animation(self):
|
||||
pass
|
||||
|
||||
# Errors
|
||||
def throw_error_if_no_points(self):
|
||||
if self.has_no_points():
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ class Speedometer(VMobject):
|
|||
"needle_color": YELLOW,
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
start_angle = np.pi / 2 + self.arc_angle / 2
|
||||
end_angle = np.pi / 2 - self.arc_angle / 2
|
||||
self.add(Arc(
|
||||
|
|
@ -866,7 +866,7 @@ class PlayingCard(VGroup):
|
|||
def __init__(self, key=None, **kwargs):
|
||||
VGroup.__init__(self, key=key, **kwargs)
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.add(Rectangle(
|
||||
height=self.height,
|
||||
width=self.height / self.height_to_width,
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class SVGMobject(VMobject):
|
|||
return
|
||||
raise IOError(f"No file matching {file_name} in image directory")
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
doc = minidom.parse(self.file_path)
|
||||
self.ref_to_element = {}
|
||||
|
||||
|
|
@ -319,7 +319,7 @@ class VMobjectFromSVGPathstring(VMobject):
|
|||
digest_locals(self)
|
||||
VMobject.__init__(self, **kwargs)
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.relative_point = ORIGIN
|
||||
for command, coord_string in self.get_commands_and_coord_strings():
|
||||
new_points = self.string_to_points(command, coord_string)
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ class Cube(VGroup):
|
|||
"side_length": 2,
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
for vect in IN, OUT, LEFT, RIGHT, UP, DOWN:
|
||||
face = Square(
|
||||
side_length=self.side_length,
|
||||
|
|
@ -153,7 +153,7 @@ class Prism(Cube):
|
|||
"dimensions": [3, 2, 1]
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
Cube.generate_points(self)
|
||||
def init_points(self):
|
||||
Cube.init_points(self)
|
||||
for dim, value in enumerate(self.dimensions):
|
||||
self.rescale_to_fit(value, dim, stretch=True)
|
||||
|
|
|
|||
|
|
@ -58,6 +58,10 @@ class VMobject(Mobject):
|
|||
"render_primative": moderngl.TRIANGLES,
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.triangulation_locked = False
|
||||
|
||||
def get_group_class(self):
|
||||
return VGroup
|
||||
|
||||
|
|
@ -796,6 +800,13 @@ class VMobject(Mobject):
|
|||
vmob.pointwise_become_partial(self, a, b)
|
||||
return vmob
|
||||
|
||||
def prepare_for_animation(self):
|
||||
if self.get_fill_opacity() > 0:
|
||||
self.lock_triangulation()
|
||||
|
||||
def cleanup_from_animation(self):
|
||||
self.unlock_triangulation()
|
||||
|
||||
# For shaders
|
||||
def get_shader_info_list(self):
|
||||
result = []
|
||||
|
|
@ -855,10 +866,39 @@ class VMobject(Mobject):
|
|||
data['joint_type'] = joint_type_to_code[self.joint_type]
|
||||
return data
|
||||
|
||||
def get_triangulation(self):
|
||||
def lock_triangulation(self):
|
||||
for sm in self.family_members_with_points():
|
||||
sm.triangulation_locked = False
|
||||
sm.saved_triangulation = sm.get_triangulation()
|
||||
sm.triangulation_locked = True
|
||||
return self
|
||||
|
||||
def unlock_triangulation(self):
|
||||
for sm in self.family_members_with_points():
|
||||
sm.triangulation_locked = False
|
||||
|
||||
def get_signed_polygonal_area(self):
|
||||
nppc = self.n_points_per_curve
|
||||
p0 = self.points[0::nppc]
|
||||
p1 = self.points[nppc - 1::nppc]
|
||||
# Add up (x1 + x2)*(y2 - y1) for all edges (x1, y1), (x2, y2)
|
||||
return sum((p0[:, 0] + p1[:, 0]) * (p1[:, 1] - p0[:, 1]))
|
||||
|
||||
def get_orientation(self):
|
||||
return np.sign(self.get_signed_polygonal_area())
|
||||
|
||||
def get_triangulation(self, orientation=None):
|
||||
# Figure out how to triangulate the interior to know
|
||||
# how to send the points as to the vertex shader.
|
||||
# First triangles come directly from the points
|
||||
if orientation is None:
|
||||
orientation = self.get_orientation()
|
||||
|
||||
if self.triangulation_locked:
|
||||
return self.saved_triangulation
|
||||
|
||||
if self.has_no_points():
|
||||
return []
|
||||
|
||||
points = self.points
|
||||
indices = np.arange(len(points), dtype=int)
|
||||
|
|
@ -869,21 +909,17 @@ class VMobject(Mobject):
|
|||
v01s = b1s - b0s
|
||||
v12s = b2s - b1s
|
||||
|
||||
# TODO, account fo 3d
|
||||
# TODO, account for 3d
|
||||
crosses = cross2d(v01s, v12s)
|
||||
orientations = np.sign(crosses)
|
||||
convexities = orientation * np.sign(crosses)
|
||||
|
||||
atol = self.tolerance_for_point_equality
|
||||
end_of_loop = np.zeros(orientations.shape, dtype=bool)
|
||||
end_of_loop = np.zeros(len(b0s), dtype=bool)
|
||||
end_of_loop[:-1] = (np.abs(b2s[:-1] - b0s[1:]) > atol).any(1)
|
||||
end_of_loop[-1] = True
|
||||
|
||||
# Add up (x1 + x2)*(y2 - y1) for all edges (x1, y1), (x2, y2)
|
||||
signed_area_terms = (b0s[:, 0] + b2s[:, 0]) * (b2s[:, 1] - b0s[:, 1])
|
||||
# Total signed area determines orientation
|
||||
total_orientation = np.sign(signed_area_terms.sum())
|
||||
orientations *= total_orientation
|
||||
concave_parts = orientations < 0
|
||||
convexities *= orientation
|
||||
concave_parts = convexities < 0
|
||||
|
||||
# These are the vertices to which we'll apply a polygon triangulation
|
||||
inner_vert_indices = np.hstack([
|
||||
|
|
@ -897,11 +933,11 @@ class VMobject(Mobject):
|
|||
# Triangulate
|
||||
inner_verts = points[inner_vert_indices]
|
||||
inner_tri_indices = inner_vert_indices[
|
||||
earclip_triangulation(inner_verts, rings, total_orientation)
|
||||
earclip_triangulation(inner_verts, rings)
|
||||
]
|
||||
|
||||
tri_indices = np.hstack([indices, inner_tri_indices])
|
||||
return tri_indices, total_orientation
|
||||
return tri_indices
|
||||
|
||||
def get_fill_shader_data(self):
|
||||
dtype = [
|
||||
|
|
@ -913,10 +949,11 @@ class VMobject(Mobject):
|
|||
|
||||
points = self.points
|
||||
|
||||
# TODO, potentially cache triangulation
|
||||
tri_indices, orientation = self.get_triangulation()
|
||||
orientation = self.get_orientation()
|
||||
tri_indices = self.get_triangulation(orientation)
|
||||
|
||||
rgbas = self.get_fill_rgbas() # TODO, best way to enable multiple colors?
|
||||
# TODO, best way to enable multiple colors?
|
||||
rgbas = self.get_fill_rgbas()
|
||||
|
||||
data = np.zeros(len(tri_indices), dtype=dtype)
|
||||
data["point"] = points[tri_indices]
|
||||
|
|
@ -930,7 +967,6 @@ class VMobject(Mobject):
|
|||
return data
|
||||
|
||||
|
||||
|
||||
class VGroup(VMobject):
|
||||
def __init__(self, *vmobjects, **kwargs):
|
||||
if not all([isinstance(m, VMobject) for m in vmobjects]):
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ class GeneralizedPascalsTriangle(VMobject):
|
|||
"submob_class": combinationMobject,
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.cell_height = float(self.height) / self.nrows
|
||||
self.cell_width = float(self.width) / self.nrows
|
||||
self.bottom_left = (self.cell_width * self.nrows / 2.0) * LEFT + \
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class SelfSimilarFractal(VMobject):
|
|||
VMobject.init_colors(self)
|
||||
self.set_color_by_gradient(*self.colors)
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
order_n_self = self.get_order_n_self(self.order)
|
||||
if self.order == 0:
|
||||
self.submobjects = [order_n_self]
|
||||
|
|
@ -210,7 +210,7 @@ class PiCreatureFractal(VMobject):
|
|||
pi.set_color(color)
|
||||
pi.set_stroke(color, width=0)
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
random.seed(self.random_seed)
|
||||
modes = get_all_pi_creature_modes()
|
||||
seed = PiCreature(mode=self.start_mode)
|
||||
|
|
@ -315,7 +315,7 @@ class FractalCurve(VMobject):
|
|||
},
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
points = self.get_anchor_points()
|
||||
self.set_points_as_corners(points)
|
||||
if not self.monochromatic:
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ class AmbientLight(VMobject):
|
|||
"radius": 5.0
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
# in theory, this method is only called once, right?
|
||||
# so removing submobs shd not be necessary
|
||||
#
|
||||
|
|
@ -181,7 +181,7 @@ class Spotlight(VMobject):
|
|||
def get_source_point(self):
|
||||
return self.source_point.get_location()
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
self.submobjects = []
|
||||
|
||||
self.add(self.source_point)
|
||||
|
|
@ -346,7 +346,7 @@ class LightSource(VMobject):
|
|||
"camera_mob": None
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
def init_points(self):
|
||||
|
||||
self.add(self.source_point)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
from time import sleep
|
||||
import code
|
||||
import os
|
||||
import readline
|
||||
import subprocess
|
||||
|
||||
from manimlib.scene.scene import Scene
|
||||
|
|
@ -10,7 +9,6 @@ import manimlib.constants
|
|||
|
||||
def start_livestream(to_twitch=False, twitch_key=None):
|
||||
class Manim():
|
||||
|
||||
def __new__(cls):
|
||||
kwargs = {
|
||||
"scene_name": manimlib.constants.LIVE_STREAM_NAME,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue