Assignment 1 - ImageMaker F2020
Assignment 1 - ImageMaker F2020
In this assignment, you will make a class that create a ppm image using basic drawing methods. In
addition, you will make a driver that can be used to help test the functionality of the class. BE SURE TO
READ THE DELIVERABLES!
RGB Format
P3
4 4
255
0 0 0 200 0 0 0 0 0 155 0 155
0 0 0 0 155 175 0 0 0 0 0 0
0 0 0 0 0 0 0 100 175 0 0 0
255 255 255 0 0 0 0 0 0 155 155 155
The first three lines defines the image header. P3 indicates that the image will use RGB color. The
second line indicates width and height. The 255 indicates the maximum value for the color. In the
example above colors are between 0-255. Read the following wiki-link for additional details:
https://en.wikipedia.org/wiki/Netpbm_format
Coordinate System
Unlike in math, the standard coordinate system for images starts in the upper left hand corner.
Class Definition
The following is the class definition:
class ImageMaker
{
public:
ImageMaker();
ImageMaker(string filename);
// Size functions
int GetWidth();
int GetHeight();
void SetWidth(int width);
void SetHeight(int height);
// Color functions
int GetPenRed();
int GetPenGreen();
int GetPenBlue();
void SetPenRed(int newR);
void SetPenGreen(int newG);
void SetPenBlue(int newB);
// Drawing methods
// These methods will use the current red, green, blue values of the pen
void DrawPixel(int x, int y);
void DrawRectangle(int x1, int y1, int x2, int y2);
void DrawLine(int x1, int y1, int x2, int y2);
private:
int width;
int height;
int pen_red; // Used by draw functions
int pen_green; // Used by draw functions
int pen_blue; // Used by draw functions
short image[MAX_WIDTH][MAX_HEIGHT][3];
};
Before you start looking at how to implement this class, you must determine and document the
appropriate preconditions and postconditions for each operation (See page 139 for examples or
preconditions and postconditions).
Constructor
There are two constructors. The default constructor should create an image with 0 width and 0 height,
and set the initial pen color to black (255, 255, 255). The second constructor should load a ppm image
into the image matrix and set the width and height accordingly; the default color should be set to black.
Draw Functions
All draw functions should throw an error if out of bounds values are given. All draw functions use the
current pen_red, pen_green and pen_blue values as the “pen” color when drawing.
DrawPixel colors the coordinate (x, y) using the current values of the pen_red, pen_green, and
pen_blue.
DrawRectangle draws a rectangle using the current values of pen_red, pen_green, and pen_blue.
(x1, y1)
(x2, y2)
DrawLine draws a rectangle using the current values of the red, green, and blue. Suppose
(3,2)
(6,4)
To figure out the values for y, you will need to figure out the line y = mx + b. In this case, it would be
b = y1 – m*x1 = 2 – 0.66667*3 = 0
y = 0.666667x + 0
With this formula, you can figure out the y values for x = 3 … 6.
Note that for x = 4
y = 0.66667*4 + 0 = 2.666667
Since there is no pixel for (4, 2.666667), we can just round the y coordinate and use the coordinate (4, 3)
instead.
Notes
1. The Load function should throw an error if file is not formatted correctly. The test driver must
be able to catch these errors and continue. Be sure to refer to examples given in class.
2. Be sure to refer to the other test driver examples
3. The ImageMaker class must throw an error if bad input is given. The test driver must be able to
catch these errors and continue. Be sure to refer to examples given in class.
4. Clarity and formatting will be counted as part of the grade.
5. Pre and post conditions should be included for each method.
Deliverables
• Your ImageMaker class
• Your test driver class
• Your test plan as input to the test driver (See page 125 for an example)
(THE TEST PLAN IS NOT TRIVIAL AND A SUBSTATIAL PART OF THE GRADE)
• The input files used with your test driver
• The output files from the test driver
Extra Credit Opportunities
Extra credit is generally available for all my projects. More difficult extensions receive more points. The
following are some ideas for extensions that can be done for extra credit. Points are additive (more
features, more points).
Extra credit awarded depending how difficult the drawing method or feature is. For example, a
DrawTriangle would have a relatively low extra credit. A filled rectangle would get slightly more points.
Additional Notes and Questions
Stack overflow error for Visual Studio
If you encounter a stack over flow error, it means you need to increase the size of the stack memory
used for the program. The following increases the size of the stack to 4mb, which should be large
enough to handle most situations for this class.