How to use wait_to method in Selene

Best Python code snippet using selene_python

set.py

Source:set.py Github

copy

Full Screen

...114 counted_pears = [Pear(i) for i in xrange(4)]115 counted_apple_group = Group(*counted_apples).arrange_submobjects().to_edge(UP)116 counted_pear_group = Group(*counted_pears).arrange_submobjects().to_edge(DOWN)117 apple_count = CountTransform(apples,counted_apple_group,direction=DOWN)118 self.wait_to(15.5)119 apple_count.play(self, run_time = 2.25)120 pear_count = CountTransform(pears,counted_pear_group,direction=UP)121 self.wait_to(20.5)122 pear_count.play(self, run_time = 1.8)123 self.wait_to(23.5)124 self.play(apple_count.summarize(),pear_count.summarize())125 inequality = TexMobject(126 apple_count.numbers[-1].args[0],127 ">",128 pear_count.numbers[-1].args[0]129 ).center()130 self.play(131 Transform(132 apple_count.numbers[-1],133 inequality.get_part_by_tex(apple_count.numbers[-1].args[0])134 ),135 Write(inequality.get_part_by_tex(">")),136 Transform(137 pear_count.numbers[-1],138 inequality.get_part_by_tex(pear_count.numbers[-1].args[0])139 )140 )141 self.wait_to(35)142 self.play(*map(FadeOut,[143 apple_count.numbers[-1],144 inequality,145 pear_count.numbers[-1]146 ]))147 # Show a matching148 matching = MatchingAnimations(Group(*apples),Group(*pears))149 self.wait_to(42)150 for anims in matching.match_animations:151 self.play(anims)152 self.wait_to(47.5)153 self.play(Transform(apples[-1],apples[-1].copy().center().to_edge(UP)))154 self.play(FocusOn2(apples[-1], highlight_color = WHITE))155 buff = matching.buff156 matching = matching.matching157 self.wait_to(53)158 for i in range(2):159 apples.submobjects.sort(key = lambda apple: apple.get_center()[0])160 apples_target = apples.copy()161 apples_target.arrange_submobjects(center = False, buff = buff)162 apples_target.shift(LEFT*apples_target.get_center()[0])163 self.play(Uncreate(matching))164 self.play(Transform(apples, apples_target))165 if i == 0: self.wait_to(55.5)166 #self.dither()167 # Permute them168 apple_permutations=permute_animations(apples,move="up")169 pear_permutations=permute_animations(pears,move="down")170 self.play(*(apple_permutations + pear_permutations))171 # Show a different matching172 permuted_apples = permute(apples)173 permuted_pears = permute(pears)174 if i == 1: permuted_apples[0], permuted_apples[-1] = permuted_apples[-1], permuted_apples[0]175 matching = get_matching(Group(*permuted_pears), Group(*permuted_apples))176 self.play(ShowCreation(matching))177 #self.dither()178 if i == 0: self.wait_to(60)179 self.play(Transform(permuted_apples[-1],permuted_apples[-1].copy().center().to_edge(UP)))180 self.play(FocusOn2(permuted_apples[-1], highlight_color = WHITE))181 subtraction = TexMobject("5-4=1")182 subtraction[0].set_color(RED)183 subtraction[2].set_color(YELLOW)184 subtraction[4].set_color(RED)185 subtraction.to_edge(RIGHT)186 self.wait_to(73)187 self.play(Write(subtraction))188 self.wait_to(84)189 self.play(FadeOut(VGroup(matching, subtraction, *permuted_apples+permuted_pears)))190def number_submobjects(mobj,direction):191 zero = TexMobject("0")192 zero.next_to(mobj.submobjects[0],direction=direction)193 submobjs = [zero]194 for i in xrange(1,len(mobj.submobjects)):195 submobj = TexMobject(str(i))196 submobj.next_to(submobjs[-1])197 submobj.shift((mobj.submobjects[i].get_center()[0]-submobj.get_center()[0],0,0))198 submobjs.append(submobj)199 return Group(*submobjs)200class InfiniteFruitScene(Scene):201 def construct(self):202 #self.force_skipping()203 self.fruit_num = 101204 apples = Group(*(Apple() for _ in xrange(self.fruit_num)))205 apples.arrange_submobjects(buff = 0.5)206 apples.to_edge(LEFT, buff = 2.5)207 pears = Group(*(208 Pear() for _ in xrange(self.fruit_num)209 ))210 for apple, pear in zip(apples, pears):211 pear.move_to(apple)212 apples.shift(1.5*UP)213 pears.shift(1.5*DOWN)214 apple_numbers = number_submobjects(apples,direction=UP)215 pear_numbers = number_submobjects(pears,direction=DOWN)216 self.play(ShowCreation(apples),Write(apple_numbers))217 self.wait_to(5.5)218 self.play(ShowCreation(pears),Write(pear_numbers))219 #self.dither()220 apples.submobjects.reverse()221 pears.submobjects.reverse()222 apple_numbers.submobjects.reverse()223 pear_numbers.submobjects.reverse()224 apples_ori = apples.copy()225 pears_ori = pears.copy()226 apple_numbers_ori = apple_numbers.copy()227 pear_numbers_ori = pear_numbers.copy()228 apples_persp = apples.copy()229 pears_persp = pears.copy()230 apple_numbers_persp = apple_numbers.copy()231 pear_numbers_persp = pear_numbers.copy()232 self.camera_distance = 12.0233 self.camera_point = apples[-1].get_center() * X_MASK234 vanishing_point = self.camera_point + self.camera_distance*RIGHT235 self.darken(apples_persp)236 self.darken(pears_persp)237 self.darken(apple_numbers_persp)238 self.darken(pear_numbers_persp)239 # perspective shift of numbers240 self.apply_perspective(apples_persp, objectwise = True)241 self.apply_perspective(pears_persp, objectwise = True)242 self.apply_perspective(apple_numbers_persp, objectwise = False)243 self.apply_perspective(pear_numbers_persp, objectwise = False)244 self.wait_to(10)245 self.play(246 ReplacementTransform(apples, apples_persp),247 ReplacementTransform(pears, pears_persp),248 ReplacementTransform(apple_numbers, apple_numbers_persp),249 ReplacementTransform(pear_numbers, pear_numbers_persp),250 )251 apples = apples_persp252 pears = pears_persp253 apple_numbers = apple_numbers_persp254 pear_numbers = pear_numbers_persp255 #self.dither()256 matching = make_ordinal_matching(257 Ordinal(*apples[1:]),258 Ordinal(*pears[1:]),259 )260 self.darken(matching)261 self.wait_to(13)262 self.play(ShowCreation(matching))263 matching_straight = matching.copy()264 # Extra apple265 self.show_extra_fruit(apples, apples_ori, apple_numbers, apple_numbers_ori,266 matching, apples[:-1], pears[1:], matching_straight)267 # Extra pear268 self.show_extra_fruit(pears, pears_ori, pear_numbers, pear_numbers_ori,269 matching, apples[1:], pears[:-1], matching_straight,270 brief = True)271 self.play(Transform(matching, matching_straight)) # 44272 definition = TextMobject("Definition:","$|A| = |B|$")273 definition.to_edge(UP)274 self.play(Write(definition[0]))275 self.wait_to(47)276 apple_box, apple_label = self.pack_into_box(apples, apple_numbers, UP, 'A', RED,277 matching, apples, pears)278 #self.dither()279 pear_box, pear_label = self.pack_into_box(pears, pear_numbers, DOWN, 'B', YELLOW,280 matching, apples, pears)281 #self.dither()282 self.wait_to(59)283 self.move_labels_to_definition(apple_label, pear_label, definition[1])284 finite_pears = VGroup(*pears_ori[-3:])285 finite_pears.move_to(pear_box)286 pears_dest = VGroup(*[287 pears[0].copy()288 for _ in range(len(pears)-3)289 ])290 pears_dest.fade(0)291 pears_dest.add(*finite_pears.submobjects)292 self.wait_to(60+20.5)293 self.play(294 Uncreate(matching),295 FadeOut(definition[1]),296 ) # 1:21.5297 self.play(298 Transform(pears, pears_dest),299 ) # 1:22.5300 self.remove(pears)301 self.add(finite_pears)302 finite_pears.submobjects.reverse()303 pears = finite_pears304 #self.dither()305 def attempt(i0, i1, i2, remove = True):306 apple_indices = i0, i1, i2307 matching = get_matching(308 pears,309 Group(*(apples.submobjects[-1-i] for i in apple_indices))310 )311 self.play(ShowCreation(matching), submobject_mode = "all_at_once")312 #self.dither()313 if remove: self.remove(matching)314 else: return matching315 self.wait_to(60 + 25.5)316 attempt(5,8,12)317 attempt(0,10,19)318 matching = attempt(7,1,0, remove = False)319 def2 = TextMobject(":","$|A|>|B|$")320 def2.shift(definition[0][-1].get_center() - def2[0].get_center())321 self.wait_to(60 + 30)322 self.move_labels_to_definition(apple_label, pear_label, def2[1])323 self.wait_to(60 + 38.5)324 def perspective_ratio(self, point):325 return self.camera_distance / (self.camera_distance + point[0])326 def apply_perspective(self, mob, objectwise = True):327 if isinstance(mob, list): mob = VGroup(*mob)328 mob.shift(-self.camera_point)329 if objectwise:330 for submob in mob:331 ratio = self.perspective_ratio(submob.get_center())332 submob.scale(ratio)333 submob.set_stroke(width = ratio*submob.stroke_width)334 else:335 def perspective_shift(point):336 return point * self.perspective_ratio(point)337 for submob in mob.family_members_with_points():338 submob.points = np.apply_along_axis(perspective_shift, 1, submob.points)339 mob.shift(self.camera_point)340 def darken(self, row):341 for i, el in enumerate(reversed(row)):342 darkness = float(i)/(self.fruit_num-1)343 #print i, darkness344 el.fade(darkness)345 def show_extra_fruit(self, fruits, fruits_ori, fruit_numbers, fruit_numbers_ori,346 matching, m1, m2, matching_straight, brief = False):347 matching_shifted = make_ordinal_matching(348 Ordinal(*m1), Ordinal(*m2),349 )350 self.darken(matching_shifted)351 if not brief: self.wait_to(18.7)352 self.play(Transform(matching, matching_shifted))353 if not brief:354 self.wait_to(20.8)355 self.play(FocusOn2(m2[-1], highlight_color = WHITE))356 self.play(FocusOn2(m1[-1], highlight_color = WHITE))357 self.wait_to(23.4)358 self.play(FocusOn2(m2[-2], highlight_color = WHITE), run_time = 0.7)359 self.play(FocusOn2(m1[-2], highlight_color = WHITE))360 fruits_shifted = fruits_ori.copy()361 fruit_numbers_shifted = fruit_numbers_ori.copy()362 shift = fruits_shifted[-1].get_center() - fruits_shifted[-2].get_center()363 extra_fruit = []364 for row, objectwise in [(fruits_shifted, True), (fruit_numbers_shifted, False)]:365 row.shift(shift)366 extra_fruit += row[-1]367 persp_row = row[:-1]368 self.darken(persp_row)369 self.apply_perspective(persp_row, objectwise)370 extra_fruit = VGroup(*extra_fruit)371 extra_fruit.center()372 extra_fruit.to_edge(LEFT)373 fruits.save_state()374 fruit_numbers.save_state()375 if not brief: self.wait_to(27)376 self.play(377 Transform(fruits, fruits_shifted),378 Transform(fruit_numbers, fruit_numbers_shifted),379 Transform(matching, matching_straight),380 ) # 28381 self.play(FocusOn2(fruits[-1], highlight_color = WHITE))382 if not brief: self.wait_to(33.5)383 else: self.wait_to(41)384 self.play(385 fruits.restore,386 fruit_numbers.restore,387 Transform(matching, matching_shifted),388 )389 #self.dither()390 def pack_into_box(self, fruits, numbers, shift_dir, set_name, color,391 matching, m1, m2):392 fruits_dest = fruits.copy()393 fruits_dest.shift(0.2*shift_dir)394 if m1 == fruits: m1 = fruits_dest395 if m2 == fruits: m2 = fruits_dest396 matching_dest = make_ordinal_matching(397 Ordinal(*m1[1:]),398 Ordinal(*m2[1:]),399 )400 self.darken(matching_dest)401 box = SurroundingRectangle(fruits_dest, color=color)402 label = TexMobject(set_name)403 label.set_color(color)404 label.next_to(box,direction=LEFT, buff=0.5)405 self.play(406 FadeOut(numbers),407 Transform(fruits, fruits_dest),408 Transform(matching, matching_dest),409 ShowCreation(box),410 Write(label)411 )412 self.add_foreground_mobjects(box)413 return box, label414 def move_labels_to_definition(self, apple_label, pear_label, definition):415 apple_label_dest = definition[1]416 pear_label_dest = definition[-2]417 apple_label_dest.set_color(RED)418 pear_label_dest.set_color(YELLOW)419 self.play(420 ReplacementTransform(apple_label[0].copy(), apple_label_dest),421 ReplacementTransform(pear_label[0].copy(), pear_label_dest),422 )423 definition_remaining = copy.copy(definition)424 definition_remaining.submobjects = copy.copy(definition_remaining.submobjects)425 definition_remaining.remove(apple_label_dest, pear_label_dest)426 self.play(Write(definition_remaining))427 self.dither()428 429class NaturalsSubsets(Scene):430 def construct(self):431 self.numbers = Group(*(self.number_tex(i) for i in xrange(15)))432 self.number_text = TextMobject("Natural Numbers").to_edge(UP)433 self.play(ShowCreation(self.numbers),Write(self.number_text))434 self.wait_to(4)435 self.show_matching(lambda n: 2*n, "Even", gradual_creation = True)436 self.dither()437 to_remove = self.show_matching(lambda n: n ** 2, "Square", end_mode = 'keep')438 self.wait_to(45)439 self.remove(to_remove)440 small_primes = [441 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,442 71,73,79,83,89,97,101,103,107,109,113443 ]444 self.show_matching(small_primes, "Prime", end_mode = 'keep')445 self.wait_to(54)446 def number_pos(self, number, direction = UP):447 return LEFT_SIDE + (1.3*number + 2)*RIGHT + direction448 def number_tex(self, i):449 mobj = TexMobject(str(i))450 mobj.move_to(self.number_pos(i))451 mobj.number = i452 return mobj453 def cardinality_tex(self, number_type):454 result = TexMobject("|","\\text{Natural Numbers}","|=|","\\text{" + number_type + " Numbers}","|").to_edge(UP)455 result[-2].set_color(RED)456 return result457 def show_matching(self, subset, set_description, gradual_creation = False, end_mode = 'uncreate'):458 if callable(subset):459 subset = [subset(i) for i in range(len(self.numbers))]460 subset = VGroup(*[self.number_tex(i) for i in subset])461 # shift down462 subset_dest = subset.copy()463 for num in subset_dest: num.move_to(self.number_pos(num.number, DOWN))464 self.play(Transform(subset, subset_dest))465 # compactize466 subset_dest = subset.copy()467 subset_dest.highlight(RED)468 for i, num in enumerate(subset_dest): num.move_to(self.number_pos(i, DOWN))469 if gradual_creation: self.wait_to(14)470 self.play(Transform(subset, subset_dest))471 matching = get_matching(subset, self.numbers)472 matching.stretch(-1, 1)473 number_text_dest = self.cardinality_tex(set_description)474 if gradual_creation:475 self.wait_to(21.7)476 for i in range(3):477 self.play(ShowCreation(matching[i]))478 self.play(ShowCreation(VGroup(*matching[i+1:])))479 self.wait_to(28)480 self.play(ReplacementTransform(self.number_text, number_text_dest))481 else:482 self.play(483 ShowCreation(matching),484 ReplacementTransform(self.number_text, number_text_dest),485 )486 self.number_text = number_text_dest487 if gradual_creation: self.wait_to(40)488 if end_mode == 'uncreate': self.play(Uncreate(matching),Uncreate(subset))489 elif end_mode == 'remove': self.remove(matching, subset)490 elif end_mode == 'keep': return VGroup(matching, subset)491class NotationScene(Scene):492 def construct(self):493 self.prepare_overall_picture()494 numbers = VGroup(*(TexMobject(str(i)) for i in xrange(15)))495 for i, num in enumerate(numbers): num.move_to(i*RIGHT)496 aleph0_brace = Brace(numbers, UP)497 aleph0_brace.highlight(GREEN)498 VGroup(aleph0_brace, numbers).shift(self.sizes[1].get_edge_center(DOWN) + 0.2*DOWN499 - aleph0_brace.get_tip())500 self.play(Write(self.title))501 self.wait_to(2.5)502 self.play(self.finite_brace.creation_anim())503 self.wait_to(7)504 self.play(Write(self.sizes[0]))505 self.wait_to(10.3)506 self.play(Write(self.subtitle))507 self.wait_to(16.5)508 self.play(self.infinite_brace.creation_anim())509 self.wait_to(18)510 self.play(FadeIn(numbers), GrowFromCenter(aleph0_brace))511 self.wait_to(22.5)512 self.play(ReplacementTransform(aleph0_brace.copy(), self.sizes[1]))513 def number_pos(n):514 return numbers[0].get_center() + n*(numbers[1].get_center() - numbers[0].get_center())515 subset = VGroup(*(TexMobject(str(2*n)) for n in xrange(15)))516 for n, mob in enumerate(subset): mob.move_to(number_pos(2*n))517 subset2 = subset.copy()518 subset3 = subset2.copy()519 for n, mob in enumerate(subset3): mob.move_to(number_pos(n))520 VGroup(subset2, subset3).shift(DOWN)521 subset3.highlight(RED)522 self.wait_to(42)523 self.play(Transform(subset, subset2))524 self.play(Transform(subset, subset3))525 self.wait_to(47.5)526 self.play(FocusOn2(self.sizes[1][1]))527 self.wait_to(49)528 self.play(FadeOut(VGroup(subset, numbers, aleph0_brace)))529 self.play(self.countable_brace.creation_anim())530 self.wait_to(66.5)531 def prepare_overall_picture(self):532 self.title = TextMobject("Notation").scale(1.3).to_edge(UP)533 self.subtitle = TextMobject("Cardinal Numbers").next_to(self.title, DOWN, buff = 0.5)534 self.sizes = TexMobject("0,1,2,\ldots", "\\aleph_0")535 self.sizes.highlight(GREEN)536 self.sizes.shift(DOWN)537 sizes0_ori = self.sizes[0].copy()538 self.sizes[0].shift(3*LEFT)539 sizes1_behind = self.sizes[1].copy()540 sizes1_behind.behind_edge(RIGHT)541 sizes1_next = self.sizes[0].copy()542 sizes1_next.next_to(543 self.sizes[1],544 buff = (self.sizes[1].get_edge_center(LEFT) - sizes0_ori.get_edge_center(RIGHT))[0],545 coor_mask = X_MASK,546 )547 self.finite_brace = BraceText(VGroup(self.sizes[0], sizes0_ori), "finite sizes", UP)548 self.infinite_brace = BraceText(VGroup(self.sizes[1], sizes1_behind), "infinite sizes", UP)549 self.countable_brace = BraceText(self.sizes, "countable sizes", DOWN)550 self.uncountable_brace = BraceText(VGroup(sizes1_next, sizes1_behind), "uncountable sizes", DOWN)551 self.uncountable_brace.desc.shift(0.5*LEFT)552 self.overall_picture = VGroup(553 self.sizes,554 self.finite_brace, self.infinite_brace,555 self.countable_brace, self.uncountable_brace,556 )557class InftyPlusInfty(Scene):558 def construct(self):559 #self.force_skipping()560 self.make_numbers()561 self.numbers.to_corner(UP+LEFT)562 even, even_ori, even_spaced, even_arranged = self.make_subset(lambda n: 2*n, 2)563 odd, odd_ori, odd_spaced, odd_arranged = self.make_subset(lambda n: 2*n+1, 3)564 self.add(self.numbers)565 self.play(Transform(even, even_spaced))566 VGroup(even_ori, even_spaced, even_arranged).highlight(RED)567 self.play(Transform(even, even_arranged))568 self.wait_to(15)569 self.play(Transform(odd, odd_spaced))570 VGroup(odd_ori, odd_spaced, odd_arranged).highlight(YELLOW)571 self.play(Transform(odd, odd_arranged))572 brace = BraceDesc(odd, "\\aleph_0")573 self.play(brace.creation_anim())574 self.wait_to(21.5)575 self.play(576 Transform(even, even_spaced),577 Transform(odd, odd_spaced),578 )579 self.play(580 Transform(even, even_ori),581 Transform(odd, odd_ori),582 )583 self.remove(self.numbers)584 self.wait_to(28.5)585 self.play(586 Transform(even, even_spaced),587 Transform(odd, odd_spaced),588 )589 self.play(590 Transform(even, even_arranged),591 Transform(odd, odd_arranged),592 )593 even_abstr = VGroup(*[Dot(num.get_center(), color = RED) for num in even])594 odd_abstr = VGroup(*[Dot(num.get_center(), color = YELLOW) for num in odd])595 self.wait_to(32)596 self.play(597 Transform(even, even_abstr),598 Transform(odd, odd_abstr),599 )600 apples_shrinked, apples, apples_spaced, apples_in_set \601 = self.make_fruit_set(Apple().scale(0.6),602 even_arranged, even_spaced, even_ori)603 pears_shrinked, pears, pears_spaced, pears_in_set \604 = self.make_fruit_set(Pear().scale(0.6),605 odd_arranged, odd_spaced, odd_ori)606 self.wait_to(47)607 self.play(608 ReplacementTransform(apples_shrinked, apples),609 ReplacementTransform(pears_shrinked, pears),610 )611 self.remove(even, odd)612 self.wait_to(53.7)613 self.play(614 Transform(apples, apples_spaced),615 Transform(pears, pears_spaced),616 )617 self.play(618 Transform(apples, apples_in_set),619 Transform(pears, pears_in_set),620 )621 sum_formula = TexMobject('\\aleph_0','+','\\aleph_0',"=\\aleph_0")622 sum_formula[0].highlight(RED)623 sum_formula[2].highlight(YELLOW)624 sum_formula.shift(BOTTOM/2)625 self.wait_to(57.5)626 self.play(Write(sum_formula))627 self.wait_to(70)628 self.play(FadeOut(VGroup(sum_formula, apples, pears, brace)))629 def make_numbers(self, num_num = 15):630 self.numbers = VGroup(*(TexMobject(str(i)) for i in xrange(num_num)))631 for i, num in enumerate(self.numbers): num.move_to(i*RIGHT)632 def make_subset(self, subset, down_shift):633 if callable(subset):634 subset = [subset(n) for n in range(len(self.numbers))]635 subset = VGroup(*[self.number_tex(n) for n in subset])636 subset_ori = subset.copy()637 subset_spaced = subset.copy()638 subset_arranged = subset.copy()639 for i, num in enumerate(subset_arranged): num.move_to(self.number_pos(i))640 VGroup(subset_spaced, subset_arranged).shift(down_shift * DOWN)641 return subset, subset_ori, subset_spaced, subset_arranged642 def number_pos(self, n):643 return self.numbers[0].get_center() + n*(self.numbers[1].get_center()644 - self.numbers[0].get_center())645 def number_tex(self, n):646 return TexMobject(str(n)).move_to(self.number_pos(n))647 def make_fruit_set(self, fruit_example, num_arranged, num_spaced, num_ori):648 fruits = VGroup(*[649 fruit_example.copy().move_to(num.get_center())650 for num in num_arranged651 ])652 shrinked = fruits.copy()653 spaced = fruits.copy()654 in_set = fruits.copy()655 for fruit in shrinked:656 fruit.scale_in_place(0)657 fruit.highlight(num_arranged.fill_color)658 for fruit, num in zip(spaced, num_spaced): fruit.move_to(num)659 for fruit, num in zip(in_set, num_ori): fruit.move_to(num)660 return shrinked, fruits, spaced, in_set661class IntegersScene(Scene):662 def construct(self):663 negatives = VGroup(*[664 self.number_tex(-n) for n in range(9)665 ])666 positives = VGroup(*[667 self.number_tex(n) for n in range(9)668 ])669 negatives.shift(UP)670 neg_brace = BraceDesc(negatives, "\\aleph_0", UP)671 pos_brace = BraceDesc(positives, "\\aleph_0", DOWN)672 self.play(ShowCreation(negatives))673 self.wait_to(6)674 self.play(neg_brace.creation_anim())675 self.wait_to(12)676 self.play(ShowCreation(positives))677 self.play(pos_brace.creation_anim())678 self.wait_to(15)679 self.play(680 positives.shift, UP,681 pos_brace.shift, UP,682 )683 self.wait_to(17)684 self.remove(positives[0])685 self.play(686 FadeOut(pos_brace),687 neg_brace.shift_brace, VGroup(negatives, negatives[-1].copy().move_to(positives[-1])),688 )689 self.wait_to(19)690 conversation = Conversation(self)691 conversation.add_bubble("Hey, what happened to the merged zero?")692 self.wait_to(24.5)693 conversation.add_bubble("The size is still countable infinite.")694 self.wait_to(32)695 def number_tex(self, n):696 return TexMobject(str(n)).move_to(n*RIGHT)697class InfiniteTable(InftyPlusInfty):698 def construct(self):699 #self.force_skipping()700 self.cur_color = WHITE701 self.number_mul = 1702 self.make_numbers(num_num = 14)703 self.numbers.to_corner(UP+LEFT)704 self.numbers.shift(1.5*RIGHT)705 self.add(self.numbers)706 even, _, even_spaced, even_arranged = self.make_subset(lambda n: 2*n, 3)707 odd, _, odd_spaced, odd_arranged = self.make_subset(lambda n: 2*n+1, 2)708 odd_arranged.highlight(YELLOW)709 even_arranged.highlight(RED)710 self.play(711 Transform(even, even_spaced),712 Transform(odd, odd_spaced),713 )714 self.wait_to(7)715 self.play(716 Transform(even, even_arranged),717 Transform(odd, odd_arranged),718 )719 colors = color_gradient([YELLOW, GREEN, BLUE], 6)720 ori_numbers = self.numbers721 self.numbers = even722 self.number_mul = 2723 self.cur_color = RED724 table = [odd]725 self.wait_to(10)726 for index, color in enumerate(colors[1:]):727 if index <= 2: run_time = 1728 else: run_time = 0.5729 subodd, _, _, subodd_arranged \730 = self.make_subset(lambda n: 2*n+1, 0)731 table += [subodd]732 subeven, _, subeven_spaced, subeven_arranged \733 = self.make_subset(lambda n: 2*n, 1)734 self.remove(self.numbers)735 self.add(subodd, subeven)736 subodd_arranged.highlight(color)737 self.play(Transform(subeven, subeven_spaced), run_time = run_time)738 self.play(739 Transform(subeven, subeven_arranged),740 Transform(subodd, subodd_arranged),741 run_time = run_time,742 )743 if index == 0: self.wait_to(16.5)744 self.number_mul *= 2745 self.numbers = subeven746 missing_zero = ori_numbers[0].copy().highlight(RED)747 self.wait_to(30)748 self.play(Write(missing_zero))749 self.remove(ori_numbers[0])750 ori_numbers.save_state()751 ori_numbers.remove(ori_numbers[0])752 self.wait_to(31.5)753 self.play(missing_zero.behind_edge, DOWN)754 h_brace = BraceDesc(odd, "\\aleph_0", UP)755 h_brace.desc.highlight(YELLOW)756 v_brace = BraceDesc(VGroup(odd, subeven), "\\aleph_0", LEFT)757 v_brace.desc.highlight(BLUE)758 v_brace.shift(0.2*LEFT)759 self.wait_to(35.8)760 self.play(761 FadeOut(ori_numbers),762 h_brace.creation_anim(),763 )764 self.wait_to(38.5)765 self.play(v_brace.creation_anim())766 prod_formula = TexMobject("\\aleph_0","\\cdot","\\aleph_0"," = \\aleph_0")767 prod_formula[0].highlight(BLUE)768 prod_formula[2].highlight(YELLOW)769 prod_formula.to_corner(LEFT+UP)770 self.wait_to(48.4)771 self.play(772 ReplacementTransform(v_brace.desc[0].copy(), prod_formula[0]),773 ReplacementTransform(h_brace.desc[0].copy(), prod_formula[2]),774 )775 self.play(Write(VGroup(prod_formula[1], prod_formula[3])))776 table_but_first_column = VGroup(*[VGroup(*row[1:]) for row in table])777 self.wait_to(60 + 3.5)778 self.play(779 FadeOut(VGroup(h_brace, v_brace, prod_formula)),780 table_but_first_column.set_fill, None, 0.4,781 )782 formula_r_ori = None783 self.wait_to(60 + 7.3)784 for i, row in enumerate(table[:4]):785 formula_r = TexMobject("2^{"+str(i)+"}=")786 formula_r.highlight(rgb_to_color(row[0].family_members_with_points()[0].fill_rgb))787 formula_r.next_to(row[0], LEFT, buff = 0.3, aligned_edge = DOWN)788 if formula_r_ori is None: self.play(Write(formula_r), run_time = 1.4)789 else: self.play(ReplacementTransform(formula_r_ori, formula_r), run_time = 0.5)790 formula_r_ori = formula_r791 formula_r = TexMobject("2^r=")792 formula_r.shift(formula_r_ori[0].get_center() - formula_r[0].get_center())793 formula_r.highlight(BLUE)794 formula_r[-1].set_fill(opacity = 0)795 formula_r.to_edge(DOWN)796 self.wait_to(60 + 11.5)797 self.play(ReplacementTransform(formula_r_ori, formula_r))798 self.wait_to(60 + 17)799 self.play(table_but_first_column.set_fill, None, 1)800 table_but_first_row = VGroup(*table[1:])801 self.play(table_but_first_row.set_fill, None, 0.4)802 formula_c = TexMobject("(2c+1)")803 formula_c.to_edge(UP)804 formula_c.highlight(YELLOW)805 self.wait_to(60 + 22)806 self.play(Write(formula_c))807 self.wait_to(60 + 28.5)808 self.play(table_but_first_row.set_fill, None, 1)809 show_r = 3810 show_c = 5811 show_circ = Circle(radius = 0.45)812 show_circ.highlight(GREEN)813 show_circ.move_to(table[show_r][show_c])814 show_r_circ = show_circ.copy()815 show_r_circ.move_to(table[show_r][0], coor_mask = X_MASK)816 show_r_circ.highlight(BLUE)817 show_c_circ = show_circ.copy()818 show_c_circ.move_to(table[0][show_c], coor_mask = Y_MASK)819 show_c_circ.highlight(YELLOW)820 self.play(ShowCreation(show_circ))821 self.wait_to(60 + 32.5)822 self.play(ShowCreation(show_c_circ))823 self.play(ShowCreation(show_r_circ))824 formula_prod = TexMobject("2^r",'\\cdot',"(2c+1)", "-1")825 formula_prod.to_corner(UP+LEFT)826 formula_prod[0].highlight(BLUE)827 formula_prod[2].highlight(YELLOW)828 self.dither()829 self.play(830 FadeIn(formula_prod[1]),831 ReplacementTransform(formula_r.copy(), formula_prod[0]),832 ReplacementTransform(formula_c.copy(), formula_prod[2]),833 )834 self.wait_to(60 + 42)835 self.play(FadeOut(VGroup(formula_r, formula_c, show_circ, show_c_circ, show_r_circ)))836 pairs_table = VGroup(*[837 VGroup(*[838 self.pair_tex(r, c, mob)839 for c, mob in enumerate(row)840 ])841 for r, row in enumerate(table)842 ])843 table = VGroup(*table)844 for row in table:845 for num in row:846 num.submobjects = [VGroup(digit) for digit in num.submobjects]847 #self.revert_to_original_skipping_status()848 #self.wait_to(60 + 48)849 self.play(ReplacementTransform(table, pairs_table))850 self.wait_to(60 + 46.7)851 h_shift = RIGHT*(table[0][1].get_center() - table[0][0].get_center())852 table = pairs_table853 table_dest = table.copy()854 for r, row in enumerate(table_dest):855 for c, num in enumerate(row):856 num.shift(h_shift * ((2**r)*(2*c+1)-1 -c))857 self.play(Transform(table, table_dest))858 table_dest = table.copy()859 for row in table_dest:860 for num in row: num.move_to(2*DOWN, coor_mask = Y_MASK)861 self.play(Transform(table, table_dest))862 self.wait_to(60 + 49.7)863 pairs_row = VGroup(*it.chain(*table))864 pairs_row.submobjects.sort(key = lambda mob: mob.get_center()[0])865 ori_numbers.restore()866 ori_numbers.shift(pairs_row[0].get_center() - ori_numbers[1].get_center())867 ori_numbers.shift(2*UP)868 self.add(ori_numbers)869 matching = VGroup(*[870 Line(num.get_edge_center(DOWN), pair.get_edge_center(UP), buff = 0.2)871 for num, pair in zip(ori_numbers[1:], pairs_row)872 ])873 self.play(874 ShowCreation(ori_numbers),875 ShowCreation(matching),876 )877 matching.add(matching[-1].copy())878 matching[-1].shift(h_shift)879 general_pair = TexMobject("r,c")880 general_pair[0].highlight(BLUE)881 general_pair[2].highlight(YELLOW)882 visible_formula_prod = VGroup(*formula_prod[:3])883 general_pair.move_to(visible_formula_prod)884 general_pair.shift(2*DOWN)885 general_matching = Line(general_pair.get_edge_center(UP),886 visible_formula_prod.get_edge_center(DOWN),887 buff = 0.2)888 self.wait_to(60 + 55.5)889 self.play(FadeIn(general_pair))890 self.play(ShowCreation(general_matching))891 self.wait_to(2*60 + 2)892 self.play(Write(formula_prod[-1]))893 self.play(VGroup(matching, pairs_row).shift, -h_shift)894 self.wait_to(2*60 + 19)895 def number_tex(self, n):896 result = TexMobject(str(n*self.number_mul))897 result.move_to(self.number_pos(n))898 if n*self.number_mul >= 100: result.scale_in_place(0.7)899 result.highlight(self.cur_color)900 return result901 def pair_tex(self, r, c, position):902 result = TexMobject(str(r),'{,}',str(c))903 result[0].highlight(BLUE)904 result[2].highlight(YELLOW)905 if c < 10: result.scale(0.8)906 else: result.scale(0.7)907 result.move_to(position)908 return result909class RationalsScene(NotationScene):910 def construct(self):911 self.h_space = 2912 self.colors = color_gradient([YELLOW, GREEN, BLUE, DARK_BLUE, DARK_GRAY], 20)913 numbers = self.make_numbers()914 self.play(915 ShowCreation(numbers[0]),916 ShowCreation(numbers[1]),917 )918 brace = BraceDesc(numbers[0], "\\aleph_0", DOWN)919 brace.next_to(numbers[1], DOWN, coor_mask = Y_MASK, buff = 0.3)920 self.wait_to(4.5)921 self.play(brace.creation_anim())922 skip = False923 denominator = 2924 parts = []925 while True:926 if denominator < 4: run_time = 1927 else: run_time = 0.5928 parts.append(numbers[0].copy())929 if denominator == 2: self.wait_to(8.25)930 elif denominator == 3: self.wait_to(12.3)931 self.add(parts[-1])932 self.play(VGroup(numbers, brace).shift, 0.9*DOWN, run_time = run_time)933 if denominator == 2: self.wait_to(9.8)934 #elif denominator == 3: self.wait_to(13.6)935 self.remove(numbers)936 if denominator == 6: break937 numbers = self.make_numbers(denominator, numbers)938 ori_numbers = self.make_numbers(denominator-1, numbers)939 if skip:940 offset = (len(ori_numbers[1])//2+1) %2941 for label in ori_numbers[1][offset::2]:942 label.set_fill(opacity = 0)943 if denominator == 4: skip = True944 if skip:945 offset = (len(numbers[1])//2+1) %2946 for label in numbers[1][offset::2]:947 label.set_fill(opacity = 0)948 self.play(ReplacementTransform(ori_numbers, numbers), run_time = run_time)949 denominator += 1950 self.remove(brace, numbers)951 while denominator < len(self.colors)+1:952 part = self.make_dots(denominator)953 part.move_to(parts[-1])954 part.shift(0.5*DOWN)955 parts.append(part)956 denominator += 1957 parts.reverse()958 parts = VGroup(*parts)959 parts_dest = parts.copy()960 for part in parts_dest: part.center()961 print("CURRENT TIME", self.current_scene_time)962 self.wait_to(17.5)963 self.play(Transform(parts, parts_dest), run_time = 2)964 rationals = TexMobject('|',"\\text{Rational Numbers}","| = \\aleph_0")965 rationals.shift(0.5*DOWN - rationals[1].get_edge_center(UP))966 self.wait_to(22)967 self.play(Write(rationals[1]))968 dots7 = self.make_dots(7)969 dots7.shift(2*DOWN)970 center = len(dots7)//2971 pi_dot = dots7[center+22]972 pi_label = TexMobject("\\frac{22}{7}")973 pi_label.next_to(pi_dot, DOWN)974 self.wait_to(25.8)975 self.play(Write(pi_label))976 self.wait_to(28.7)977 self.play(ShowCreation(dots7))978 self.play(FocusOn2(pi_dot, scale = 3))979 dots7.remove(pi_dot)980 self.play(FadeOut(dots7))981 self.play(VGroup(pi_dot, pi_label).shift, 2*UP)982 self.wait_to(33)983 self.play(FadeOut(VGroup(pi_dot, pi_label)))984 self.play(Write(VGroup(rationals[0], rationals[2])))985 self.wait_to(48.5)986 conversation1 = Conversation(self)987 conversation1.add_bubble("Are all sets countable?")988 self.wait_to(54)989 conversation2 = Conversation(self, start_answer = True)990 conversation2.add_bubble("Of course not ;-)")991 self.prepare_overall_picture()992 self.overall_picture.to_edge(UP, buff = 0.4)993 self.overall_picture.remove(self.uncountable_brace)994 self.wait_to(60 + 1)995 self.play(FadeIn(self.overall_picture))996 self.wait_to(60 + 3.3)997 self.play(self.uncountable_brace.creation_anim())998 self.wait_to(60 + 11)999 real_size = TexMobject("|\\mathbb R|")1000 real_size.set_color(GREEN)1001 real_size.next_to(self.sizes, buff = 1)1002 self.play(Write(real_size))1003 self.wait_to(60 + 29.5)1004 def make_numbers(self, denominator = 1, template = None):1005 if template is not None:1006 min_num = len(template[0])//21007 else: min_num = 01008 dots = self.make_dots(denominator, min_num)1009 max_num = len(dots)//21010 labels = []1011 for n, dot in zip(range(-max_num, max_num+1), dots):1012 if denominator == 1:1013 tex = str(n)1014 else:1015 tex = "\\textstyle\\frac{"+str(n)+"}{"+str(denominator)+"}"1016 label = TexMobject(tex)1017 label.next_to(dot, DOWN)1018 labels.append(label)1019 labels = VGroup(*labels)1020 labels.highlight(dots.color)1021 result = VGroup(dots, labels)1022 result.highlight(self.colors[denominator-1])1023 if template is not None:1024 dest_center = template[0][len(template[0])//2].get_center()1025 result.shift(dest_center)1026 return result1027 def make_dots(self, denominator = 1, min_num = 0):1028 1029 max_num = max(int(np.ceil((SPACE_WIDTH/self.h_space+1)*denominator)), min_num)1030 dots = []1031 for n in range(-max_num, max_num+1):1032 dot = Dot(float(n)/denominator * self.h_space*RIGHT)1033 dot.scale_in_place(4.0/(4.0+denominator-1))1034 dots.append(dot)1035 dots = VGroup(*dots)1036 dots.set_color(self.colors[denominator-1])1037 return dots1038class CantorDiagonal(Scene):1039 def construct(self):1040 self.zero = TexMobject('0')1041 self.one = TexMobject('1')1042 self.h_shift = 0.6*RIGHT1043 self.v_shift = 0.8*DOWN1044 self.diag_dir = self.h_shift + self.v_shift1045 self.sequences = VGroup(*[1046 self.make_seq()1047 for _ in range(3)1048 ])1049 for seq, color in zip(self.sequences, color_gradient([WHITE, DARK_GREY], 3)):1050 seq.set_color(color)1051 self.sequences.arrange_submobjects(DOWN)1052 self.sequences.to_edge(LEFT, buff = 3)1053 self.sequences[1].shift(2*RIGHT)1054 self.sequences[2].shift(RIGHT)1055 for seq in self.sequences:1056 self.play(ShowCreation(seq))1057 column = VGroup(*[1058 TexMobject(str(n)) for n in range(10)1059 ])1060 for i, num in enumerate(column):1061 num.move_to(i*self.v_shift)1062 column.to_corner(UP+LEFT)1063 column.shift(DOWN)1064 column.highlight(GREEN)1065 self.matching_l_buff = 0.21066 self.matching_r_buff = 0.71067 self.wait_to(7.3)1068 self.play(ShowCreation(column))1069 matching = []1070 for num in column:1071 start = num.get_edge_center(RIGHT)+self.matching_l_buff*RIGHT1072 end = copy.copy(start)1073 end[0] = -SPACE_WIDTH+2.51074 matching.append(Line(start, end))1075 for line, seq in zip(matching, self.sequences):1076 seq_dest = seq.copy()1077 seq_dest.highlight(WHITE)1078 self.seq_to_match_line(seq_dest, line)1079 self.play(1080 Transform(seq, seq_dest),1081 ShowCreation(line),1082 )1083 for line in matching[3:]:1084 seq = self.make_seq()1085 self.seq_to_match_line(seq, line)1086 self.sequences.submobjects.append(seq)1087 self.play(1088 ShowCreation(VGroup(*matching[3:])),1089 ShowCreation(VGroup(*self.sequences[3:])),1090 )1091 self.dither()1092 self.wait_to(15.5)1093 missing_seq = self.apply_diag_argument()1094 attempt_indices = [2, 6, 3]1095 attempt = attempt_indices[0]1096 self.wait_to(28.5)1097 rect_ori = None1098 for attempt in attempt_indices:1099 rect = SurroundingRectangle(self.sequences[attempt], color = WHITE)1100 if rect_ori is None: self.play(FadeIn(rect))1101 else: self.play(ReplacementTransform(rect_ori, rect))1102 self.play(FocusOn2(missing_seq[attempt]))1103 self.dither()1104 rect_ori = rect1105 self.play(FadeOut(rect)) # 35.51106 self.sequences.add_to_back(missing_seq)1107 sequences_dest = self.sequences.copy()1108 sequences_dest.highlight(WHITE)1109 for seq, line in zip(sequences_dest, matching):1110 self.seq_to_match_line(seq, line)1111 sequences_dest[-1].shift(DOWN)1112 self.wait_to(43)1113 self.play(Transform(self.sequences, sequences_dest))1114 self.wait_to(45)1115 missing_seq = self.apply_diag_argument(brief = True)1116 self.wait_to(54.5)1117 self.play(FadeOut(missing_seq))1118 title = TextMobject("Cantor's Diagonal Argument")1119 title.to_edge(UP)1120 self.play(Write(title))1121 self.wait_to(80.5)1122 def seq_to_match_line(self, seq, line):1123 seq.shift(line.get_end() - seq[0].get_center() + self.matching_r_buff*RIGHT)1124 1125 def random_digit(self):1126 return [self.zero, self.one][random.randint(0,1)].copy()1127 def make_seq(self, seq_len = 20):1128 1129 result = VGroup(*[1130 self.random_digit()1131 for i in range(seq_len)1132 ])1133 for i, digit in enumerate(result): digit.move_to(i*self.h_shift)1134 return result1135 def apply_diag_argument(self, brief = False, times = [18.5, 23.5]):1136 1137 diag = []1138 out_of_diag = []1139 for i, seq in enumerate(self.sequences):1140 diag.append(seq[i])1141 out_of_diag += seq[:i]1142 out_of_diag += seq[i+1:]1143 diag_start = diag[0].get_center()1144 arrow = Arrow(diag_start - 2*self.diag_dir,1145 diag_start - 0.5*self.diag_dir)1146 diag = VGroup(*diag)1147 out_of_diag = VGroup(*out_of_diag)1148 if not brief: self.play(ShowCreation(arrow))1149 self.play(1150 diag.highlight, YELLOW,1151 out_of_diag.highlight, DARK_GREY,1152 )1153 if not brief:1154 self.play(FadeOut(arrow))1155 self.wait_to(times[0])1156 while len(diag) < len(self.sequences[0]):1157 next_el = self.random_digit()1158 next_el.highlight(YELLOW)1159 next_el.move_to(diag[0])1160 next_el.shift(len(diag)*self.diag_dir)1161 diag.submobjects.append(next_el)1162 self.add(diag)1163 diag_extracted = diag.copy()1164 for num in diag_extracted:1165 num.to_edge(UP)1166 self.play(ReplacementTransform(diag.copy(), diag_extracted))1167 missing_seq = []1168 for num in diag_extracted:1169 inverted = TexMobject(str(1-int(num.tex_string)))1170 inverted.highlight(RED)1171 inverted.move_to(num)1172 missing_seq.append(inverted)1173 missing_seq = VGroup(*missing_seq)1174 if not brief: self.wait_to(times[1])1175 self.play(ReplacementTransform(diag_extracted, missing_seq))1176 return missing_seq...

