#returns copy of picture at 50% scale def scale_half(pic): w=getWidth(pic) h=getHeight(pic) pic2=makeEmptyPicture(w/2,h/2) for px in getPixels(pic2): x=getX(px) y=getY(px) sourcepx=getPixel(pic,2*x ,2*y ) c=getColor(sourcepx) setColor(px,c) return pic2 #returns copy of picture at 200% scale def scale_double(pic): w=getWidth(pic) h=getHeight(pic) pic2=makeEmptyPicture(2*w ,2*h ) for px in getPixels(pic2): x=getX(px) y=getY(px) sourcepx=getPixel(pic,(x+1)/2 ,(y+1)/2 ) c=getColor(sourcepx) setColor(px,c) return pic2 #the demo selects a picture, displays several #successive reductions, and then several successive #enlargements. def scale_demo(): p=makePicture(pickAFile()) show(p) p=scale_half(p) show(p) p=scale_half(p) show(p) p=scale_half(p) show(p) p=scale_double(p) show(p) p=scale_double(p) show(p) p=scale_double(p) show(p)