def construct(self): grid = get_grid() grid.sort_points(np.linalg.norm) freq_line = get_freq_line() freq_line.sort_points(lambda p : p[0]) red, blue = Color(RED), Color(BLUE) freq_line.gradient_highlight(red, blue) colors = [ Color(rgb = interpolate( np.array(red.rgb), np.array(blue.rgb), alpha )) for alpha in np.arange(4)/3. ] string = Line(3*LEFT, 3*RIGHT, color = colors[1]) vibration = Vibrate(string) vibration_copy = vibration.copy() vibration_copy.mobject.stroke_width = 1 sub_vibrations = [ Vibrate( string.copy().shift((n-1)*UP).highlight(colors[n]), overtones = 1, spatial_period = 6./(n+1), temporal_period = 1./(n+1), amplitude = 0.5/(n+1) ) for n in range(4) ] words = TexMobject("&\\vdots \\\\ \\text{thousands }& \\text{of frequencies} \\\\ &\\vdots") words.to_edge(UP, buff = 0.1) self.add(grid) self.dither() self.play(DelayByOrder(ApplyMethod( grid.gradient_highlight, red, blue ))) self.play(Transform(grid, freq_line)) self.dither() self.play( ShimmerIn( words, rate_func = squish_rate_func(smooth, 0, 0.2) ), *sub_vibrations, run_time = 5 ) self.play( *[ TransformAnimations( sub_vib, vibration ) for sub_vib in sub_vibrations ]+[FadeOut(words)] ) self.clear() self.add(freq_line) self.play(vibration)
def add_treds_to_tires(self): for tire in self.get_tires(): radius = tire.get_width() / 2 center = tire.get_center() tred = Line(0.9 * radius * RIGHT, 1.4 * radius * RIGHT, stroke_width=2, color=BLACK) tred.rotate_in_place(np.pi / 4) for theta in np.arange(0, 2 * np.pi, np.pi / 4): new_tred = tred.copy() new_tred.rotate(theta, about_point=ORIGIN) new_tred.shift(center) tire.add(new_tred) return self
def construct(self): big_grid_dim = 20. small_grid_dim = 6. big_grid = Grid(64, 64, height=big_grid_dim, width=big_grid_dim) big_grid.to_corner(UP + RIGHT, buff=2) small_grid = big_grid.copy() small_grid.scale(small_grid_dim / big_grid_dim) small_grid.center() pixel = MobjectFromRegion( region_from_polygon_vertices( *0.2 * np.array([RIGHT + DOWN, RIGHT + UP, LEFT + UP, LEFT + DOWN]))) pixel.set_color(WHITE) pixel_width = big_grid.width / big_grid.columns pixel.scale_to_fit_width(pixel_width) pixel.to_corner(UP + RIGHT, buff=2) pixel.shift(5 * pixel_width * (2 * LEFT + DOWN)) freq_line = get_freq_line() dot = Dot() dot.shift(freq_line.get_center() + 2 * RIGHT) string = Line(LEFT, RIGHT, color=GREEN) arrow = Arrow(dot, string.get_center()) vibration_config = { "overtones": 1, "spatial_period": 2, } vibration, loud_vibration, quiet_vibration = [ Vibrate(string.copy(), amplitude=a, **vibration_config) for a in [0.5, 1., 0.25] ] self.add(small_grid) self.dither() self.play(Transform(small_grid, big_grid)) self.play(FadeIn(pixel)) self.dither() self.play(FadeOut(small_grid), ShowCreation(freq_line)) self.remove(small_grid) self.play(Transform(pixel, dot), ) self.dither() self.play(ShowCreation(arrow)) self.play(loud_vibration) self.play(TransformAnimations(loud_vibration, quiet_vibration), ApplyMethod(dot.fade, 0.9)) self.clear() self.add(freq_line, dot, arrow) self.play(quiet_vibration)
def construct(self): big_grid_dim = 20. small_grid_dim = 6. big_grid = Grid(64, 64, height = big_grid_dim, width = big_grid_dim) big_grid.to_corner(UP+RIGHT, buff = 2) small_grid = big_grid.copy() small_grid.scale(small_grid_dim/big_grid_dim) small_grid.center() pixel = MobjectFromRegion( region_from_polygon_vertices(*0.2*np.array([ RIGHT+DOWN, RIGHT+UP, LEFT+UP, LEFT+DOWN ])) ) pixel.set_color(WHITE) pixel_width = big_grid.width/big_grid.columns pixel.scale_to_fit_width(pixel_width) pixel.to_corner(UP+RIGHT, buff = 2) pixel.shift(5*pixel_width*(2*LEFT+DOWN)) freq_line = get_freq_line() dot = Dot() dot.shift(freq_line.get_center() + 2*RIGHT) string = Line(LEFT, RIGHT, color = GREEN) arrow = Arrow(dot, string.get_center()) vibration_config = { "overtones" : 1, "spatial_period" : 2, } vibration, loud_vibration, quiet_vibration = [ Vibrate(string.copy(), amplitude = a, **vibration_config) for a in [0.5, 1., 0.25] ] self.add(small_grid) self.dither() self.play( Transform(small_grid, big_grid) ) self.play(FadeIn(pixel)) self.dither() self.play( FadeOut(small_grid), ShowCreation(freq_line) ) self.remove(small_grid) self.play( Transform(pixel, dot), ) self.dither() self.play(ShowCreation(arrow)) self.play(loud_vibration) self.play( TransformAnimations(loud_vibration, quiet_vibration), ApplyMethod(dot.fade, 0.9) ) self.clear() self.add(freq_line, dot, arrow) self.play(quiet_vibration)