Image Range-Loop Problems

```            ```
def double_left(filename):
image = SimpleImage(filename)
# style idea: the math is hard enough to follow,
# it's helpful to introduce a variable like this to name
# a common value we need (identify mid_x on drawing too).
mid_x = image.width // 2
for y in range(image.height):
for x in range(mid_x):
pixel = image.get_pixel(x, y)
pixel_right = image.get_pixel(mid_x + x, y)
pixel_right.red = pixel.red
pixel_right.green = pixel.green
pixel_right.blue = pixel.blue
return image

def double_left_up(filename):
image = SimpleImage(filename)
mid_x = image.width // 2
for y in range(image.height):
for x in range(mid_x):
pixel = image.get_pixel(x, y)
# the key line:
pixel_right = image.get_pixel(mid_x + x, image.height - y - 1)
pixel_right.red = pixel.red
pixel_right.green = pixel.green
pixel_right.blue = pixel.blue
return image

def copies_2(filename):
image = SimpleImage(filename)
# Creates a new white image with nothing in it
out = SimpleImage('', width=image.width * 2, height=image.height)
mid_x = image.width
for y in range(image.height):
for x in range(image.width):
pixel = image.get_pixel(x, y)
# left copy
pixel_left = out.get_pixel(x, y)
pixel_left.red = pixel.red
pixel_left.green = pixel.green
pixel_left.blue = pixel.blue
# right copy
pixel_right = out.get_pixel(mid_x + x, y)
pixel_right.red = pixel.red
pixel_right.green = pixel.green
pixel_right.blue = pixel.blue
return out

def squeeze_width(filename, n):
image = SimpleImage(filename)
out = SimpleImage('', width=image.width // n, height=image.height)
# strategy: iterate x,y over the out pixels, compute
# scaled * n pixel in original image.
for y in range(out.height):
for x in range(out.width):
pixel_out = out.get_pixel(x, y)
pixel = image.get_pixel(x * n, y)

pixel_out.red = pixel.red
pixel_out.green = pixel.green
pixel_out.blue = pixel.blue
return  out
```
```

Image Puzzles

```            ```
def fix1(filename):
"""Fix the fix1 puzzle image."""
image = SimpleImage(filename)
for pixel in image:
pixel.red = pixel.red * 8
pixel.green = pixel.green * 2
pixel.blue = pixel.blue  * 4
return  image

def fix2(filename):
"""Fix the fix2 puzzle image."""
image = SimpleImage(filename)
for pixel in image:
temp = pixel.red
pixel.red = pixel.green
pixel.green = temp
return image

def fix3(filename):
"""Fix the fix3 puzzle image."""
image = SimpleImage(filename)
for pixel in image:
temp = pixel.red
pixel.red = pixel.blue
pixel.blue = temp
pixel.green = pixel.green * 4
return  image
```
```