| CS321 -- Lab 4: Lines and Color |
|
|
PurposeThe purpose of this lab is to develop the ability to implement low-level graphics algorithms. AcknowledgementThis lab was developed by Dr. Henry Welch. General Lab InformationIt is now time to add more functionality to our graphical system. Specifically, we will be adding color and the ability to draw lines. Update your button pressing code so that the left mouse button defines lines (e.g., press for the start and release for the end) and the right mouse button defines points. This does present a bit of a coding challenge since the press and release come from different events and the one has to know about the other. In general it is better to use static local variables to the member function than use a data member to this class that is accessible to the other member functions; however, if more than one Shell object exists then their member functions would all share the same static local variable. (You may want to experiment with pressing or releasing outside of the drawing window to see what happens.) For an additional challenge use the motion event to "draw" the line in progress; although this is not a requirement. Develop a line class that is derived from shape so that you can store both the points and lines in the same image object. In addition add a line drawing (end points) command to the command line parser and be sure to document all of these changes in your help text routine. Also you will need to enter a color command to the command line parser that either accepts RGB values, uses one of the standard X color names from the standard list in the file /usr/lib/X11/rgb.txt, or uses the QColorDialog. Once a new color is selected, all subsequent shapes should appear in that color until a new and valid color command is entered. During an exposure redraw each shape should appear in the color in which it was first drawn so you will need to save the color information with the shape itself (you will have to modify your point class or derive a new coloredpoint class from it). You must use some caution when working with color. Because X is network aware both the PC and Concord must agree on how colors are being modeled. Each graphics API handles this differently so you need to research the QColor class and color modeling. It is vitally important that when your program is finished using a color (erase or exit) that you deallocate the colors you've used. For your line drawing code you MAY NOT use the predefined methods of QPainter. You MUST implement Bresenham's Line Drawing Algorithm. For future maintainability you may want to give it the same parameter list as the corresponding QPainter call so that it is a simple matter to substitute the standard line drawing method for yours. To help you demonstrate that you have accounted for all the special cases of the Bresenham algorithm a sample data file is provided which draws a graphical asterisk. The file format is 4 integers per line as x y x y for each line. It is perfectly acceptable to modify this file so that your Line::Read and Image::Read methods can use it. There are plenty of areas for extra credit with this assignment; however, you must complete the basic requirements in order to receive the extra credit. (e.g., Dashed lines, anti-aliasing, etc.) Application demonstrationYou should demonstrate the successful operation of your application before or during week 6 lab. Lab report (due 11pm, the day prior to week 6 lab)Your lab report should be self-contained. That is, it should be possible for someone to understand what you did and why without seeing anything other than your report and any previous reports that you have submitted. Your report should include:
As with any report you submit, correct spelling and grammar are required. In addition, your report should be submitted electronically following the Electronic Submission Guidelines. (You may wish to consult the sample report before submitting your report.) Be sure to keep copies of all your files, in case something gets lost. It may be wise to keep a diskette backup as well. If you have any questions, consult the instructor. |
| © 1998-2001 Dr. Christopher C. Taylor | Office: CC-27C | Phone: 277-7339 | Last Updated: May 9, 2001 |
| I am responsible for all content posted on these pages; MSOE is welcome to share these opinions but may not want to. | |||