def destroy_existing(self, destroyed_blocks): all_anims = [] overlay_objs = [] for id1, id2 in destroyed_blocks: # Generate a square containing both arrow blocks, and fade colour. if self.DESTRUCTION_RUNTIME > 0: anims = [] if self.DESTRUCTION_ARROW_ANIM is not None: anims.append(self.DESTRUCTION_ARROW_ANIM(self.arrow_blocks[id1])) anims.append(self.DESTRUCTION_ARROW_ANIM(self.arrow_blocks[id2])) else: # Instantly remove on animate. anims.append(FadeOut(self.arrow_blocks[id1], rate_func=lambda t: 1)) anims.append(FadeOut(self.arrow_blocks[id2], rate_func=lambda t: 1)) if self.DESTRUCTION_OVERLAY_COLOUR is not None: top = max(self.arrow_blocks[id1].get_top()[1], self.arrow_blocks[id2].get_top()[1]) right = max(self.arrow_blocks[id1].get_right()[0], self.arrow_blocks[id2].get_right()[0]) fade_square = Square(side_length=self.scale * 2, color=self.DESTRUCTION_OVERLAY_COLOUR) fade_square.set_opacity(self.DESTRUCTION_OVERLAY_STARTING_ALPHA) fade_square.move_to([right - self.scale, top - self.scale, 0]) overlay_objs.append(fade_square) anims.append(FadeOut(fade_square)) all_anims.append(AnimationGroup(*anims)) else: self.remove(self.arrow_blocks[id1], self.arrow_blocks[id2]) del self.arrow_blocks[id1] del self.arrow_blocks[id2] if self.DESTRUCTION_RUNTIME > 0 and len(all_anims) > 0: return overlay_objs, LaggedStart(*all_anims, lag_ratio=self.DESTRUCTION_LAG_RATIO) return None, None
def create_arrows(self, created): all_anims = [] overlay_objs = [] for (id1, (p11, p12), (d1x, d1y)), (id2, (p21, p22), (d2x, d2y)) in created: self.arrow_blocks[id1] = self._create_arrow( [((p11[0] + p12[0])/2 + 0.5) * self.scale, ((p11[1] + p12[1])/2 + 0.5) * self.scale, 0], [d1x, d1y], ) self.arrow_blocks[id2] = self._create_arrow( [((p21[0] + p22[0])/2 + 0.5) * self.scale, ((p21[1] + p22[1])/2 + 0.5) * self.scale, 0], [d2x, d2y], ) overlay_objs.extend([self.arrow_blocks[id1], self.arrow_blocks[id2]]) if self.ARROW_OVERLAY_COLOUR is not None: top = max(self.arrow_blocks[id1].get_top()[1], self.arrow_blocks[id2].get_top()[1]) right = max(self.arrow_blocks[id1].get_right()[0], self.arrow_blocks[id2].get_right()[0]) fade_square = Square(side_length=self.scale * 2, color=self.ARROW_OVERLAY_COLOUR) fade_square.set_opacity(self.ARROW_OVERLAY_STARTING_ALPHA) fade_square.move_to([right - self.scale, top - self.scale, 0]) overlay_objs.append(fade_square) if self.ARROW_CREATE_RUNTIME > 0: anims = [] if self.ARROW_OVERLAY_COLOUR is not None: anims.append(FadeOut(fade_square)) if self.ARROW_CREATE_ANIM is not None: if self.ARROW_CREATE_ANIM == FadeInFrom: anims.append(FadeInFrom(self.arrow_blocks[id1], direction=[-d1x * self.scale, -d1y * self.scale, 0])) anims.append(FadeInFrom(self.arrow_blocks[id2], direction=[-d2x * self.scale, -d2y * self.scale, 0])) else: anims.append(self.ARROW_CREATE_ANIM(self.arrow_blocks[id1])) anims.append(self.ARROW_CREATE_ANIM(self.arrow_blocks[id2])) else: # This adds them to the scene. anims.append(Transform(self.arrow_blocks[id1], self.arrow_blocks[id1])) anims.append(Transform(self.arrow_blocks[id2], self.arrow_blocks[id2])) all_anims.append(AnimationGroup(*anims)) if self.ARROW_CREATE_RUNTIME > 0 and len(all_anims) > 0: return overlay_objs, LaggedStart(*all_anims, lag_ratio=self.ARROW_LAG_RATIO) return overlay_objs, None
def _generate_open_square(self, position): sq = Square(side_length=self.scale, **self.OPEN_SQUARE_KWARGS) sq.move_to(position) return sq