I have placed the Templates here as well to help you with the excersises below.
To open a picture and display it on the screen: Template1
To open a picture, display it on the screen, do something to each pixel, show results: Template2
Here are some pictures I used in class. You can right click on them with your mouse to save them on your computer. I suggest you use them as starters, but then try using your own. Remember, these are .jpg images.
color_strip (1px x 6px)
color_lines (10px x 6px)
color_stripes(100px x 120px)
color_flag(180px x 120px)
Here are some problems to try on your own. Don't look at my answers until you have tried your own solution at least twice.
1) Write a function named midGreen that has a picture’s name hardcoded as the variable file; shows the picture in the show box; changes the entire green channel of the picture to equal 128; and repaints the picture. Answer 3.1
2) Write a function named noRed that has the user enter a picture’s name on function call; shows the picture in the show box; changes the entire red channel of the picture to equal 0; and repaints the picture. Answer 3.2
3) Write a function named allBlue that loads a picture from pickAFile ; shows the picture in the picture tool; changes the entire blue channel of the picture to equal 255; and repaints the picture. Answer 3.3
4) Write a function named halfGreen that loads a picture from pickAFile ; shows the picture in the picture tool; changes each pixels green value to half of what it was and repaints the picture. Answer 3.4
5) Write a function named quarterRed that has a picture’s name hardcoded as the variable file; shows the picture in the show box; changes each pixels red value to a quarter of what it was; and repaints the picture. Answer 3.5
6) Write a function named redBlue that has the user enter a picture’s name on function call; shows the picture in the show box; changes the red value of each pixel to equal its blue value; and repaints the picture. Answer 3.6
7) Write a function named blueHalfGreen that has the user enter a picture’s name on function call; shows the picture in the show box; changes the blue value of each pixel to equal half its Green value; and repaints the picture. Answer 3.7
8) Write a function named makeNegative that loads a picture from pickAFile ; shows the picture in the picture tool; changes the color of each pixel to its negative; and repaints the picture. Answer 3.8
9) Write a function named makeBandW that loads a picture from pickAFile ; shows the picture in the picture tool; changes the color picture to black and white; and repaints the picture. Answer 3.9
10) Try making up some functions of your own.
Link to this Page
Spring 2007 materials last edited on 21 August 2007 at 10:44 pm by user-1121vkp.dsl.mindspring.com