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 construct(self): overtones = 5 floor = 2 * DOWN main_string = Vibrate(color=BLUE_D) component_strings = [ Vibrate(num_periods=k + 1, overtones=1, color=color, center=2 * DOWN + UP * k) for k, color in zip(range(overtones), Color(BLUE_E).range_to(WHITE, overtones)) ] dots = [ Dot(string.mobject.get_center(), color=string.mobject.get_color()) for string in component_strings ] freq_line = get_freq_line() freq_line.shift(floor) freq_line.sort_points(np.linalg.norm) brace = Brace(freq_line, UP) words = TextMobject("Range of frequency values") words.next_to(brace, UP) self.play(*[ TransformAnimations(main_string.copy(), string, run_time=5) for string in component_strings ]) self.clear() self.play(*[ TransformAnimations(string, Animation(dot)) for string, dot in zip(component_strings, dots) ]) self.clear() self.play( ShowCreation(freq_line), GrowFromCenter(brace), ShimmerIn(words), *[ Transform(dot, dot.copy().scale(2).rotate(-np.pi / 2).shift(floor), path_func=path_along_arc(np.pi / 3)) for dot in dots ]) self.dither(0.5)
def construct(self): overtones = 5 floor = 2*DOWN main_string = Vibrate(color = BLUE_D) component_strings = [ Vibrate( num_periods = k+1, overtones = 1, color = color, center = 2*DOWN + UP*k ) for k, color in zip( range(overtones), Color(BLUE_E).range_to(WHITE, overtones) ) ] dots = [ Dot( string.mobject.get_center(), color = string.mobject.get_color() ) for string in component_strings ] freq_line = get_freq_line() freq_line.shift(floor) freq_line.sort_points(np.linalg.norm) brace = Brace(freq_line, UP) words = TextMobject("Range of frequency values") words.next_to(brace, UP) self.play(*[ TransformAnimations( main_string.copy(), string, run_time = 5 ) for string in component_strings ]) self.clear() self.play(*[ TransformAnimations( string, Animation(dot) ) for string, dot in zip(component_strings, dots) ]) self.clear() self.play( ShowCreation(freq_line), GrowFromCenter(brace), ShimmerIn(words), *[ Transform( dot, dot.copy().scale(2).rotate(-np.pi/2).shift(floor), path_func = path_along_arc(np.pi/3) ) for dot in dots ] ) self.dither(0.5)