def __init__(self, canvas: Optional[Image] = None): """ Init the turtle world. :param canvas: the underlying image of the world. None means it's the graphics window. """ if canvas is None: self._win = eg.get_graphics_window() self._world_image = eg.create_image(eg.get_width(), eg.get_height()) else: self._world_image = canvas self._win = None self._width = self._world_image.get_width() self._height = self._world_image.get_height() self._buffer_image = eg.create_image(self._width, self._height) self._reset_world_image() self._turtles: List[Turtle] = [] self._running = True if self._win is not None: self._immediate = False self._win.set_immediate(False) self._start_refresh_loop() eg.set_target(self._world_image) else: self._immediate = True
def end_fill(self): """ Fill the shape enclosed by the turtle's drawing path after the last call to begin_fill. """ if not self.is_filling(): return image = eg.create_image(self._world.get_width(), self._world.get_height()) image.set_pen(QtGui.QPen(self._world.get_world_image().get_pen())) image.set_color(eg.Color.TRANSPARENT) image.set_line_style(eg.LineStyle.SOLID_LINE) image.set_brush(QtGui.QBrush( self._world.get_world_image().get_brush())) image.set_fill_rule(self._world.get_world_image().get_fill_rule()) image.set_composition_mode(eg.CompositionMode.SOURCE) transform = self._world.get_world_image().get_transform() image.set_transform(transform) image.draw_polygon(*self._fillpath) self._world.get_world_image().reset_transform() self._world.get_world_image().draw_image( 0, 0, image, with_background=False, composition_mode=eg.CompositionMode.SOURCE_OVER) self._world.get_world_image().set_transform(transform) image.close() self._fillpath.clear()
def create_snap_shot(self) -> Image: """ Create a snap shot of the current drawing. :return: the snap shot image. """ image = eg.create_image(self._width, self._height) self.snap_shot_to_image(image) return image