def setup_axes(self, animate=False): ##TODO, once eoc is done, refactor this to be less redundant. x_num_range = float(self.x_max - self.x_min) self.space_unit_to_x = self.x_axis_width / x_num_range self.x_labeled_nums = self.x_labeled_nums or [] if self.x_leftmost_tick is None: self.x_leftmost_tick = self.x_min x_axis = NumberLine(x_min=self.x_min, x_max=self.x_max, unit_size=self.space_unit_to_x, tick_frequency=self.x_tick_frequency, leftmost_tick=self.x_leftmost_tick, numbers_with_elongated_ticks=self.x_labeled_nums, color=self.axes_color) x_axis.shift(self.graph_origin - x_axis.number_to_point(0)) if len(self.x_labeled_nums) > 0: if self.exclude_zero_label: self.x_labeled_nums = filter(lambda x: x != 0, self.x_labeled_nums) x_axis.add_numbers(*self.x_labeled_nums) x_label = TextMobject(self.x_axis_label) x_label.next_to(x_axis.get_tick_marks(), UP + RIGHT, buff=SMALL_BUFF) x_label.shift_onto_screen() x_axis.add(x_label) self.x_axis_label_mob = x_label y_num_range = float(self.y_max - self.y_min) self.space_unit_to_y = self.y_axis_height / y_num_range self.y_labeled_nums = self.y_labeled_nums or [] if self.y_bottom_tick is None: self.y_bottom_tick = self.y_min y_axis = NumberLine(x_min=self.y_min, x_max=self.y_max, unit_size=self.space_unit_to_y, tick_frequency=self.y_tick_frequency, leftmost_tick=self.y_bottom_tick, numbers_with_elongated_ticks=self.y_labeled_nums, color=self.axes_color) y_axis.shift(self.graph_origin - y_axis.number_to_point(0)) y_axis.rotate(np.pi / 2, about_point=y_axis.number_to_point(0)) if len(self.y_labeled_nums) > 0: if self.exclude_zero_label: self.y_labeled_nums = filter(lambda y: y != 0, self.y_labeled_nums) y_axis.add_numbers(*self.y_labeled_nums) for mob in y_axis.numbers: mob.next_to(mob.get_center(), LEFT, MED_SMALL_BUFF) mob.shift(self.y_axis_numbers_nudge) y_label = TextMobject(self.y_axis_label) y_label.next_to(y_axis.get_tick_marks(), UP + RIGHT, buff=SMALL_BUFF) y_label.shift_onto_screen() y_axis.add(y_label) self.y_axis_label_mob = y_label if animate: self.play(Write(VGroup(x_axis, y_axis))) else: self.add(x_axis, y_axis) self.x_axis, self.y_axis = self.axes = VGroup(x_axis, y_axis) self.default_graph_colors = it.cycle(self.default_graph_colors)
def setup_axes(self, animate = True): x_num_range = float(self.x_max - self.x_min) x_axis = NumberLine( x_min = self.x_min, x_max = self.x_max, space_unit_to_num = self.x_axis_width/x_num_range, tick_frequency = self.x_tick_frequency, leftmost_tick = self.x_leftmost_tick or self.x_min, numbers_with_elongated_ticks = self.x_labeled_nums, color = self.axes_color ) x_axis.shift(self.graph_origin - x_axis.number_to_point(0)) if self.x_labeled_nums: x_axis.add_numbers(*self.x_labeled_nums) x_label = TextMobject(self.x_axis_label) x_label.next_to(x_axis, RIGHT+UP, buff = SMALL_BUFF) x_label.shift_onto_screen() x_axis.add(x_label) self.x_axis_label_mob = x_label y_num_range = float(self.y_max - self.y_min) y_axis = NumberLine( x_min = self.y_min, x_max = self.y_max, space_unit_to_num = self.y_axis_height/y_num_range, tick_frequency = self.y_tick_frequency, leftmost_tick = self.y_bottom_tick or self.y_min, numbers_with_elongated_ticks = self.y_labeled_nums, color = self.axes_color ) y_axis.shift(self.graph_origin-y_axis.number_to_point(0)) y_axis.rotate(np.pi/2, about_point = y_axis.number_to_point(0)) if self.y_labeled_nums: y_axis.add_numbers(*self.y_labeled_nums) y_axis.numbers.shift(self.y_axis_numbers_nudge) y_label = TextMobject(self.y_axis_label) y_label.next_to(y_axis.get_top(), RIGHT, buff = 2*MED_BUFF) y_label.shift_onto_screen() y_axis.add(y_label) self.y_axis_label_mob = y_label if animate: self.play(Write(VGroup(x_axis, y_axis))) else: selfe.add(x_axis, y_axis_label) self.x_axis, self.y_axis = x_axis, y_axis
def setup_axes(self, animate=True): x_num_range = float(self.x_max - self.x_min) self.space_unit_to_x = self.x_axis_width / x_num_range x_axis = NumberLine(x_min=self.x_min, x_max=self.x_max, space_unit_to_num=self.space_unit_to_x, tick_frequency=self.x_tick_frequency, leftmost_tick=self.x_leftmost_tick or self.x_min, numbers_with_elongated_ticks=self.x_labeled_nums, color=self.axes_color) x_axis.shift(self.graph_origin - x_axis.number_to_point(0)) if self.x_labeled_nums: x_axis.add_numbers(*self.x_labeled_nums) x_label = TextMobject(self.x_axis_label) x_label.next_to(x_axis, RIGHT + UP, buff=SMALL_BUFF) x_label.shift_onto_screen() x_axis.add(x_label) self.x_axis_label_mob = x_label y_num_range = float(self.y_max - self.y_min) self.space_unit_to_y = self.y_axis_height / y_num_range y_axis = NumberLine(x_min=self.y_min, x_max=self.y_max, space_unit_to_num=self.space_unit_to_y, tick_frequency=self.y_tick_frequency, leftmost_tick=self.y_bottom_tick or self.y_min, numbers_with_elongated_ticks=self.y_labeled_nums, color=self.axes_color) y_axis.shift(self.graph_origin - y_axis.number_to_point(0)) y_axis.rotate(np.pi / 2, about_point=y_axis.number_to_point(0)) if self.y_labeled_nums: y_axis.add_numbers(*self.y_labeled_nums) y_axis.numbers.shift(self.y_axis_numbers_nudge) y_label = TextMobject(self.y_axis_label) y_label.next_to(y_axis.get_top(), RIGHT, buff=2 * MED_BUFF) y_label.shift_onto_screen() y_axis.add(y_label) self.y_axis_label_mob = y_label if animate: self.play(Write(VGroup(x_axis, y_axis))) else: self.add(x_axis, y_axis) self.x_axis, self.y_axis = x_axis, y_axis self.default_graph_colors = it.cycle(self.default_graph_colors)
def zoom_in_on(self, number, zoom_factor, run_time=2.0): unit_length_to_spatial_width = self.number_line.unit_length_to_spatial_width * zoom_factor radius = SPACE_WIDTH / unit_length_to_spatial_width tick_frequency = 10**(np.floor(np.log10(radius))) left_tick = tick_frequency * (np.ceil( (number - radius) / tick_frequency)) new_number_line = NumberLine( numerical_radius=radius, unit_length_to_spatial_width=unit_length_to_spatial_width, tick_frequency=tick_frequency, leftmost_tick=left_tick, number_at_center=number) new_displayed_numbers = new_number_line.default_numbers_to_display() new_number_mobs = new_number_line.get_number_mobjects( *new_displayed_numbers) transforms = [] additional_mobjects = [] squished_new_line = new_number_line.copy() squished_new_line.scale(1.0 / zoom_factor) squished_new_line.shift(self.number_line.number_to_point(number)) squished_new_line.points[:, 1] = self.number_line.number_to_point(0)[1] transforms.append(Transform(squished_new_line, new_number_line)) for mob, num in zip(new_number_mobs, new_displayed_numbers): point = Point(self.number_line.number_to_point(num)) point.shift(new_number_line.get_vertical_number_offset()) transforms.append(Transform(point, mob)) for mob in self.mobjects: if mob == self.number_line: new_mob = mob.copy() new_mob.shift(-self.number_line.number_to_point(number)) new_mob.stretch(zoom_factor, 0) transforms.append(Transform(mob, new_mob)) continue mob_center = mob.get_center() number_under_center = self.number_line.point_to_number(mob_center) new_point = new_number_line.number_to_point(number_under_center) new_point += mob_center[1] * UP if mob in self.number_mobs: transforms.append(Transform(mob, Point(new_point))) else: transforms.append( ApplyMethod(mob.shift, new_point - mob_center)) additional_mobjects.append(mob) line_to_hide_pixelation = Line(self.number_line.get_left(), self.number_line.get_right(), color=self.number_line.get_color()) self.add(line_to_hide_pixelation) self.play(*transforms, run_time=run_time) self.clear() self.number_line = new_number_line self.displayed_numbers = new_displayed_numbers self.number_mobs = new_number_mobs self.add(self.number_line, *self.number_mobs) self.add(*additional_mobjects)
def setup_axes(self, animate = False): x_num_range = float(self.x_max - self.x_min) self.space_unit_to_x = self.x_axis_width/x_num_range self.x_labeled_nums = self.x_labeled_nums or [] x_axis = NumberLine( x_min = self.x_min, x_max = self.x_max, space_unit_to_num = self.space_unit_to_x, tick_frequency = self.x_tick_frequency, leftmost_tick = self.x_leftmost_tick or self.x_min, numbers_with_elongated_ticks = self.x_labeled_nums, color = self.axes_color ) x_axis.shift(self.graph_origin - x_axis.number_to_point(0)) if len(self.x_labeled_nums) > 0: if self.exclude_zero_label: self.x_labeled_nums = filter( lambda x : x != 0, self.x_labeled_nums ) x_axis.add_numbers(*self.x_labeled_nums) x_label = TextMobject(self.x_axis_label) x_label.next_to( x_axis.get_tick_marks(), UP+RIGHT, buff = SMALL_BUFF ) x_label.shift_onto_screen() x_axis.add(x_label) self.x_axis_label_mob = x_label y_num_range = float(self.y_max - self.y_min) self.space_unit_to_y = self.y_axis_height/y_num_range self.y_labeled_nums = self.y_labeled_nums or [] y_axis = NumberLine( x_min = self.y_min, x_max = self.y_max, space_unit_to_num = self.space_unit_to_y, tick_frequency = self.y_tick_frequency, leftmost_tick = self.y_bottom_tick or self.y_min, numbers_with_elongated_ticks = self.y_labeled_nums, color = self.axes_color ) y_axis.shift(self.graph_origin-y_axis.number_to_point(0)) y_axis.rotate(np.pi/2, about_point = y_axis.number_to_point(0)) if len(self.y_labeled_nums) > 0: if self.exclude_zero_label: self.y_labeled_nums = filter( lambda y : y != 0, self.y_labeled_nums ) y_axis.add_numbers(*self.y_labeled_nums) for mob in y_axis.numbers: mob.next_to(mob.get_center(), LEFT, MED_SMALL_BUFF) mob.shift(self.y_axis_numbers_nudge) y_label = TextMobject(self.y_axis_label) y_label.next_to( y_axis.get_tick_marks(), UP+RIGHT, buff = SMALL_BUFF ) y_label.shift_onto_screen() y_axis.add(y_label) self.y_axis_label_mob = y_label if animate: self.play(Write(VGroup(x_axis, y_axis))) else: self.add(x_axis, y_axis) self.x_axis, self.y_axis = self.axes = VGroup(x_axis, y_axis) self.default_graph_colors = it.cycle(self.default_graph_colors)
def setup_axes(self, animate = False): x_num_range = float(self.x_max - self.x_min) self.space_unit_to_x = self.x_axis_width/x_num_range if self.x_labeled_nums is None: self.x_labeled_nums = np.arange( self.x_min, self.x_max, 2*self.x_tick_frequency ) x_axis = NumberLine( x_min = self.x_min, x_max = self.x_max, space_unit_to_num = self.space_unit_to_x, tick_frequency = self.x_tick_frequency, leftmost_tick = self.x_leftmost_tick or self.x_min, numbers_with_elongated_ticks = self.x_labeled_nums, color = self.axes_color ) x_axis.shift(self.graph_origin - x_axis.number_to_point(0)) if len(self.x_labeled_nums) > 0: x_axis.add_numbers(*filter( lambda x : x != 0, self.x_labeled_nums )) x_label = TextMobject(self.x_axis_label) x_label.next_to( x_axis.get_tick_marks(), UP+RIGHT, buff = SMALL_BUFF ) x_label.shift_onto_screen() x_axis.add(x_label) self.x_axis_label_mob = x_label y_num_range = float(self.y_max - self.y_min) self.space_unit_to_y = self.y_axis_height/y_num_range if self.y_labeled_nums is None: self.y_labeled_nums = np.arange( self.y_min, self.y_max, 2*self.y_tick_frequency ) y_axis = NumberLine( x_min = self.y_min, x_max = self.y_max, space_unit_to_num = self.space_unit_to_y, tick_frequency = self.y_tick_frequency, leftmost_tick = self.y_bottom_tick or self.y_min, numbers_with_elongated_ticks = self.y_labeled_nums, color = self.axes_color ) y_axis.shift(self.graph_origin-y_axis.number_to_point(0)) y_axis.rotate(np.pi/2, about_point = y_axis.number_to_point(0)) if len(self.y_labeled_nums) > 0: y_axis.add_numbers(*filter( lambda y : y != 0, self.y_labeled_nums )) for mob in y_axis.numbers: mob.next_to(mob.get_center(), LEFT, MED_SMALL_BUFF) mob.shift(self.y_axis_numbers_nudge) y_label = TextMobject(self.y_axis_label) y_label.next_to( y_axis.get_tick_marks(), UP+RIGHT, buff = SMALL_BUFF ) y_label.shift_onto_screen() y_axis.add(y_label) self.y_axis_label_mob = y_label if animate: self.play(Write(VGroup(x_axis, y_axis))) else: self.add(x_axis, y_axis) self.x_axis, self.y_axis = x_axis, y_axis self.default_graph_colors = it.cycle(self.default_graph_colors)
def construct(self): numberline = NumberLine(unit_size = 3) numberline.shift(2*UP) desc_R = TexMobject('\\mathfrak c=|\\mathbb R|') desc_R[-2].set_color(GREEN) desc_R.to_edge(RIGHT) desc_R.shift(2.6*UP) num_dot = Dot(numberline.number_to_point(-1.5)) num_desc = TexMobject("-1.5").next_to(num_dot, DOWN) num_desc.set_color(GREEN) self.add(numberline, desc_R, num_dot, num_desc) encoding = map(str, list(range(10))) + ['-', '.'] encoding = VGroup(*[ TextMobject("``$"+c+"$''","$\\to$", str(i)) for i,c in enumerate(encoding) ]) for rule in encoding: rule.shift(encoding[0][1].get_center()-rule[1].get_center()) encoding.arrange_submobjects(DOWN, coor_mask = UP) enc_part2 = VGroup(*encoding[6:]) enc_part2.shift(encoding[0][1].get_center() -enc_part2[0][1].get_center() + 3*RIGHT) encoding.to_corner(LEFT+DOWN) #self.add(encoding) representation_data = [10, 1, 11, 5] representation = VGroup(*[encoding[i][0].copy() for i in representation_data]) representation.arrange_submobjects(buff = 1) representation.to_corner(UP+LEFT) repr_body = VGroup(*[repr[1] for repr in representation]) repr_quotes = VGroup(*[VGroup(repr[0],repr[2]) for repr in representation]) self.wait_to(6.3) self.play(ReplacementTransform(num_desc.copy(), repr_body), FadeIn(repr_quotes)) self.wait_to(9.8) self.play(ShowCreation(VGroup(*[enc[0] for enc in encoding]))) self.wait_to(17.3) self.play(ShowCreation(VGroup(*[VGroup(enc[1], enc[2]) for enc in encoding]))) repr_num = VGroup(*[encoding[i][2].copy() for i in representation_data]) for num, char in zip(repr_num, repr_body): center = char.get_center() center[1] = repr_body[0].get_center()[1] num.move_to(center) self.play(FadeOut(repr_quotes), ReplacementTransform(repr_body, repr_num)) self.wait_to(22.5) repr_rect = SurroundingRectangle(repr_num, color = RED, buff = MED_SMALL_BUFF) self.play(ShowCreation(repr_rect)) self.wait_to(28) for i in range(2): self.play(Swap(repr_num[1], repr_num[3]), Swap(num_desc[1], num_desc[3])) if i == 0: self.wait_to(33.5) info = [] for i in range(1,4): cur_info = self.index_info(repr_num[i], 100*i+representation_data[i]) if i == 1: self.wait_to(46) elif i == 2: self.wait_to(48) elif i == 3: self.wait_to(50) self.play(FadeIn(cur_info)) info.append(cur_info) info = VGroup(*info) self.wait_to(53) self.play(*map(FadeOut, [repr_num, numberline, desc_R, info, repr_rect, num_dot, num_desc])) pi_str = "3.14159265358979323846265338327950288" pi_str_mobj = TexMobject(pi_str) pi_str_mobj.set_color(GREEN) pi_str_mobj.shift(1.5*UP+2*RIGHT) pi_str_mobj = VGroup(*[VGroup(c) for c in pi_str_mobj]) self.play(FadeIn(pi_str_mobj)) pi_num_list = [3, 111] + [200+100*i+int(c) for i,c in enumerate(pi_str[2:])] pi_num_list_mobj = VGroup(*[TexMobject(str(num)) for num in pi_num_list]) pi_num_list_mobj.arrange_submobjects(buff = 0.25) pi_rect = SurroundingRectangle(pi_num_list_mobj, color = RED, buff = MED_SMALL_BUFF) VGroup(pi_num_list_mobj, pi_rect).to_corner(LEFT+UP) self.wait_to(58) self.play(FadeIn(pi_rect), ReplacementTransform(pi_str_mobj.copy(), pi_num_list_mobj)) match_start = pi_str_mobj.get_edge_center(UP)+0.1*UP match_end = pi_rect.get_edge_center(DOWN) match_start[0] = match_end[0] = 0 match_line = Line(match_start, match_end, color = GREEN) self.wait_to(60 + 3.5) self.play(ShowCreation(match_line)) question = TexMobject("|", "\\mathbb R", "| = |", "\\mathcal P(\\omega)", "|?") question[1].highlight(GREEN) question[-2].highlight(RED) note = TextMobject("Jenom zkratka za\\\\ perfektní párování") q_point = encoding.get_corner(UP+RIGHT) q_point[0] = (q_point[0] + SPACE_WIDTH)/2 question.shift(q_point - question.get_edge_center(UP)) self.wait_to(60 + 27.5) self.play(Write(question)) arrow = Arrow(ORIGIN, UP) arrow.next_to(question[2][1], DOWN) note.next_to(arrow, DOWN) self.wait_to(60 + 39.5) self.play(ShowCreation(arrow), FadeIn(note)) self.wait_to(2*60 + 6)
def construct(self): desc_R = TexMobject('\\mathfrak c=|\\mathbb R|') desc_R[-2].set_color(GREEN) desc_R.to_edge(RIGHT) numberline = NumberLine(unit_size = 3) numberline.shift(2*UP) desc_R.shift(2.6*UP) self.play(ShowCreation(numberline), Write(desc_R[-2])) self.wait_to(14) self.play(Write(VGroup(*desc_R[:-2] + [desc_R[-1]]))) seq_len = 30 seq_data = [random.randint(0,1) for _ in range(seq_len)] set_el = VGroup(*[TexMobject(str(i)) for i in range(seq_len)]) for x, b in zip(set_el, seq_data): x.set_color([BLACK, WHITE][b]) set_el.arrange_submobjects(buff = 0.4) set_rect = SurroundingRectangle(set_el, color = RED, buff = MED_SMALL_BUFF) set_complet = VGroup(set_rect, set_el) set_complet.to_corner(LEFT+DOWN) self.wait_to(26) self.play(FadeIn(set_complet)) zero = TexMobject('0').set_color(DARK_GREY) one = TexMobject('1').set_color(GREEN) seq = VGroup(*[[zero, one][b].copy() for b in seq_data]) for (digit, num) in zip(seq, set_el): digit.move_to(num) seq.shift(2*UP) match_start = set_rect.get_edge_center(UP) match_end = seq.get_edge_center(DOWN)+0.1*DOWN match_start[0] = match_end[0] = 0 match_line = Line(match_start, match_end, color = RED) self.wait_to(28.5) self.play(ReplacementTransform(set_el.copy(), seq), ShowCreation(match_line)) num = seq_data[0]*.1 + seq_data[1]*.01 + seq_data[2]*.001 + seq_data[3]*.0001 num_dot = Dot(numberline.number_to_point(num)) zero_point = TexMobject("0.") zero_point.set_color(GREEN) num_seq = seq.copy() num_seq.highlight(GREEN) num_seq.arrange_submobjects(buff = 0.1) num_seq.next_to(num_dot, DOWN, aligned_edge = LEFT) match_line_dest = Line(match_start, num_seq.get_corner(LEFT+DOWN)+0.1*DOWN, color = RED) self.wait_to(38) self.play(ReplacementTransform(seq, num_seq), Transform(match_line, match_line_dest)) # 39 zero_point.next_to(num_seq, LEFT, buff = 0.1) self.dither() # 40 self.play(Write(zero_point), ShowCreation(num_dot)) self.wait_to(45) nats_and_arrows = [] for i,x in enumerate([-1.7, 1.2, num]): arrow_end = numberline.number_to_point(x) arrow = Arrow(arrow_end+UP, arrow_end) nat = TexMobject(str(i)) nat.next_to(arrow, UP) nats_and_arrows += [arrow, nat] self.play(ShowCreation(arrow), FadeIn(nat)) self.dither() nat_dest = nat.copy() nat_dest.next_to(match_end, UP) match_line_dest = Line(match_start, match_end, color = RED) self.wait_to(52) self.play(Transform(match_line, match_line_dest), ReplacementTransform(nat.copy(), nat_dest, path_arc = np.pi/2)) uncount = TexMobject("|\\mathbb R|\\geq", "|\\mathcal P(\\omega)| > \\aleph_0") uncount[0][1].set_color(GREEN) VGroup(*uncount[1][1:5]).set_color(RED) uncount.to_edge(RIGHT) self.wait_to(57.5) self.play(Write(uncount[1])) self.wait_to(60 + 1) self.play(Write(uncount[0])) strict_q = TexMobject("|\\mathbb R|>|\\mathcal P(\\omega)|?").to_edge(LEFT) strict_q[1].set_color(GREEN) VGroup(*strict_q[5:9]).set_color(RED) self.wait_to(60 + 13.5) self.play(Write(strict_q)) self.play(*map(FadeOut, nats_and_arrows+[match_line, nat_dest])) #brace = Brace(Line(*map(numberline.number_to_point, [0, 0.11111])), UP) #brace.shift(0.2*UP) #self.play(GrowFromCenter(brace)) #self.dither() simple_num_dot = Dot(numberline.number_to_point(-1.5)) simple_num_desc = TexMobject("-1.5").next_to(simple_num_dot, DOWN) simple_num_desc.set_color(GREEN) self.wait_to(60 + 30) self.play(*(map(FadeOut, [set_complet, strict_q, zero_point, num_seq, uncount]) + [FadeIn(simple_num_desc), Transform(num_dot, simple_num_dot)])) self.wait_to(60 + 36.5)