class ThoughtBubble(Bubble): DEFAULT_CONFIG = { "num_bulges": 7, "initial_inner_radius": 1.8, "initial_width": 6, } def __init__(self, **kwargs): Bubble.__init__(self, **kwargs) def get_tip(self): return self.small_circle.get_bottom() def generate_points(self): self.small_circle = Circle().scale(0.15) self.small_circle.shift(2.5 * DOWN + 2 * LEFT) self.add(self.small_circle) self.add(Circle().scale(0.3).shift(2 * DOWN + 1.5 * LEFT)) for n in range(self.num_bulges): theta = 2 * np.pi * n / self.num_bulges self.add(Circle().shift((np.cos(theta), np.sin(theta), 0))) self.filter_out( lambda p: np.linalg.norm(p) < self.initial_inner_radius) self.stretch_to_fit_width(self.initial_width) self.highlight("white")
def generate_points(self): self.small_circle = Circle().scale(0.15) self.small_circle.shift(2.5 * DOWN + 2 * LEFT) self.add(self.small_circle) self.add(Circle().scale(0.3).shift(2 * DOWN + 1.5 * LEFT)) for n in range(self.num_bulges): theta = 2 * np.pi * n / self.num_bulges self.add(Circle().shift((np.cos(theta), np.sin(theta), 0))) self.filter_out( lambda p: np.linalg.norm(p) < self.initial_inner_radius) self.stretch_to_fit_width(self.initial_width) self.highlight("white")
def animate_product(self, left, right, result): l_matrix = left.get_mob_matrix() r_matrix = right.get_mob_matrix() result_matrix = result.get_mob_matrix() circle = Circle( radius = l_matrix[0][0].get_height(), color = GREEN ) circles = VMobject(*[ entry.get_point_mobject() for entry in l_matrix[0][0], r_matrix[0][0] ]) (m, k), n = l_matrix.shape, r_matrix.shape[1] for mob in result_matrix.flatten(): mob.highlight(BLACK) lagging_anims = [] for a in range(m): for b in range(n): for c in range(k): l_matrix[a][c].highlight(YELLOW) r_matrix[c][b].highlight(YELLOW) for c in range(k): start_parts = VMobject( l_matrix[a][c].copy(), r_matrix[c][b].copy() ) result_entry = result_matrix[a][b].split()[c] new_circles = VMobject(*[ circle.copy().shift(part.get_center()) for part in start_parts.split() ]) self.play(Transform(circles, new_circles)) self.play( Transform( start_parts, result_entry.copy().highlight(YELLOW), path_arc = -np.pi/2, submobject_mode = "all_at_once", ), *lagging_anims ) result_entry.highlight(YELLOW) self.remove(start_parts) lagging_anims = [ ApplyMethod(result_entry.highlight, WHITE) ] for c in range(k): l_matrix[a][c].highlight(WHITE) r_matrix[c][b].highlight(WHITE) self.play(FadeOut(circles), *lagging_anims) self.dither()
def get_circles_and_points(self, min_input, max_input): input_left, input_right = [ self.interval.number_to_point(num) for num in min_input, max_input ] input_circle = Circle( radius = np.linalg.norm(input_left-input_right)/2, color = WHITE ) input_circle.shift((input_left+input_right)/2) input_points = Line( input_left, input_right, color = self.input_color ) output_points = Mobject(color = self.output_color) n = self.output.get_num_points() output_points.add_points( self.output.points[int(min_input*n):int(max_input*n)] ) output_center = output_points.points[int(0.5*output_points.get_num_points())] max_distance = np.linalg.norm(output_center-output_points.points[-1]) output_circle = Circle( radius = max_distance, color = WHITE ) output_circle.shift(output_center) return ( input_circle, input_points, output_circle, output_points )
def increment(self, run_time_per_anim = 1): moving_dot = Dot( self.counting_dot_starting_position, radius = self.count_dot_starting_radius, color = self.digit_place_colors[0], ) moving_dot.generate_target() moving_dot.set_fill(opacity = 0) kwargs = { "run_time" : run_time_per_anim } continue_rolling_over = True first_move = True place = 0 while continue_rolling_over: added_anims = [] if first_move: added_anims += self.get_digit_increment_animations() first_move = False moving_dot.target.replace( self.dot_template_iterators[place].next() ) self.play(MoveToTarget(moving_dot), *added_anims, **kwargs) self.curr_configurations[place].add(moving_dot) if len(self.curr_configurations[place].split()) == self.get_place_max(place): full_configuration = self.curr_configurations[place] self.curr_configurations[place] = VGroup() place += 1 center = full_configuration.get_center_of_mass() radius = 0.6*max( full_configuration.get_width(), full_configuration.get_height(), ) circle = Circle( radius = radius, stroke_width = 0, fill_color = self.digit_place_colors[place], fill_opacity = 0.5, ) circle.move_to(center) moving_dot = VGroup(circle, full_configuration) moving_dot.generate_target() moving_dot[0].set_fill(opacity = 0) else: continue_rolling_over = False
def __init__(self, focal_point, **kwargs): digest_config(self, kwargs) circles = VGroup() for x in range(self.n_circles): circle = Circle( radius=self.big_radius, stroke_color=BLACK, stroke_width=0, ) circle.move_to(focal_point) circle.save_state() circle.scale_to_fit_width(self.small_radius * 2) circle.set_stroke(WHITE, 8) circles.add(circle) LaggedStart.__init__(self, ApplyMethod, circles, lambda c: (c.restore, ), **kwargs)
def circle_to_mobject(self, circle_element): x, y, r = [ float(circle_element.getAttribute(key)) if circle_element.hasAttribute(key) else 0.0 for key in "cx", "cy", "r" ] return Circle(radius=r).shift(x * RIGHT + y * DOWN)
def ellipse_to_mobject(self, circle_element): x, y, rx, ry = [ float(circle_element.getAttribute(key)) if circle_element.hasAttribute(key) else 0.0 for key in "cx", "cy", "rx", "ry" ] return Circle().scale(rx * RIGHT + ry * UP).shift(x * RIGHT + y * DOWN)
def animate_product(self, left, right, result): l_matrix = left.get_mob_matrix() r_matrix = right.get_mob_matrix() result_matrix = result.get_mob_matrix() circle = Circle(radius=l_matrix[0][0].get_height(), color=GREEN) circles = VMobject(*[ entry.get_point_mobject() for entry in l_matrix[0][0], r_matrix[0][0] ]) (m, k), n = l_matrix.shape, r_matrix.shape[1] for mob in result_matrix.flatten(): mob.highlight(BLACK) lagging_anims = [] for a in range(m): for b in range(n): for c in range(k): l_matrix[a][c].highlight(YELLOW) r_matrix[c][b].highlight(YELLOW) for c in range(k): start_parts = VMobject(l_matrix[a][c].copy(), r_matrix[c][b].copy()) result_entry = result_matrix[a][b].split()[c] new_circles = VMobject(*[ circle.copy().shift(part.get_center()) for part in start_parts.split() ]) self.play(Transform(circles, new_circles)) self.play( Transform( start_parts, result_entry.copy().highlight(YELLOW), path_arc=-np.pi / 2, submobject_mode="all_at_once", ), *lagging_anims) result_entry.highlight(YELLOW) self.remove(start_parts) lagging_anims = [ ApplyMethod(result_entry.highlight, WHITE) ] for c in range(k): l_matrix[a][c].highlight(WHITE) r_matrix[c][b].highlight(WHITE) self.play(FadeOut(circles), *lagging_anims) self.wait()
def generate_points(self): complex_power = 0.9 radius = self.initial_width/2 circle = Circle(radius = radius) circle.scale(1.0/radius) circle.apply_complex_function(lambda z : z**complex_power) circle.scale(radius) boundary_point_as_complex = radius*complex(-1)**complex_power boundary_points = [ [ boundary_point_as_complex.real, unit*boundary_point_as_complex.imag, 0 ] for unit in -1, 1 ] tip = radius*(1.5*LEFT+UP) self.little_line = Line(boundary_points[0], tip) self.circle = circle self.add( circle, self.little_line, Line(boundary_points[1], tip) ) self.highlight("white") self.rotate(np.pi/2) self.stretch_to_fit_height(self.initial_height)
def construct(self): digest_config(self, {}) ## Usually shouldn't need this... self.frame_duration = self.DEFAULT_CONFIG["frame_duration"] ## digest_config(self, {}) circle = Circle( density = self.circle_density, color = self.circle_blue ) circle.repeat(self.circle_repeats) circle.scale(self.radius) sphere = Sphere( density = self.sphere_density, color = self.sphere_blue ) sphere.scale(self.radius) sphere.rotate(-np.pi / 7, [1, 0, 0]) sphere.rotate(-np.pi / 7) iris = Mobject() iris.interpolate( circle, sphere, self.interpolation_factor ) for mob, color in [(iris, self.sphere_brown), (circle, self.circle_brown)]: mob.highlight(color, lambda (x, y, z) : x < 0 and y > 0) mob.highlight( "black", lambda point: np.linalg.norm(point) < \ self.inner_radius_ratio*self.radius ) name = TextMobject("3Blue1Brown").center() name.highlight("grey") name.shift(2*DOWN) self.play(Transform( circle, iris, run_time = self.run_time )) self.frames = drag_pixels(self.frames) self.save_image(IMAGE_DIR) self.show_frame() self.add(name) self.dither() print "Dragging pixels..."
def generate_points(self): self.small_circle = Circle().scale(0.15) self.small_circle.shift(2.5*DOWN+2*LEFT) self.add(self.small_circle) self.add(Circle().scale(0.3).shift(2*DOWN+1.5*LEFT)) for n in range(self.num_bulges): theta = 2*np.pi*n/self.num_bulges self.add(Circle().shift((np.cos(theta), np.sin(theta), 0))) self.filter_out(lambda p : np.linalg.norm(p) < self.initial_inner_radius) self.stretch_to_fit_width(self.initial_width) self.highlight("white")
def construct(self): circle = Circle(color = YELLOW_C) self.use_function( lambda p : p/(2*np.linalg.norm(0.5*p)**0.5+0.01) ) self.add_plane() self.add(circle) self.add_arrows() self.add_dots() self.flow(run_time = 2, virtual_time = 2) self.dither(2)
def construct(self): digest_config(self, {}) ## Usually shouldn't need this... self.frame_duration = self.CONFIG["frame_duration"] ## digest_config(self, {}) circle = Circle(density=self.circle_density, color=self.circle_blue) circle.repeat(self.circle_repeats) circle.scale(self.radius) sphere = Sphere(density=self.sphere_density, color=self.sphere_blue) sphere.scale(self.radius) sphere.rotate(-np.pi / 7, [1, 0, 0]) sphere.rotate(-np.pi / 7) iris = Mobject() iris.interpolate(circle, sphere, self.interpolation_factor) for mob, color in [(iris, self.sphere_brown), (circle, self.circle_brown)]: mob.highlight(color, lambda (x, y, z): x < 0 and y > 0) mob.highlight( "black", lambda point: np.linalg.norm(point) < \ self.inner_radius_ratio*self.radius ) self.name_mob = TextMobject("3Blue1Brown").center() self.name_mob.highlight("grey") self.name_mob.shift(2 * DOWN) self.play(Transform(circle, iris, run_time=self.run_time)) self.frames = drag_pixels(self.frames) self.save_image(IMAGE_DIR) self.logo = MobjectFromPixelArray(self.frames[-1]) self.add(self.name_mob) self.dither()
class ThoughtBubble(Bubble): DEFAULT_CONFIG = { "num_bulges" : 7, "initial_inner_radius" : 1.8, "initial_width" : 6, } def __init__(self, **kwargs): Bubble.__init__(self, **kwargs) def get_tip(self): return self.small_circle.get_bottom() def generate_points(self): self.small_circle = Circle().scale(0.15) self.small_circle.shift(2.5*DOWN+2*LEFT) self.add(self.small_circle) self.add(Circle().scale(0.3).shift(2*DOWN+1.5*LEFT)) for n in range(self.num_bulges): theta = 2*np.pi*n/self.num_bulges self.add(Circle().shift((np.cos(theta), np.sin(theta), 0))) self.filter_out(lambda p : np.linalg.norm(p) < self.initial_inner_radius) self.stretch_to_fit_width(self.initial_width) self.highlight("white")
def __init__(self, **kwargs): circle = Circle() ticks = [] for x in range(12): alpha = x / 12. point = complex_to_R3(np.exp(2 * np.pi * alpha * complex(0, 1))) length = 0.2 if x % 3 == 0 else 0.1 ticks.append(Line(point, (1 - length) * point)) self.hour_hand = Line(ORIGIN, 0.3 * UP) self.minute_hand = Line(ORIGIN, 0.6 * UP) # for hand in self.hour_hand, self.minute_hand: # #Balance out where the center is # hand.add(VectorizedPoint(-hand.get_end())) VGroup.__init__(self, circle, self.hour_hand, self.minute_hand, *ticks)
def __init__(self, camera): VMobject.__init__(self) stroke = 20 factor = sum(PRODUCTION_QUALITY_CAMERA_CONFIG["pixel_shape"]) / sum( camera.pixel_shape) stroke /= factor self.add(Circle()) h1, h2, x = 1, 1.5, 0.5 y = -np.sqrt(1 - x**2) + h1 self.add(Line([-x, y, 0], [-x, y - h1, 0])) self.add(Line([0, 1, 0], [0, 1 - h2, 0])) self.add(Line([x, y, 0], [x, y - h1, 0])) self.set_stroke(color="#00ffff", width=stroke) self.to_corner(RIGHT + DOWN)
def generate_points(self): complex_power = 0.9 radius = self.initial_width / 2 circle = Circle(radius=radius) circle.scale(1.0 / radius) circle.apply_complex_function(lambda z: z**complex_power) circle.scale(radius) boundary_point_as_complex = radius * complex(-1)**complex_power boundary_points = [[ boundary_point_as_complex.real, unit * boundary_point_as_complex.imag, 0 ] for unit in -1, 1] tip = radius * (1.5 * LEFT + UP) self.little_line = Line(boundary_points[0], tip) self.circle = circle self.add(circle, self.little_line, Line(boundary_points[1], tip)) self.highlight("white") self.rotate(np.pi / 2) self.stretch_to_fit_height(self.initial_height)
def construct(self): circles = [ Circle().shift(3*vect) for vect in compass_directions() ] self.use_function( lambda (x, y, z) : 0.5*(y**3-9*y)*RIGHT+(x**3-9*x)*UP ) self.add_plane() self.add_arrows() # for circle in circles: # self.play(ShowCreation(circle)) self.add_dots() self.add_extra_dots() self.flow( virtual_time = 4, run_time = 20, rate_func = None )
def __init__(self, mobject, **kwargs): digest_config(self, kwargs) circle = Circle(color = self.color, **kwargs) circle.surround(mobject) Indicate.__init__(self, circle, **kwargs)
def __init__(self, **kwargs): Circle.__init__(self, **kwargs) self.rotate(np.pi/2) self.to_corner(UP+RIGHT, buff = 0.8)
def get_seed_shape(self): return Circle()