Full Screen

Full Screen

MIDNIGHT_8-1.py

Source:MIDNIGHT_8-1.py Github

copy

Full Screen

...54 else:55 XY = template.match_in(screen)56 return XY is not None5758def wait_to(template, rect=None):59 global screen60 while 1:61 screen = G.DEVICE.snapshot()62 if is_found(template, rect):63 return64 sleep(0.2)65 assert 06667def detach():68 '''检索当前图片,更新全局坐标点,返回图片策略序号'''69 global XY70 global screen71 global cnt72 global start73 screen = G.DEVICE.snapshot()74 if is_found(Template(r"tpl1644856635384.png", record_pos=(0.41, -0.223), resolution=(1024, 576)), g((925, 51), (925, 70), (940, 70))):75 return 076 elif is_found(Template(r"tpl1644856716623.png", target_pos=4, record_pos=(-0.354, -0.255), resolution=(1024, 576)), g((57, 12), (57, 43), (242, 43))):77 return 078 elif is_found(Template(r"tpl1647070771440.png", record_pos=(0.029, -0.055), resolution=(1024, 576)), g((430, 204), (430, 261), (655, 261))):79 return 080 elif is_found(Template(r"tpl1644764815224.png", threshold=0.97, target_pos=5, record_pos=(-0.479, -0.009), resolution=(1024, 665))):81 return 082 elif is_found(Template(r"tpl1644771271544.png", record_pos=(-0.409, -0.074), resolution=(1024, 576)), g((61, 198), (61, 226), (125, 226))):83 return 084 elif is_found(Template(r"tpl1644766848271.png", rgb=False, record_pos=(0.081, 0.097), resolution=(1024, 665)), g((537, 377), (537, 416), (653, 416))):85 return 086 elif is_found(Template(r"tpl1644771347927.png", record_pos=(0.209, 0.047), resolution=(1024, 576)), g((648, 298), (648, 375), (805, 375))):87 return 088 elif is_found(Template(r"tpl1647025537096.png", record_pos=(-0.307, -0.196), resolution=(1024, 576)), g((141, 68), (141, 107), (255, 107))):89 return 390 elif is_found(Template(r"tpl1647025901008.png", record_pos=(-0.283, -0.194), resolution=(1024, 576)), g((145, 73), (145, 105), (299, 105))):91 return 392 elif is_found(Template(r"tpl1644771635172.png", record_pos=(0.297, 0.185), resolution=(1024, 576)), g((771, 466), (771, 489), (862, 489))):93 return 094 elif is_found(Template(r"tpl1644771405564.png", record_pos=(-0.198, -0.237), resolution=(1024, 576)), g((261, 21), (261, 69), (357, 69))):95 return 296 elif is_found(Template(r"tpl1644771706558.png", record_pos=(-0.151, -0.247), resolution=(1024, 576)), g((338, 6), (338, 65), (377, 65))) and is_found(Template(r"tpl1644771774441.png", record_pos=(0.386, 0.221), resolution=(1024, 576)), g((842, 500), (842, 529), (972, 529))):97 return 498 elif is_found(Template(r"tpl1647063538393.png", record_pos=(-0.149, -0.234), resolution=(1024, 576)), g((341, 29), (341, 67), (378, 67))) and is_found(Template(r"tpl1647063577054.png", threshold=0.75, rgb=True, record_pos=(0.311, 0.241), resolution=(1024, 576)), g((797, 518), (797, 552), (863, 552))):99 return 5100 elif is_found(Template(r"tpl1647063538393.png", record_pos=(-0.149, -0.234), resolution=(1024, 576)), g((341, 29), (341, 67), (378, 67))) and is_found(Template(r"tpl1647450033644.png", record_pos=(0.311, 0.242), resolution=(1024, 576)), g((801, 517), (801, 555), (861, 555))) and is_found(Template(r"tpl1647066298630.png", record_pos=(-0.439, 0.179), resolution=(1024, 576)), g((2, 456), (2, 487), (122, 487))):101 return 6102 elif is_found(Template(r"tpl1647063538393.png", record_pos=(-0.149, -0.234), resolution=(1024, 576)), g((341, 29), (341, 67), (378, 67))) and is_found(Template(r"tpl1647144019805.png", record_pos=(0.311, 0.242), resolution=(1024, 576)), g((801, 517), (801, 555), (861, 555))):103 return 7104 elif is_found(Template(r"tpl1644773664247.png", record_pos=(-0.437, -0.248), resolution=(1024, 576)), g((31, 18), (31, 51), (100, 51))):105 XY = (XY[0] + 100, XY[1])106 return 0107 elif is_found(Template(r"tpl1644775198955.png", record_pos=(-0.076, 0.223), resolution=(1024, 576)), g((408, 509), (408, 524), (461, 524))):108 XY = (XY[0] + 100, XY[1])109 for _ in range(4):110 click(XY)111 sleep(0.5)112 return 0113 elif is_found(Template(r"tpl1647069986280.png", record_pos=(-0.246, -0.121), resolution=(1024, 576)), g((194, 153), (194, 175), (327, 175))) and is_found(Template(r"tpl1647070154857.png", target_pos=8, record_pos=(-0.002, 0.046), resolution=(1024, 576)), g((443, 251), (443, 419), (578, 419))):114 return 0115 elif is_found(Template(r"tpl1647070306739.png", record_pos=(-0.2, -0.237), resolution=(1024, 576)), g((258, 20), (258, 71), (359, 71))) and is_found(Template(r"tpl1647070328462.png", record_pos=(-0.064, -0.126), resolution=(1024, 576)), g((427, 140), (427, 179), (465, 179))):116 return 0117 elif is_found(Template(r"tpl1647070542885.png", record_pos=(0.393, 0.199), resolution=(1024, 576)), g((884, 474), (884, 510), (944, 510))):118 click(XY)119 sleep(1.0)120 click(XY)121 sleep(1.0)122 return 0123 elif is_found(Template(r"tpl1644856432544.png", threshold=0.9500000000000002, record_pos=(-0.281, -0.102), resolution=(1024, 576)), g((193, 153), (193, 216), (256, 216))):124 XY = (XY[0] - 100, XY[1])125 return 0126 elif is_found(Template(r"tpl1644779677165.png", record_pos=(-0.415, -0.241), resolution=(1024, 576))):127 return 0128 return -1129 130131def attach():132 '''根据当前策略号作相应策略'''133 global XY134 global cnt135 global start136 index = detach()137 logger.debug("index============>" + str(index))138 if index == 0:139 click(XY)140 elif index == 1:141 logger.debug("============>" + str(XY))142 elif index == 2:143 click((75, 188)) # 作战任务144 wait_to(Template(r"tpl1647447498252.png", record_pos=(0.427, -0.185), resolution=(1024, 576)), g((938, 87), (938, 112), (961, 112)))145 swipe((200, 283), vector=[0.0, -0.4], steps=3, duration=0.2)146 elif index == 3:147 click(XY)148 wait_to(Template(r"tpl1647447972805.png", record_pos=(-0.145, -0.052), resolution=(1024, 576)), g((343, 204), (343, 267), (386, 267)))149 click((970, 153))150 wait_to(Template(r"tpl1647447972805.png", record_pos=(-0.145, -0.052), resolution=(1024, 576)), g((343, 204), (343, 267), (386, 267)))151 click((540, 237))152 elif index == 4:153 pinch(in_or_out='in', center=None, percent=0.5) # 缩放154 sleep(1.0)155 swipe((200, 283), vector=[1.0, 1.0], steps=50, duration=0.1) # 右下滑动156 wait_to(Template(r"tpl1647448741476.png", record_pos=(-0.075, 0.19), resolution=(1024, 576)), g((402, 444), (402, 523), (469, 523)))157 click((224, 118)) # 左上机场158 wait_to(Template(r"tpl1647277864179.png", record_pos=(-0.302, 0.208), resolution=(1024, 576)), g((142, 489), (142, 514), (264, 514)))159 click((932, 508)) # 第一梯队部署160 wait_to(Template(r"tpl1647448741476.png", record_pos=(-0.075, 0.19), resolution=(1024, 576)), g((402, 444), (402, 523), (469, 523)))161 click((178, 493)) # 左下机场162 wait_to(Template(r"tpl1647277864179.png", record_pos=(-0.302, 0.208), resolution=(1024, 576)), g((142, 489), (142, 514), (264, 514)))163 click((932, 508)) # 第二梯队部署164 wait_to(Template(r"tpl1647448741476.png", record_pos=(-0.075, 0.19), resolution=(1024, 576)), g((402, 444), (402, 523), (469, 523)))165 click((932, 508)) # 开始作战166 click((932, 508)) # 开始作战167 if time.time() - start > 2:168 cnt += 1169 start = time.time()170 logger.error("无限脚本开始,当前进行第%d轮" % cnt)171 sleep(1.5)172 elif index == 5:173 wait_to(Template(r"tpl1647449130009.png", record_pos=(-0.429, -0.168), resolution=(1024, 576)), g((56, 99), (56, 133), (90, 133)))174 click((74, 116)) # 点击说明175 wait_to(Template(r"tpl1647449181778.png", record_pos=(-0.428, -0.166), resolution=(1024, 576)), g((61, 102), (61, 135), (87, 135)))176 click((74, 116)) # 点击说明177 sleep(0.2)178 wait_to(Template(r"tpl1647278147416.png", record_pos=(-0.44, 0.181), resolution=(1024, 576)), g((7, 460), (7, 486), (115, 486)))179 click((224, 135)) # 左上机场180 wait_to(Template(r"tpl1647278748100.png", record_pos=(0.424, -0.172), resolution=(1024, 576)), g((934, 99), (934, 126), (958, 126)))181 click((60, 472)) # 计划模式182 wait_to(Template(r"tpl1647278941881.png", record_pos=(-0.443, 0.181), resolution=(1024, 576)), g((5, 463), (5, 483), (112, 483)))183 click((155, 243)) # 左上白点184 wait_to(Template(r"tpl1647449520081.png", record_pos=(-0.351, -0.044), resolution=(1024, 576)), g((133, 222), (133, 265), (173, 265)))185 click((178, 493)) # 左下机场186 wait_to(Template(r"tpl1647449602282.png", record_pos=(-0.25, 0.198), resolution=(1024, 576)), g((213, 480), (213, 503), (300, 503)))187 click((168, 493)) # 移动188 wait_to(Template(r"tpl1647449673833.png", record_pos=(-0.341, 0.089), resolution=(1024, 576)), g((142, 358), (142, 401), (184, 401)))189 click((900, 510)) # 执行计划190 sleep(10.0)191 elif index == 6:192 click((183, 428)) # 左下机场193 wait_to(Template(r"tpl1647277864179.png", record_pos=(-0.302, 0.208), resolution=(1024, 576)), g((142, 489), (142, 514), (264, 514)))194 click((783, 509)) # 撤离195 wait_to(Template(r"tpl1647450113336.png", record_pos=(0.081, 0.106), resolution=(1024, 576)), g((540, 379), (540, 415), (651, 415)))196 click((594, 396)) # 确认撤离197 wait_to(Template(r"tpl1647450191589.png", record_pos=(-0.326, 0.141), resolution=(1024, 576)), g((164, 418), (164, 446), (192, 446)))198 click((183, 428)) # 左下机场199 wait_to(Template(r"tpl1647277864179.png", record_pos=(-0.302, 0.208), resolution=(1024, 576)), g((142, 489), (142, 514), (264, 514)))200 click((201, 502)) # 队伍编成201 wait_to(Template(r"tpl1647450267553.png", record_pos=(-0.168, -0.245), resolution=(1024, 576)), g((265, 23), (265, 52), (415, 52)))202 click((949, 544)) # 阵型编成203 wait_to(Template(r"tpl1647450327595.png", record_pos=(0.341, -0.054), resolution=(1024, 576)), g((834, 206), (834, 260), (888, 260)))204 click((861, 234)) # 梯队预设205 wait_to(Template(r"tpl1647450393651.png", record_pos=(0.39, 0.138), resolution=(1024, 576)), g((831, 410), (831, 448), (992, 448)))206 click((687, 159)) # 预设2207 wait_to(Template(r"tpl1647450515144.png", record_pos=(0.008, -0.003), resolution=(1024, 576)), g((512, 240), (512, 329), (552, 329)))208 click((906, 507)) # 套用预设209 wait_to(Template(r"tpl1647450580716.png", record_pos=(-0.061, 0.051), resolution=(1024, 576)), g((432, 323), (432, 357), (468, 357)))210 click((452, 340)) # 强制替换211 wait_to(Template(r"tpl1647450629017.png", record_pos=(-0.06, 0.052), resolution=(1024, 576)), g((432, 323), (432, 357), (468, 357)))212 click((657, 399)) # 确认213 wait_to(Template(r"tpl1647450327595.png", record_pos=(0.341, -0.054), resolution=(1024, 576)), g((834, 206), (834, 260), (888, 260)))214 click((928, 507)) # 确定215 wait_to(Template(r"tpl1647450267553.png", record_pos=(-0.168, -0.245), resolution=(1024, 576)), g((265, 23), (265, 52), (415, 52)))216 click((87, 42)) # 后退217 wait_to(Template(r"tpl1647278147416.png", record_pos=(-0.44, 0.181), resolution=(1024, 576)), g((7, 460), (7, 486), (115, 486)))218 click((183, 428)) # 左下机场219 wait_to(Template(r"tpl1647277864179.png", record_pos=(-0.302, 0.208), resolution=(1024, 576)), g((142, 489), (142, 514), (264, 514)))220 click((932, 508)) # 确认部署221 wait_to(Template(r"tpl1647278147416.png", record_pos=(-0.44, 0.181), resolution=(1024, 576)), g((7, 460), (7, 486), (115, 486)))222 sleep(0.2)223 click((183, 428)) # 左下机场224 wait_to(Template(r"tpl1647278748100.png", record_pos=(0.424, -0.172), resolution=(1024, 576)), g((934, 99), (934, 126), (958, 126)))225 click((183, 428)) # 左下机场226 wait_to(Template(r"tpl1647277864179.png", record_pos=(-0.302, 0.208), resolution=(1024, 576)), g((142, 489), (142, 514), (264, 514)))227 click((932, 447)) # 补给228 wait_to(Template(r"tpl1647278748100.png", record_pos=(0.424, -0.172), resolution=(1024, 576)), g((934, 99), (934, 126), (958, 126)))229 click((183, 428)) # 左下机场230 wait_to(Template(r"tpl1647277864179.png", record_pos=(-0.302, 0.208), resolution=(1024, 576)), g((142, 489), (142, 514), (264, 514)))231 click((783, 509)) # 撤离232 wait_to(Template(r"tpl1647450113336.png", record_pos=(0.081, 0.106), resolution=(1024, 576)), g((540, 379), (540, 415), (651, 415)))233 click((594, 396)) # 确认撤离234 wait_to(Template(r"tpl1647450191589.png", record_pos=(-0.326, 0.141), resolution=(1024, 576)), g((164, 418), (164, 446), (192, 446)))235 click((183, 428)) # 左下机场236 wait_to(Template(r"tpl1647277864179.png", record_pos=(-0.302, 0.208), resolution=(1024, 576)), g((142, 489), (142, 514), (264, 514)))237 click((201, 502)) # 队伍编成238 wait_to(Template(r"tpl1647450267553.png", record_pos=(-0.168, -0.245), resolution=(1024, 576)), g((265, 23), (265, 52), (415, 52)))239 click((949, 544)) # 阵型编成240 wait_to(Template(r"tpl1647450327595.png", record_pos=(0.341, -0.054), resolution=(1024, 576)), g((834, 206), (834, 260), (888, 260)))241 click((861, 234)) # 梯队预设242 wait_to(Template(r"tpl1647450393651.png", record_pos=(0.39, 0.138), resolution=(1024, 576)), g((831, 410), (831, 448), (992, 448)))243 click((687, 89)) # 预设1244 wait_to(Template(r"tpl1647450515144.png", record_pos=(0.008, -0.003), resolution=(1024, 576)), g((512, 240), (512, 329), (552, 329)))245 click((906, 507)) # 套用预设246 wait_to(Template(r"tpl1647450327595.png", record_pos=(0.341, -0.054), resolution=(1024, 576)), g((834, 206), (834, 260), (888, 260)))247 click((928, 507)) # 确定248 wait_to(Template(r"tpl1647450267553.png", record_pos=(-0.168, -0.245), resolution=(1024, 576)), g((265, 23), (265, 52), (415, 52)))249 click((87, 42)) # 后退250 elif index == 7:251 click((253, 35)) # 终止作战252 wait_to(Template(r"tpl1647451075150.png", record_pos=(-0.118, 0.1), resolution=(1024, 576)), g((324, 366), (324, 415), (458, 415)))253 click((393, 394)) # 重新作战254 if time.time() - start > 2:255 logger.error("第%d轮结束,耗时%.2lfs" % (cnt, time.time() - start))256 start = time.time()257 sleep(1.0)258 else:259 logger.debug("============>" + str(XY))260 sleep(1.0)261 return 262263if DEBUG:264 attach()265else:266 while True: ...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1# date: 2019.04.092# https://stackoverflow.com/questions/55588557/how-to-move-a-circle-again-after-being-idle-for-3-seconds3import pygame4# --- constants ---5WHITE = (255, 255, 255)6BLACK = ( 0, 0, 0)7RED = (255, 0, 0)8GREEN = ( 0, 255, 0)9BLUE = ( 0, 0, 255)10# --- classes ---11# empty12# --- functions ---13# empty14# --- main ---15pygame.init()16windowCalibration = pygame.display.set_mode((0,0))17pygame.display.set_caption("Eye calibration")18circles = [19 {'pos': [300, 368], 'speed': 1, 'state': 'move_left', 'wait_to': 0, 'color': RED},20 {'pos': [300, 268], 'speed': 10, 'state': 'move_right', 'wait_to': 0, 'color': GREEN},21 {'pos': [300, 168], 'speed': 30, 'state': 'move_right', 'wait_to': 0, 'color': BLUE},22]23done = False24while not done:25 # --- events ---26 for event in pygame.event.get():27 if event.type == pygame.QUIT:28 done = True29 if event.type == pygame.KEYDOWN:30 if event.key == pygame.K_ESCAPE:31 done = True32 # --- moves ---33 34 current_time = pygame.time.get_ticks()35 for circle in circles:36 if circle['state'] == 'move_left':37 if circle['pos'][0] >= 10:38 circle['pos'][0] -= circle['speed']39 else:40 circle['pos'][0] = 1041 circle['state'] = 'wait_before_move_right'42 circle['wait_to'] = pygame.time.get_ticks() + 300043 elif circle['state'] == 'move_right':44 if circle['pos'][0] <= 1350:45 circle['pos'][0] += circle['speed']46 else:47 circle['pos'][0] = 135048 circle['state'] = 'wait_before_move_left'49 circle['wait_to'] = pygame.time.get_ticks() + 300050 elif circle['state'] == 'wait_before_move_right':51 if current_time > circle['wait_to']:52 circle['state'] = 'move_right'53 elif circle['state'] == 'wait_before_move_left':54 if current_time > circle['wait_to']:55 circle['state'] = 'move_left'56 # --- draws ----57 windowCalibration.fill(WHITE)58 for circle in circles:59 pygame.draw.circle(windowCalibration, circle['color'], circle['pos'], 10)60 pygame.display.update()61# --- end ---...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selene automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful