Create a function changeColors(img) that sets the red in all pixels equal to the blue value in the image img. Then, it sets the green and blue in all pixels to 255.
Write a function changeColors(img) that sets the red in all pixels equal to the blue value in the image img. Then, it sets the green and blue in all pixels to 255.
Create a function modifyColors(img) that decreases the red to 60% of its original value, increases the blue by 60% of its original value, and sets the green to 0 in the image img.
Write a function modifyColors(img) that decreases the red to 60% of its original value, increases the blue by 60% of its original value, and sets the green to 0 in the image img.
from image import *
---
def alternatingRed(img):
---
for x in range(0, img.getWidth(), 2):
---
for x in range(img.getWidth()): #paired
---
for y in range(0, img.getHeight(), 2):
---
for y in range(img.getHeight()): #paired
---
p = img.getPixel(x,y)
---
p.setRed(0)
---
img.updatePixel(p)
---
win = ImageWin(img.getWidth(), img.getHeight())
img.draw(win)
Create a function changeQuadrantColors(img) that only changes the color of the pixels in the bottom left quadrant of the image img. The code should set the red value to the original blue value, the green value to the original red value, and the blue value to the original green value.
from image import *
---
def changeQuadrantColors(img):
---
halfWidth = (int) (img.getWidth() / 2)
halfHeight = (int) (img.getHeight() / 2)
---
for x in range(halfWidth):
---
for y in range(halfHeight, img.getHeight()):
---
for y in range(halfHeight): #paired
---
p = img.getPixel(x, y)
---
r = p.getRed()
g = p.getGreen()
b = p.getBlue()
---
newPixel = Pixel(b, r, g)
---
img.setPixel(x, y, newPixel)
---
win = ImageWin(img.getWidth(), img.getHeight())
img.draw(win)
Write a function changeQuadrantColors(img) that only changes the color of the pixels in the bottom left quadrant of the image img. The code should set the red value to the original blue value, the green value to the original red value, and the blue value to the original green value.
from image import *
---
def copyRightSide(img):
---
halfway = (int) (img.getWidth() / 2)
---
for x in range(halfway, img.getWidth()):
---
for x in range(halfway): #paired
---
for y in range(img.getHeight()):
---
p = img.getPixel(x, y)
---
img.setPixel(x - halfway, y, p)
---
img.setPixel(halfway + x, y, p) #paired
---
win = ImageWin(img.getWidth(), img.getHeight())
img.draw(win)
from image import *
---
def copyTopQuarter(img):
---
quarterHeight = (int) (img.getHeight() / 4)
---
for x in range(img.getWidth()):
---
for y in range(quarterHeight):
---
p = img.getPixel(x, y)
---
img.setPixel(x, quarterHeight * 3 + y, p)
---
win = ImageWin(img.getWidth(), img.getHeight())
img.draw(win)