Docsity

Assignment 2 | Introduction to Computer Graphics | 22C 151, Assignments of Computer Graphics

Toggle sidebar
bg1
Fall 2006
22C:151 Introduction to Computer Graphics
Assignment 2
Due: Wednesday September 6th at 11:59pm
Goal: Write a program that rasterizes lines (using the Bresenham/midpoint algorithm) and outputs them to PPM files.
Write a second program that draws the same lines using OpenGL and GLUT.
Problem 1 (10 points): (8 points) Write a program that rasterizes the following lines (using the Bresenham
algorithm) into a 512 ×512 buffer (in memory), and output the result to a PPM file. The background should be black
(i.e., RGB = [0,0,0]). Use a utility program to convert the PPM file to GIF, PNG or BMP to display on your web page
(e.g., use ppmtogif,ppmtobmp, or xv on Linux systems or GIMP on Windows systems). To reduce data-entry time,
these points are available online in an electronic format. (Note: This program should not use OpenGL.)
•Red lines: (1,1)→(1, 510), (1,510)→(510,510), (510,510)→(510,1), (510,1)→(1,1)
•Green lines: (32,500)→(82,475), (30,396)→(90,415), (82,475)→(30,396)
•Purple (red + blue) lines: (100,420)→(147,427), (104,366)→(149,368), (102,324)→(150,300), (102,324)→(104,366),
(147,427)→(149,368)
•Blue lines: (176,340)→(223,341), (176,340)→(185,228), (237,240)→(185,228)
•White lines: (250,300)→(250,280), (248,240)→(253,220)
•Yellow (red + green) lines: (293,249)→(307,286), (307,286)→(307,144), (264,145)→(347,148)
•Cyan (green + blue) lines: (415,251)→(371,233), (371,233)→(376,201), (376,201)→(431,151), (431,151)→(368,102)
•Orange (red + 0.5∗green) lines: (444,174)→(474,179),(474,179)→(442,38),(391,38)→(493,45)
(2 points) In a second 512 ×512 image, draw the same lines, but change colors gradually from one end to the
other. For example, draw the line from (1,1) to (1, 510) starting at red and gradually blending to green at (1, 510). I
want you to think about and come up with a blending method on your own. There is no right or wrong way to blend
here, as long as the color varies gradually over the line. Make sure to use contrasting colors at the endpoints (white &
black, red & green, yellow & blue, etc.)
Problem 2 (10 points): (5 points) Write an OpenGL/GLUT program that draws the same lines as in Problem 1
(using the same colors). Using a keyboard callback, allow the user to switch back and forth between the solid lines
(glShadeModel(GL FLAT);) and those with gradually varying colors (glShadeModel(GL SMOOTH);) by
hitting the key ’c’. Capture the result in an image and post on your web page. Make sure to label your images, so I
know which is from Problem 1 and which is from Problem 2.
(5 points) Allow the user to draw an additional line by clicking the right mouse button at the two endpoints.
Extra Credit (2 points): Using code from Problem 2, write an OpenGL-based program that displays and updates
the current time (i.e., a clock).

Partial preview of the text

Download Assignment 2 | Introduction to Computer Graphics | 22C 151 and more Assignments Computer Graphics in PDF only on Docsity!

Fall 2006

22C:151 Introduction to Computer Graphics

Assignment 2

Due: Wednesday September 6th at 11:59pm

Goal: Write a program that rasterizes lines (using the Bresenham/midpoint algorithm) and outputs them to PPM files. Write a second program that draws the same lines using OpenGL and GLUT.

Problem 1 (10 points): (8 points) Write a program that rasterizes the following lines (using the Bresenham algorithm) into a 512 × 512 buffer (in memory), and output the result to a PPM file. The background should be black (i.e., RGB = [0,0,0]). Use a utility program to convert the PPM file to GIF, PNG or BMP to display on your web page (e.g., use ppmtogif , ppmtobmp , or xv on Linux systems or GIMP on Windows systems). To reduce data-entry time, these points are available online in an electronic format. (Note: This program should not use OpenGL.)

  • Red lines: (1,1)→(1, 510), (1,510)→(510,510), (510,510)→(510,1), (510,1)→(1,1)
  • Green lines: (32,500)→(82,475), (30,396)→(90,415), (82,475)→(30,396)
  • Purple (red + blue) lines: (100,420)→(147,427), (104,366)→(149,368), (102,324)→(150,300), (102,324)→(104,366), (147,427)→(149,368)
  • Blue lines: (176,340)→(223,341), (176,340)→(185,228), (237,240)→(185,228)
  • White lines: (250,300)→(250,280), (248,240)→(253,220)
  • Yellow (red + green) lines: (293,249)→(307,286), (307,286)→(307,144), (264,145)→(347,148)
  • Cyan (green + blue) lines: (415,251)→(371,233), (371,233)→(376,201), (376,201)→(431,151), (431,151)→(368,102)
  • Orange (red + 0. 5 ∗green) lines: (444,174)→(474,179),(474,179)→(442,38),(391,38)→(493,45)

(2 points) In a second 512 × 512 image, draw the same lines, but change colors gradually from one end to the other. For example, draw the line from (1,1) to (1, 510) starting at red and gradually blending to green at (1, 510). I want you to think about and come up with a blending method on your own. There is no right or wrong way to blend here, as long as the color varies gradually over the line. Make sure to use contrasting colors at the endpoints (white & black, red & green, yellow & blue, etc.)

Problem 2 (10 points): (5 points) Write an OpenGL/GLUT program that draws the same lines as in Problem 1 (using the same colors). Using a keyboard callback , allow the user to switch back and forth between the solid lines (glShadeModel(GL FLAT);) and those with gradually varying colors (glShadeModel(GL SMOOTH);) by hitting the key ’ c ’. Capture the result in an image and post on your web page. Make sure to label your images, so I know which is from Problem 1 and which is from Problem 2.

(5 points) Allow the user to draw an additional line by clicking the right mouse button at the two endpoints.

Extra Credit (2 points): Using code from Problem 2, write an OpenGL-based program that displays and updates the current time (i.e., a clock).