CS 345: Spring 2025
Programming Assignment 2
Poly want a Pixel
Rectanges, lovely as they are, can get boring. Time to draw arbitrary (convex) shapes!
class GPaint ...
enum class GBlendMode ...
class GCanvas {
public:
...
virtual void drawRect(const GRect&, const GPaint&) = 0;
/**
* Fill the convex polygon with the color, following the same "containment" rule as
* rectangles.
*/
virtual void drawConvexPolygon(const GPoint[], int count, const GPaint&) = 0;
};
You task is to extend the subclass of GCanvas you created in PA1...
- Use GPaint instead of GColor for the drawing methods
- Support all of the GBlendModes defined in GPaint.h
- Rename fillRect --> drawRect
- Override drawConvexPolygon
- Update your GDrawSomething(...) to take advantage of polygons
The pa2 directory should like something like this:
- apps contains the code for testing your code.
- expected contains sample output from the image tool to compare with your output.
- include contains class headers that your code can use.
- src contains common implementations needed for the tools.
- DO NOT EDIT/ADD/REMOVE anything in these sub-directories. You should only add files to the root of the directory.
- your_files any .cpp or .h files you need for your implementation. All of your work must be here.
To test your code...
> make
> ./image -e expected
> ./tests
> ./bench
> ./dbench (just run this to be sure it doesn't crash)
For more details when testing...
> mkdir diff
> ./image -e expected -d diff
> open diff/index.html
>
> ./tests -v
>
> ./bench -m substring-to-match
Bench scores on the VM
clear 2.41
rects_blend 6.57
rects_opaque 0.88
rect_big 0.45
rect_tiny 0.44
quads_blend 6.92
quads_opaque 1.08
circles_large 3.4
circles_tiny 0.46
modes_0 1.45
modes_x 25.05
modes_1 13.57