def collage(p): w=getWidth(p) h=getHeight(p) p2=makeEmptyPicture(w,h) #this will paint p2 with four #half-sized views of the original #picture: the picture itself, #a grayscale image, a negative #grayscale image, and a "posterized" #color version that uses a small #palette of colors. for x in range(1,w/2): for y in range(1,h/2): px=getPixel(p,2*x,2*y) r=getRed(px) g=getGreen(px) b=getBlue(px) c=getColor(px) #paint upper left original color px1=getPixel(p2,x,y) setColor(px1,c) #paint upper right grayscale of original color av=(r+g+b)/3 gs=makeColor(av,av,av) px2=getPixel(p2,w/2+x,y) setColor(px2,gs) #paint lower left negative grayscale of original color px3=getPixel(p2,x,h/2+y) ngs=makeColor(255-av,255-av,255-av) setColor(px3,ngs) #paint lower right posterized color g=255*((127+g)/255) b=255*((127+b)/255) r=255*((127+r)/255) px4 = getPixel(p2,w/2+x,h/2+y) setColor(px4,makeColor(r,g,b)) return p2