Download presentation
Presentation is loading. Please wait.
1
Picture Functions ppp =makePicture(pickAFile())
ppp.getWidth(), ppp.getHeight() xxx=ppp.getPixel( , ) xxx.getColor(), .getRed(), .getGreen(), .getBlue() xxx.setColor(), .setRed(), .setGreen(), .setBlue() makeColor(), pickAColor() setMediaPath() – fix a path to media files getMediaPath(filename) file = makeEmptyPicture(100,100) – creates a blank picture of size 100x100 writePictureTo(file, “100x100.jpg”) – save file with name “100x100.jpg”
2
Copy to a blank canvas Download and targetX = sourceX targetY = sourceY sourceX sourceY flower1 canvas
3
Picture Copy Function picCopy() with a picture into a larger canvas
Convert the copying operation below to picCopy() and main() pict = makePicture(pickAFile()) # flower1.jpg canvas = makeEmptyPicture(1000,800) hgt = pict.getHeight() wid = pict.getWidth() repaint(canvas) def picCopy(fPic, tPic, fx, fy): return canvas # main() pict = makePicture(pickAFile()) # flower1.jpg canvas = makeEmptyPicture(1000,800) picCopy(pict, canvas, 0, 0) repaint(canvas)
4
Copy flower2 targetX = sourceX + getWidth(flower1) targetY = sourceY
5
Making a collage Given a blank canvas
Copy flower1 at upper left corner of canvas Copy flower2 next Copy negated flower1 Copy flower2 with blue removed Copy flower1, negated and red reduced
6
Put them together #First picture, at left edge targetX=1
for sourceX in range(1, getWidth(flower1)): targetY=1 for sourceY in range(1,getHeight(flower1)): px=getPixel(flower1,sourceX,sourceY) canvas_x=getPixel(canvas,targetX,targetY) setColor(canvas_x,getColor(px)) targetY=targetY + 1 targetX=targetX + 1 #Second picture, 100 pixels over targetX= getWidth(flower1) # 100 for sourceX in range(1,getWidth(flower2)): targetY= 1 for sourceY in range(1,getHeight(flower2)): px=getPixel(flower2,sourceX,sourceY) canvas_x=getPixel(canvas,targetX,targetY) setColor(canvas_x,getColor(px)) targetY=targetY + 1 targetX=targetX + 1
7
Collage: Code def createCollage():
flower1=makePicture(getMediaPath("flower1.jpg")) print flower1 flower2=makePicture(getMediaPath("flower2.jpg")) print flower2 canvas=makePicture(getMediaPath("640x480.jpg")) print canvas #First picture, at left edge targetX=1 for sourceX in range(1,getWidth(flower1)): targetY=1 for sourceY in range(1,getHeight(flower1)): px=getPixel(flower1,sourceX,sourceY) cx=getPixel(canvas,targetX,targetY) setColor(cx,getColor(px)) targetY=targetY + 1 targetX=targetX + 1 #Second picture, 100 pixels over targetX=100 for sourceX in range(1,getWidth(flower2)): for sourceY in range(1,getHeight(flower2)): px=getPixel(flower2,sourceX,sourceY) #Third picture, flower1 negated negative(flower1) targetX=200 for sourceX in range(1,getWidth(flower1)): targetY=1 for sourceY in range(1,getHeight(flower1)): px=getPixel(flower1,sourceX,sourceY) cx=getPixel(canvas,targetX,targetY) setColor(cx,getColor(px)) targetY=targetY + 1 targetX=targetX + 1 #Fourth picture, flower2 with no blue clearBlue(flower2) targetX=300 for sourceX in range(1,getWidth(flower2)): targetY= 1 for sourceY in range(1,getHeight(flower2)): px=getPixel(flower2,sourceX,sourceY) #Fifth picture, flower1, negated with decreased red ……. show(canvas) return(canvas)
8
General picCopy() If we had a general picCopy(pic, targetPic, targetX, targetY) createCollage() picCopy(flower1, canvas, 0, 0) picCopy(flower2, canvas, getWidth(flower1), 0) picCopy(negate(flower1), canvas, getWidth(flower1) + getWidth(flower2), 0) picCopy(clearBlue(flower2), canvas, getWidth(flower1)*2 + getWidth(flower2), 0) picCopy(reduceRed(negate(flower1)), canvas, getWidth(flower1)*2 + getWidth(flower2)*2, 0)
9
Encapsulation Once picCopy(pic, targetPic, targetX, targetY) is written View a collage A collection of high-level picture manipulation Don’t worry about the details of negate, reduceRed, etc. In cooking recipe, Do not worry about how wheat is processed into flour, … Encapsulation -> Information Hiding
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.