Write a function to interleave two pictures taken as input. Take the first 20 pixels from the first picture and then 20 pixels from the second picture and then the next 20 pixels from the first picture and then the next 20 pixels from the second picture and so on till all the pixels have been used.

What will be an ideal response?


```
def interleavePictures(pic, picTwo):
numPixels = 0

for px in getPixels(pic):
numPixels = numPixels +1
x = getX(px)
y = getY(px)
val = numPixels/20

if val%2 ==1:
secondPx = getPixel(picTwo, x, y)
pxcol = getColor(secondPx)
setColor(px,pxcol)
```

Note: There are many different ways to accomplish the interleaving. The important thing is that the switch occurs every 20 pixels, not how it occurs. One possibility is to track which of the two pictures the function pulls from at any moment, such as:

```
def interleavePictures(pic, picTwo):
numPixels = 0
currentPicture = 1
for px in getPixels(pic):
numPixels = numPixels +1
x = getX(px)
y = getY(px)

if numPixels ==20:
if currentPicture==1:
currentPicture = 2
elif currentPicture==2:
currentPicture = 1
numPixels = 0

if currentPicture==2:
secondPx = getPixel(picTwo, x, y)
pxcol = getColor(secondPx)
setColor(px,pxcol)
```

Computer Science & Information Technology

You might also like to view...

Write a complete Java applet that displays the phrase “Welcome to my world!” in the center of the applet.

What will be an ideal response?

Computer Science & Information Technology

After the following program is finished, how many bytes are written to the file t.dat?

``` import java.io.*; public class Test { public static void main(String[] args) throws IOException { DataOutputStream output = new DataOutputStream( new FileOutputStream("t.dat")); output.writeUTFString("ABCD"); output.close(); } } ``` a. 2 bytes. b. 4 bytes. c. 6 bytes. d. 8 bytes. e. 10 bytes.

Computer Science & Information Technology

To insert a comment into a cell, you click New Comment in the ________

A) Comments group on the REVIEW tab B) Comments group on the INSERT tab C) Documentation group on the REVIEW tab D) Documentation group on the INSERT tab

Computer Science & Information Technology

Which of the following can be an STP cable?

A) RG-6 B) RG-59 C) Fiber D) CAT5e

Computer Science & Information Technology