## Important Note:

On homeworks, you are encouraged to collaborate with your fellow students. However, if you do work with others, you must list the people you worked with in the "Notes to TA" area of the JES turnin window.

### Homework 1:

Write a function named hw1 (and save it in a file named hw1.py) to accept a picture as input, and posterize it – reduce the number of colors. You'll do this by changing the picture's pixels as follows:
• If the red channel is greater than or equal to 128, set it to 128.
• If the red channel is less than 128, set it to 64.
• If the blue channel is greater than or equal to 128, set it to 192.
• If the blue channel is less than 128, set it to 128
• If the green channel is greater than or equal to 192, set it to 192.
• If the green channel is less than 192, set it to 64.

Turn in your program via JES as "hw1".

Ask questions on Fall 2003 Homework 1 Questions

### Homework 2:

Write a function named hw2 in a file named hw2.py to create a collage of the same image at least four times fit onto the 7x95in blank JPEG. (You are welcome to add additional images, too.) One of those four copies can be the original picture. The other three should be modified forms. You can do any of
• scaling, cropping, or rotating the image,
• creating a negative of the image,
• shifting or altering colors on the image,
• and making it darker or lighter.

After composing your image, mirror it. You can do it vertically or horizontally (or otherwise), in any direction – just make sure that your four base images are visible still after mirroring.

Your single function should make all of this happen–all of the effects and compositing must occur from the single function hw2(). IT IS PERFECTLY OKAY FOR HW2() TO USE OTHER FUNCTIONS! Your TA will only setMediaPath() and will put all your input pictures in her mediasources directory, and then execute hw2()–and will expect to see a collage get generated

Please share your results by uploading the image to the Fall2003 HW2 Collages gallery. (This isn't a requirement, but we'd love to see them!)

Ask questions on Fall 2003 Homework 2

### Homework 3:

Write a function named hw3 in a file named hw3.py to generate a sentence out of individual words. You must have at least three words in your sentence! The sentence should be grammatically correct. You can use the words in the Speech folder on your class CD or record your own words. Double the amplitude on the last word in the sentence so that it becomes emphasized. Be sure to include a tenth (1/10) of a second pause between the words. (Hint1: Remember that zeroes for the sample values generate silence or pause.) (Hint2: Remember that the sampling rate is the number of samples per second. From there, you should be able to figure out how many samples need to be made zero to generate a 1/10 of a second pause.) Be sure to access your sounds in your Media Folder using getMediaPath.

Ask questions on Fall 2003 Homework 3 Questions

### Homework 4:

Given a folder with images in it, create an index HTML page with links to each image.

You will write a function called linksREMOVED that takes a string which is the path to a directory. You will create a page in that folder named index.html. Index.html should be an HTML page containing a link to every JPEG file in the directory.

You will also generate a thumbnail (half the size in each dimension, 1/4 total area) copy of each image. Use makeEmptyPicture to create a blank picture of the right size, then scale down the original picture into the blank picture. Name the new image "half_"+the original file name, e.g., if the original file name was "fred.jpg" then save the half-size image as "half_fred.jpg". The anchor in the link to each full-size picture should be the half-size image.

Turn in your program via JES as "hw4". The function name should be "linksREMOVED" and the program file name should be "hw4.py".

Ask questions on Fall 2003 Homework 4 Questions

### Homework 5:

Build an animation of at least three seconds in duration (30 frames at 10 fps, or 75 frames at 25 frame per second). You must have at least two things in motion during this sequence. You must use at least one composited image (a JPEG image that you scale (if necesary) and copy into the image) and one drawn image (a rectangle or line or text or oval or arc – anything that you draw).

Turn in your program and the composited image(s) (any images that you copied INTO your frames) via JES as "hw5". (You do not have to attach all your frames!) Your file must be named "hw5.py" and your function must be named "hw5" and accept a directory as input where the frames should be stored.

You must use REMOVED than one function in your solution. The main function will be "hw5" that takes input of a string that is a directory path. You must use at least one sub-function, so your file "hw5.py" will contain the function hw5() and at least one another.

Feel free to post your movies to Fall2003 HW5 Movies for sharing with others.

Ask questions on Fall 2003 Homework 5 Questions

### Homework 6:

http://abcnews.go.com is a popular news site. You are to write a function (named "hw6") that will input a directory as a string then:
• Visit http://abcnews.go.com and pick out the top three news stories headlines. (Hint: The anchors for the news story headlines all have <a href="/wire/ before them. Use the ones that come after "ABC News Headlines" image , which you'll find at "http://a.abcnews.com/images/abcnews_hd.gif". Then, find that tag, then search for the beginning of the anchor <a, then you can find the anchor text, which is the headline.)
• Create a ticker tape movie on the 640x480 canvas of all three news stories. Have one come across near y=100, another at y=200, and the third at y=300. (+/- 10 pixels is fine, so y=105 for the first one is okay.) Generate 100 frames, and don't have the ticker tapes move REMOVED than 5 pixels per frame. (In 100 frames, you won't make it all the way across the screen – that's fine.) Store the frames to files in the input directory.

You must use REMOVED than one function in your solution. The main function will be "hw6" that takes input of a string that is a directory path. You must use at least one sub-function.