Write a general scaleDown function that takes in any picture and creates and returns a new picture half as big using makeEmptyPicture(width,height).

What will be an ideal response?


```
def scaleDown (src):
w = getWidth(src)
h = getHeight(src)
canvas = makeEmptyPicture(w/2,h/2)
sourceX = 0.0
for targetX in range(0, int(w/2)):
sourceY = 0.0
for targetY in range(0,int(h/2)):
px = getPixel(src,int(sourceX),int(sourceY))
color = getColor(px)
setColor(getPixel(canvas ,int(targetX) ,int(targetY)), color)
sourceY = sourceY + 2
sourceX = sourceX + 2
return canvas
```

Note: The only differences between this function and the previous one is to increment by 2 instead of 0.5 and to change the canvas size and range sizes to half.

Computer Science & Information Technology

You might also like to view...

Sum, Count, and Avg are all examples of aggregate functions

Indicate whether the statement is true or false

Computer Science & Information Technology

Using a touchscreen, which of the following actions is the same as right-clicking the mouse?

A) Press and hold for a few seconds B) Touch the screen with two fingers C) Slide right D) Slide right and then press

Computer Science & Information Technology

In a stack overflow, what is overwritten by the overflow?

A. Nothing is overwritten in a stack overflow. B. The root password is overwritten in a stack overflow. C. The return address in a stack is overwritten in a stack overflow. D. The whole memory is overwritten in a stack overflow.

Computer Science & Information Technology

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

1. In pseudocode, the DOUNTIL statement is positioned after the loop steps. 2. The steps within a DOUNTIL loop are always placed on the line after DOUNTIL and are indented a few positions for clarity. 3. A DOUNTIL loop cannot be used if automatic end-of-file processing is needed to control the loop. 4. In header record logic the DOUNTIL loop is not controlled by a counter as it is with a DOWHILE loop. 5.The READ statement used to input the header record must be placed before the DOUNTIL loop test.

Computer Science & Information Technology