CS 345: Spring 2025
Programming Assignment 1
Building Blocks
We are now ready to begin creating our graphics library.
class GCanvas {
public:
virtual ~GCanvas() {}
/**
* Fill the entire canvas with the specified color, using SRC porter-duff mode.
*/
virtual void clear(const GColor&) = 0;
/**
* Fill the rectangle with the color, using SRC_OVER porter-duff mode.
*
* The affected pixels are those whose centers are "contained" inside the rectangle:
* e.g. contained == center > min_edge && center <= max_edge
*
* Any area in the rectangle that is outside of the bounds of the canvas is ignored.
*/
virtual void fillRect(const GRect&, const GColor&) = 0;
};
/**
* Implemnt this, returning an instance of your subclass of GCanvas.
*/
std::unique_ptr<GCanvas> GCreateCanvas(const GBitmap&);
/**
* Implement this, drawing into the provided canvas, and returning the title of your artwork.
*/
std::string GDrawSomething(GCanvas*, GISize dimension);
You have 3 tasks:
- Create a subclass of GCanvas, and override these methods:
- Implement GCreateCanvas to return an instance of your subclass.
- Implement GDrawSomething
- draw something into the canvas
- return a title for your artwork
- Inspirations
The pa1 directory will look 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.
Add your files as needed at the root level (whatever .cpp or .h files you need). e.g.
- my_canvas.cpp
- my_draw_something.cpp
- my_utils.h
To test your code...
> make
> ./image -e expected
> ./tests
> ./bench
> ./dbench
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.01
rects_blend 6.3
rects_opaque 0.66
rect_big 0.35
rect_tiny 0.34