










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Notes; Professor: Mock; Class: Automata, Algorithms, and Complexity; Subject: Computer Science ; University: University of Alaska - Anchorage; Term: Spring 2009;
Typology: Study notes
1 / 18
This page cannot be seen from the preview
Don't miss anything!
**def copyBarb():
barbf=getMediaPath("barbara.jpg") barb = makePicture(barbf) canvasf = getMediaPath("7inX95in.jpg") canvas = makePicture(canvasf)
targetX = 1 for sourceX in range(1,getWidth(barb)): targetY = 1 for sourceY in range(1,getHeight(barb)): color = getColor(getPixel(barb,sourceX,sourceY)) setColor(getPixel(canvas,targetX,targetY), color) targetY = targetY + 1 targetX = targetX + 1 show(barb) show(canvas) return canvas**
What’s this naming something to itself?
Transformation = Small changes in copying
Copying into the middle of the canvas
**def copyBarbMidway():
barbf=getMediaPath("barbara.jpg") barb = makePicture(barbf) canvasf = getMediaPath("7inX95in.jpg") canvas = makePicture(canvasf)
targetX = 100 for sourceX in range(1,getWidth(barb)): targetY = 100 for sourceY in range(1,getHeight(barb)): color = getColor(getPixel(barb,sourceX,sourceY)) setColor(getPixel(canvas,targetX,targetY), color) targetY = targetY + 1 targetX = targetX + 1 show(barb) show(canvas) return canvas**
Copying: How it looks at the end
def createCollage():flower1=makePicture(getMediaPath("flower1.jpg")) print flower1flower2=makePicture(getMediaPath("flower2.jpg")) print flower2canvas=makePicture(getMediaPath("640x480.jpg")) print canvas#First picture, at left edge targetX=1for sourceX in range(1,getWidth(flower1)): targetY=getHeight(canvas)-getHeight(flower1)-5for sourceY in range(1,getHeight(flower1)): px=getPixel(flower1,sourceX,sourceY)cx=getPixel(canvas,targetX,targetY) setColor(cx,getColor(px))targetY=targetY + 1 #Second picture, 100 pixels overtargetX=targetX + 1 targetX=100for sourceX in range(1,getWidth(flower2)): targetY=getHeight(canvas)-getHeight(flower2)-5for sourceY in range(1,getHeight(flower2)): px=getPixel(flower2,sourceX,sourceY)cx=getPixel(canvas,targetX,targetY) setColor(cx,getColor(px))targetY=targetY + 1 targetX=targetX + 1
#Third picture, flower1 negatednegative(flower1) targetX=200for sourceX in range(1,getWidth(flower1)): targetY=getHeight(canvas)-getHeight(flower1)-5for sourceY in range(1,getHeight(flower1)): px=getPixel(flower1,sourceX,sourceY)cx=getPixel(canvas,targetX,targetY) setColor(cx,getColor(px))targetY=targetY + 1 #Fourth picture, flower2 with no bluetargetX=targetX + 1 clearBlue(flower2)targetX= for sourceX in range(1,getWidth(flower2)):targetY=getHeight(canvas)-getHeight(flower2)- for sourceY in range(1,getHeight(flower2)):px=getPixel(flower2,sourceX,sourceY) cx=getPixel(canvas,targetX,targetY)setColor(cx,getColor(px)) targetX=targetX + 1targetY=targetY + 1 #Fifth picture, flower1, negated with decreased reddecreaseRed(flower1) targetX=400for sourceX in range(1,getWidth(flower1)): targetY=getHeight(canvas)-getHeight(flower1)-5for sourceY in range(1,getHeight(flower1)): px=getPixel(flower1,sourceX,sourceY)cx=getPixel(canvas,targetX,targetY) setColor(cx,getColor(px))targetY=targetY + 1 show(canvas)targetX=targetX + 1 return(canvas)
Exactly from book
**def copyBarbSmaller():
barbf=getMediaPath("barbara.jpg") barb = makePicture(barbf) canvasf = getMediaPath("7inX95in.jpg") canvas = makePicture(canvasf)
sourceX = 1 for targetX in range(100,100+(getWidth(barb)/2)): sourceY = 1 for targetY in range(100,100+(getHeight(barb)/2)): color = getColor(getPixel(barb,sourceX,sourceY)) setColor(getPixel(canvas,targetX,targetY), color) sourceY = sourceY + 2 sourceX = sourceX + 2 show(barb) show(canvas) return canvas**
**>>> print int(1) 1
print int(1.5) 1 print int(2) 2 print int(2.5) 2**
Scaling the picture up
**def copyBarbLarger():
barbf=getMediaPath("barbara.jpg") barb = makePicture(barbf) canvasf = getMediaPath("7inX95in.jpg") canvas = makePicture(canvasf)
sourceX = 1 for targetX in range(10,10+(getWidth(barb)2)): sourceY = 1 for targetY in range(10,10+(getHeight(barb)2)): color = getColor(getPixel(barb,int(sourceX),int(sourceY))) setColor(getPixel(canvas,targetX,targetY), color) sourceY = sourceY + 0. sourceX = sourceX + 0. show(barb) show(canvas) return canvas**
Described in the text, but skipping here. Good things to try:
def chromakey2(source,bg): for p in getPixels(source): if (getRed(p)+getGreen(p) < getBlue(p)): setColor(p, getColor(getPixel(bg, getX(p),getY(p)))) return source