def generate_discrete_path(self): points = self.cycloid.points tops = list(self.layer_tops) tops.append(tops[-1]-self.layer_thickness) indices = [ np.argmin(np.abs(points[:, 1]-top)) for top in tops ] self.bend_points = points[indices[1:-1]] self.path_angles = [] self.discrete_path = Mobject1D( color = YELLOW, density = 3*DEFAULT_POINT_DENSITY_1D ) for start, end in zip(indices, indices[1:]): start_point, end_point = points[start], points[end] self.discrete_path.add_line( start_point, end_point ) self.path_angles.append( angle_of_vector(start_point-end_point)-np.pi/2 ) self.discrete_path.add_line( points[end], SPACE_WIDTH*RIGHT+(self.layer_tops[-1]-1)*UP )
def construct(self): curve = HilbertCurve(order=1) grid = Grid(2, 2, stroke_width=1) self.add(grid, curve) for order in range(2, 6): self.dither() new_grid = Grid(2**order, 2**order, stroke_width=1) self.play(ShowCreation(new_grid), Animation(curve)) self.remove(grid) grid = new_grid self.play(Transform(curve, HilbertCurve(order=order))) square = Square(side_length=6, color=WHITE) square.corner = Mobject1D() square.corner.add_line(3 * DOWN, ORIGIN) square.corner.add_line(ORIGIN, 3 * RIGHT) square.digest_mobject_attrs() square.scale(2**(-5)) square.corner.highlight( Color(rgb=curve.rgbs[curve.get_num_points() / 3])) square.shift( grid.get_corner(UP+LEFT)-\ square.get_corner(UP+LEFT) ) self.dither() self.play(FadeOut(grid), FadeOut(curve), FadeIn(square)) self.play(ApplyMethod(square.replace, grid)) self.dither()
def generate_discrete_path(self): points = self.cycloid.points tops = [mob.get_top()[1] for mob in self.layers] tops.append(tops[-1] - self.layers[0].get_height()) indices = [np.argmin(np.abs(points[:, 1] - top)) for top in tops] self.bend_points = points[indices[1:-1]] self.path_angles = [] self.discrete_path = Mobject1D(color=WHITE, density=3 * DEFAULT_POINT_DENSITY_1D) for start, end in zip(indices, indices[1:]): start_point, end_point = points[start], points[end] self.discrete_path.add_line(start_point, end_point) self.path_angles.append( angle_of_vector(start_point - end_point) - np.pi / 2) self.discrete_path.add_line( points[end], SPACE_WIDTH * RIGHT + (tops[-1] - 0.5) * UP)