def highlight_region(self, region, color = None): self.background = disp.paint_region( region, image_array = self.background, color = color, ) return self
def construct(self): GraphScene.construct(self) self.generate_regions() self.generate_dual_graph() region_mobs = [ImageMobject(disp.paint_region(reg, self.background), invert=False) for reg in self.regions] for region, mob in zip(self.regions, region_mobs): self.highlight_region(region, mob.get_color()) outer_region = self.regions.pop() outer_region_mob = region_mobs.pop() outer_dual_vertex = self.dual_vertices.pop() internal_edges = filter( lambda e: abs(e.start[0]) < SPACE_WIDTH and abs(e.end[0]) < SPACE_WIDTH and abs(e.start[1]) < SPACE_HEIGHT and abs(e.end[1]) < SPACE_HEIGHT, self.dual_edges, ) external_edges = filter(lambda e: e not in internal_edges, self.dual_edges) self.dither() self.reset_background() self.highlight_region(outer_region, outer_region_mob.get_color()) self.play(*[Transform(reg_mob, dot) for reg_mob, dot in zip(region_mobs, self.dual_vertices)]) self.dither() self.reset_background() self.play(ApplyFunction(lambda p: (SPACE_WIDTH + SPACE_HEIGHT) * p / np.linalg.norm(p), outer_region_mob)) self.dither() for edges in internal_edges, external_edges: self.play(*[ShowCreation(edge, run_time=2.0) for edge in edges]) self.dither()
def highlight_region(self, region, color=None): self.background = disp.paint_region( region, image_array=self.background, color=color, ) return self
def highlight_region_over_time_range(self, region, time_range=None, color="black"): if time_range: frame_range = map(lambda t: t / self.frame_duration, time_range) frame_range[0] = max(frame_range[0], 0) frame_range[1] = min(frame_range[1], len(self.frames)) else: frame_range = (0, len(self.frames)) for index in range(frame_range[0], frame_range[1]): self.frames[index] = disp.paint_region(region, image_array=self.frames[index], color=color)
def highlight_region_over_time_range(self, region, time_range=None, color="black"): if time_range: frame_range = map(lambda t: t / self.frame_duration, time_range) frame_range[0] = max(frame_range[0], 0) frame_range[1] = min(frame_range[1], len(self.frames)) else: frame_range = (0, len(self.frames)) for index in range(frame_range[0], frame_range[1]): self.frames[index] = disp.paint_region( region, image_array=self.frames[index], color=color)
def construct(self): GraphScene.construct(self) self.generate_regions() self.generate_dual_graph() region_mobs = [ ImageMobject(disp.paint_region(reg, self.background), invert = False) for reg in self.regions ] for region, mob in zip(self.regions, region_mobs): self.set_color_region(region, mob.get_color()) outer_region = self.regions.pop() outer_region_mob = region_mobs.pop() outer_dual_vertex = self.dual_vertices.pop() internal_edges = filter( lambda e : abs(e.start[0]) < FRAME_X_RADIUS and \ abs(e.end[0]) < FRAME_X_RADIUS and \ abs(e.start[1]) < FRAME_Y_RADIUS and \ abs(e.end[1]) < FRAME_Y_RADIUS, self.dual_edges ) external_edges = filter( lambda e : e not in internal_edges, self.dual_edges ) self.wait() self.reset_background() self.set_color_region(outer_region, outer_region_mob.get_color()) self.play(*[ Transform(reg_mob, dot) for reg_mob, dot in zip(region_mobs, self.dual_vertices) ]) self.wait() self.reset_background() self.play(ApplyFunction( lambda p : (FRAME_X_RADIUS + FRAME_Y_RADIUS)*p/np.linalg.norm(p), outer_region_mob )) self.wait() for edges in internal_edges, external_edges: self.play(*[ ShowCreation(edge, run_time = 2.0) for edge in edges ]) self.wait()
def construct(self): GraphScene.construct(self) self.generate_regions() self.generate_dual_graph() region_mobs = [ ImageMobject(disp.paint_region(reg, self.background), invert = False) for reg in self.regions ] for region, mob in zip(self.regions, region_mobs): self.set_color_region(region, mob.get_color()) outer_region = self.regions.pop() outer_region_mob = region_mobs.pop() outer_dual_vertex = self.dual_vertices.pop() internal_edges = [e for e in self.dual_edges if abs(e.start[0]) < FRAME_X_RADIUS and \ abs(e.end[0]) < FRAME_X_RADIUS and \ abs(e.start[1]) < FRAME_Y_RADIUS and \ abs(e.end[1]) < FRAME_Y_RADIUS] external_edges = [e for e in self.dual_edges if e not in internal_edges] self.wait() self.reset_background() self.set_color_region(outer_region, outer_region_mob.get_color()) self.play(*[ Transform(reg_mob, dot) for reg_mob, dot in zip(region_mobs, self.dual_vertices) ]) self.wait() self.reset_background() self.play(ApplyFunction( lambda p : (FRAME_X_RADIUS + FRAME_Y_RADIUS)*p/get_norm(p), outer_region_mob )) self.wait() for edges in internal_edges, external_edges: self.play(*[ ShowCreation(edge, run_time = 2.0) for edge in edges ]) self.wait()
def show(self, color=None): Image.fromarray(disp.paint_region(self, color=color)).show()
def show(self, color = None): Image.fromarray(disp.paint_region(self, color = color)).show()
def __init__(self, region, color=None, **kwargs): MobjectFromPixelArray.__init__(self, disp.paint_region(region, color=color), **kwargs)
def __init__(self, region, color = None, **kwargs): MobjectFromPixelArray.__init__( self, disp.paint_region(region, color = color), **kwargs )