Question: I'm creating a collage in JES for a project and it has to have color change, rotations, and flips. When I run my code the

I'm creating a collage in JES for a project and it has to have color change, rotations, and flips. When I run my code the color changes work but the rotations & flips do not.

def swapGreenAndBlue(pic): myPixels = getPixels(pic) for eachPixel in myPixels: g=getGreen(eachPixel) b=getBlue(eachPixel) setGreen(eachPixel,b) setBlue(eachPixel,g) def greyscale(pic): myPixels = getPixels(pic) for eachPixel in myPixels: r = getRed(eachPixel) g = getGreen(eachPixel) b = getBlue(eachPixel) c = (r+g+b) f = (c/3) setRed(eachPixel,f) setGreen(eachPixel,f) setBlue(eachPixel,f) def flipTopBottom(pic): w=getWidth(pic) h=getHeight(pic) newpic=makeEmptyPicture(w,h) for col in range(0,w): for row in range(0,h): newPixel=getPixel(newpic,col,row) oldPixel=getPixel(pic,col,h-1-row) color=getColor(oldPixel) setColor(newPixel,color) def rotate90CC(pic): canvas = makeEmptyPicture(getHeight(pic),getWidth(pic)) targetX = 0 width = getWidth(pic) for sourceX in range(0,getWidth(pic)): targetY = 0 for sourceY in range(0,getHeight(pic)): color = getColor(getPixel(pic,sourceX,sourceY)) setColor(getPixel(canvas,targetY,width - targetX - 1), color) targetY = targetY + 1 targetX = targetX + 1 def rotate90Clockwise(pic): canvas = makeEmptyPicture(getHeight(pic),getWidth(pic)) targetX = 0 height=getHeight(pic) for sourceX in range(0,getWidth(pic)): targetY = 0 for sourceY in range(0,getHeight(pic)): color = getColor(getPixel(pic,sourceX,sourceY)) setColor(getPixel(canvas,height-targetY-1,targetX),color) targetY = targetY + 1 targetX = targetX + 1 ########################################################################### def makeCollage(): pic=makePicture(pickAFile()) canvas=makeEmptyPicture(getWidth(pic)*3,getHeight(pic)*2) w1 = getWidth(pic) h1 = getHeight(pic) w2 = getWidth(canvas) h2 = getHeight(canvas)

#picture will have green and blue values swapped and placed in top left corner picA=makePicture(pickAFile()) swapGreenAndBlue(picA) startX=0 for col in range(0,w1): startY=0 for row in range(0,w1): picPixel = getPixel(picA,col,row) canvasPixel = getPixel(canvas,col+startX,row+startY) setColor(canvasPixel,getColor(picPixel))

#picture will be flipped vertically and placed in top middle picB=makePicture(pickAFile()) flipTopBottom(picB) startX=w1 for col in range(0,w1): startY=0 for row in range(0,w1): picPixel = getPixel(picB,col,row) canvasPixel = getPixel(canvas,col+startX,row+startY) setColor(canvasPixel,getColor(picPixel)) #picture will be greyscaled, rotated 90 degrees clockwise, and placed in top right corner picC=makePicture(pickAFile()) greyscale(picC) rotate90Clockwise(picC) startX=w1*2 for col in range(0,w1): startY=0 for row in range(0,w1): picPixel = getPixel(picC,col,row) canvasPixel = getPixel(canvas,col+startX,row+startY) setColor(canvasPixel,getColor(picPixel))

#picture will be greyscaled, rotated 90 degrees counterclockwise, and placed in bottom left corner picD=makePicture(pickAFile()) greyscale(picD) rotate90CC(picD) startX=0 for col in range(0,w1): startY=h1 for row in range(0,w1): picPixel = getPixel(picD,col,row) canvasPixel = getPixel(canvas,col+startX,row+startY) setColor(canvasPixel,getColor(picPixel)) #original picture placed in bottom middle picE=makePicture(pickAFile()) startX=w1 for col in range(0,w1): startY=h1 for row in range(0,w1): picPixel = getPixel(picE,col,row) canvasPixel = getPixel(canvas,col+startX,row+startY) setColor(canvasPixel,getColor(picPixel)) #picture will have green and blue values swapped and placed in bottom right corner picF=makePicture(pickAFile()) swapGreenAndBlue(picF) flipTopBottom(picF) startX=w1*2 for col in range(0,w1): startY=h1 for row in range(0,w1): picPixel = getPixel(picF,col,row) canvasPixel = getPixel(canvas,col+startX,row+startY) setColor(canvasPixel,getColor(picPixel)) show(canvas) return canvas

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!