- C++ 98.2%
- Makefile 1.8%
| inc | ||
| proposal | ||
| samples | ||
| src | ||
| .gitignore | ||
| Makefile | ||
| README.md | ||
ShapeDrawer9001
High tech program that takes a file containing a list of shapes and outputs a bitmap rendering.
The original proposal is located in proposal/
Notable deviations from proposal
- FileWriter
write()ended up containing a lot of duplicate code between the different file formats, so I decided to write a singlewrite()function that handles everything except writing the pixel data, and then instead defined awritePixel()abstract function which each filetype overrides with it's own definition.
- Added a
blendColor()function to increase readability of lines withsetPixel() - ShapesList
- The standard forward_list implementation required a custom tail iterator, which required rebuilding to ensure that it was still valid. This was done by traversing the list, which is slow and bad, especially since it was already in a for loop during parsing. This makes parsing files O(n) instead of O(n^2).
Notable deviations from style guidelines
using namespace std;
This works fine for smaller programs, but in larger projects this tends to lead to namespace collisions. It also self-documents where a function came from when you use "std::func".
Single class per file
In this project, I put classes into header files by hierarchy. The three shape classes are fairly small and always used together, so it didn't make sense to split them up.
FileWriter was done for similar reasons.
Compilation
Requirements:
- An OS that can execute ELF files
- A compiler with C++17 support and a standard library implementing:
- string
- cstdint
- fstream
- sstream
- forward_list
- iostream
- cmath
- algorithm
make will generate bin/shapedrawer9001
Usage
shapedrawer9001 file1 [file2... ] output
If your computer does not have an image viewer which can view PPM/PGM files directly, ImageMagick convert on Linux can convert PPM/PGM files to PNG (or many other formats).
magick convert $INPUT.ppm $OUTPUT.png