def do_effect(self, painting): """Process an image so that it is made up of circles. This method processes an image so that it is made up of circles of a supplied radius, on top of a given background colour. The color of the circles correspond to the pixel that would have been at its centre. Arguments: painting -- the painting.Painting that the effect should be applied to """ distance_between_centres = self.diameter + self.gap # Half of distance so that circles fully visible on top and left edges first_centre = distance_between_centres/2 canvas = painting.copy() canvas.clear_image(self.background) for x in range(first_centre, painting.width, distance_between_centres): for y in range(first_centre, painting.height, distance_between_centres): centre = point.Point(x, y) centre_color = painting.get_pixel_color(centre) circle = shape.Circle(centre, self.radius, centre_color) circle.draw(canvas) painting.img = canvas
def do_effect(self, painting): """Process an image so that it is made up of circles. This method processes an image so that it is made up of circles of a supplied radius, on top of a given background colour. The color of the circles correspond to the pixel that would have been at its centre. Arguments: painting -- the painting.Painting that the effect should be applied to """ distance_between_centres = self.diameter + self.gap # Half of distance so that circles fully visible on top and left edges first_centre = distance_between_centres / 2 canvas = painting.copy() canvas.clear_image(self.background) for x in range(first_centre, painting.width, distance_between_centres): for y in range(first_centre, painting.height, distance_between_centres): centre = point.Point(x, y) centre_color = painting.get_pixel_color(centre) circle = shape.Circle(centre, self.radius, centre_color) circle.draw(canvas) painting.img = canvas
def do_effect(self, painting): """Process an image so that its pixels are shuffled. This method processes an image so that the pixels of the image are shuffled with nearby pixels. Arguments: painting -- the painting.Painting that the effect should be applied to """ original_painting = painting.copy() for x in range(0, painting.width, self.shuffle_step): for y in range(0, painting.height, self.shuffle_step): current_coordinate = point.Point(x, y) squaresize = self.__get_random_squaresize() pixel_square = original_painting.get_square( current_coordinate, squaresize, squaresize) shuffled_pixel_square = pixel_square random.shuffle(shuffled_pixel_square) for pixel in pixel_square: new_pixel_color = original_painting.get_pixel_color(pixel) pixel_to_be_replaced = shuffled_pixel_square.pop() painting.set_pixel_color(pixel_to_be_replaced, new_pixel_color)
def do_effect(self, painting): """Process an image so that its pixels are shuffled. This method processes an image so that the pixels of the image are shuffled with nearby pixels. Arguments: painting -- the painting.Painting that the effect should be applied to """ original_painting = painting.copy() for x in range(0, painting.width, self.shuffle_step): for y in range(0, painting.height, self.shuffle_step): current_coordinate = point.Point(x, y) squaresize = self.__get_random_squaresize() pixel_square = original_painting.get_square(current_coordinate, squaresize, squaresize) shuffled_pixel_square = pixel_square random.shuffle(shuffled_pixel_square) for pixel in pixel_square: new_pixel_color = original_painting.get_pixel_color(pixel) pixel_to_be_replaced = shuffled_pixel_square.pop() painting.set_pixel_color(pixel_to_be_replaced, new_pixel_color)