22#include " BitmapPlusPlus.hpp"
33
44struct Shape {
5+ virtual ~Shape () = default ;
6+
57 int x, y;
68 bmp::Pixel color;
79
8- Shape (int x, int y, bmp::Pixel color) : x(x), y(y), color(color) {}
10+ Shape (int x, int y, bmp::Pixel color) : x(x), y(y), color(color) {
11+ }
912
1013 virtual void draw (bmp::Bitmap &image) = 0;
1114};
1215
1316struct Rectangle : Shape {
1417 int width, height;
1518
16- Rectangle (int x, int y, int w, int h, bmp::Pixel color) : width(w), height(h), Shape(x, y, color) {}
19+ Rectangle (int x, int y, int w, int h, bmp::Pixel color) : width(w), height(h), Shape(x, y, color) {
20+ }
1721
1822 void draw (bmp::Bitmap &image) override {
1923 image.fill_rect (x, y, width, height, color);
@@ -24,7 +28,8 @@ struct Triangle : Shape {
2428 int x2, y2, x3, y3;
2529
2630 Triangle (int x1, int y1, int x2, int y2, int x3, int y3, bmp::Pixel color) : x2(x2), y2(y2), x3(x3), y3(y3),
27- Shape (x1, y1, color) {}
31+ Shape (x1, y1, color) {
32+ }
2833
2934 void draw (bmp::Bitmap &image) override {
3035 image.fill_triangle (x, y, x2, y2, x3, y3, color);
@@ -34,7 +39,8 @@ struct Triangle : Shape {
3439struct Circle : Shape {
3540 int radius;
3641
37- Circle (int x, int y, int radius, bmp::Pixel color) : radius(radius), Shape(x, y, color) {}
42+ Circle (int x, int y, int radius, bmp::Pixel color) : radius(radius), Shape(x, y, color) {
43+ }
3844
3945 void draw (bmp::Bitmap &image) override {
4046 image.fill_circle (x, y, radius, color);
@@ -48,22 +54,21 @@ int main() {
4854 image.clear (background_color);
4955
5056 std::vector<Shape *> shapes
51- {
52- new Rectangle (20 , 20 , 180 , 180 , bmp::Pixel (0xa31d3a )),
53- new Triangle (310 , 20 , 230 , 200 , 400 , 200 , bmp::Pixel (0x1a5096 )),
54- new Circle (500 , 110 , 90 , bmp::Pixel (0x228035 ))
55- };
57+ {
58+ new Rectangle (20 , 20 , 180 , 180 , bmp::Pixel (0xa31d3a )),
59+ new Triangle (310 , 20 , 230 , 200 , 400 , 200 , bmp::Pixel (0x1a5096 )),
60+ new Circle (500 , 110 , 90 , bmp::Pixel (0x228035 ))
61+ };
5662
5763 for (Shape *shape: shapes) {
5864 shape->draw (image);
5965 delete shape;
6066 }
61- image.save (" shapes .bmp" );
67+ image.save (" polymorphic_shapes .bmp" );
6268
6369 return EXIT_SUCCESS;
64- }
65- catch (const bmp::Exception &e) {
70+ } catch (const bmp::Exception &e) {
6671 std::cerr << " [BMP ERROR]: " << e.what () << ' \n ' ;
6772 return EXIT_FAILURE;
6873 }
69- }
74+ }
0 commit comments