Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Canvas.h
- class Canvas
- {
- private:
- // Matrice di punti.
- bool points[24][80];
- public:
- // Costruttore.
- Canvas();
- // Distruttore.
- virtual ~Canvas();
- // Accende un punto ad una determinata coordinata specificata dai parametri.
- void set(int, int);
- // Spegne un punto ad una determinata coordinata specificata dai parametri.
- void reset(int, int);
- // Pulisce il canovaccio;
- void clear();
- // Controlla se un punto è acceso.
- bool isSet(int, int) const;
- };
- // Canvas.cpp
- Canvas::Canvas() : points()
- {
- clear();
- }
- Canvas::~Canvas() {}
- void Canvas::set(int x, int y)
- {
- if (x < 0 || x > 79 || y < 0 || y > 23) return;
- points[y][x] = true;
- }
- void Canvas::reset(int x, int y)
- {
- if (x < 0 || x > 79 || y < 0 || y > 23) return;
- points[y][x] = false;
- }
- void Canvas::clear()
- {
- for (int y = 0; y < 24; ++y)
- for (int x = 0; x < 80; ++x)
- reset(x, y);
- }
- bool Canvas::isSet(int x, int y) const {
- if (x < 0 || x > 79 || y < 0 || y > 23) return false;
- return points[y][x];
- }
- // main
- #include "Canvas.h"
- #include "Shape.h"
- #include "Rectangle.h"
- #include "Square.h"
- #include "Ellipse.h"
- #include "Circle.h"
- void drawShapeOnCanvas(Shape& s, Canvas& c) {
- s.draw(c);
- }
- void printCanvas(Canvas& c) {
- for (int y = 0; y < 24; ++y) {
- for (int x = 0; x < 80; ++x)
- cout << (c.isSet(x, y) ? '*' : ' ');
- cout << endl;
- }
- }
- int main()
- {
- Canvas c;
- c.set(10, 10);
- c.set(30, 15);
- printCanvas(c);
- Rectangle r(4, 4, 20, 15);
- drawShapeOnCanvas(r, c);
- Square s(4, 4, 15);
- drawShapeOnCanvas(s, c);
- Ellipse e(30, 12, 25, 10);
- Circle ci(30, 12, 10);
- drawShapeOnCanvas(e, c);
- drawShapeOnCanvas(ci, c);
- printCanvas(c);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement