Write a general crop function that takes a source picture, the start X value, the start Y value, the end X value, and the end Y value. Create and return the new picture and copy just the specified area into the new picture.

What will be an ideal response?


```
def crop (src, x1, y1, x2, y2):
w = getWidth(src)
h = getHeight(src)
canvas = makeEmptyPicture(x2-x1,y2-y1)
for x in range(x1, x2):
for y in range(y1,y2):
p = getPixel(canvas, x-x1, y-y1)
p2 = getPixel(src, x, y)
color = getColor(p2)
setColor(p, color)
return canvas
```

Note: The important lines here are to make sure that you grab from the correct pixels from the canvas. Grabbing the pixels “x” and “y” will not work, as they may be larger than the canvas you’re copying to.

Computer Science & Information Technology

You might also like to view...

Which of the following is not a JavaScript keyword?

a) break b) delete c) sub d) function

Computer Science & Information Technology

The summary of changes in the Reviewing Pane shows only insertions and deletions.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

A computer program is an example of _____.

a. a device b. software c. hardware d. an operating system

Computer Science & Information Technology

When using more than one adjustment layer, you can ____________________ the layers down once you are satisfied with the results.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology