CMakeLists aufgeteilt
This commit is contained in:
parent
0631932d78
commit
86f07e7b23
|
@ -0,0 +1,3 @@
|
|||
add_executable(01_ENV_MP MP/main.c MP/func1.c)
|
||||
target_link_libraries(01_ENV_MP m)
|
||||
add_executable(01_ENV_Testat Testat/main.c Testat/func1.c)
|
|
@ -0,0 +1,2 @@
|
|||
add_executable(02_MENT_MP MP/main_02_MENT.cpp)
|
||||
add_executable(02_MENT_Testat Testat/main_02_MENT.cpp)
|
|
@ -0,0 +1,2 @@
|
|||
add_executable(03_FLOW_MP MP/main_mp2_FLOW_a.cpp ../helpers/AnsiConsole.cpp)
|
||||
add_executable(03_FLOW_Testat Testat/main_mp2_FLOW_a.cpp ../helpers/AnsiConsole.cpp)
|
|
@ -0,0 +1,4 @@
|
|||
add_executable(04_UDEF_MP MP/main_04_UDEF_e.cpp)
|
||||
target_link_libraries(04_UDEF_MP m)
|
||||
add_executable(04_UDEF_Testat Testat/main_04_UDEF_e.cpp)
|
||||
target_link_libraries(04_UDEF_Testat m)
|
|
@ -0,0 +1,2 @@
|
|||
add_subdirectory(a)
|
||||
add_subdirectory(b)
|
|
@ -1,160 +0,0 @@
|
|||
#include "../../helpers/AnsiConsole.h"
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
struct Position {
|
||||
int x;
|
||||
int y;
|
||||
|
||||
explicit Position(int x_ = 0, int y_ = 0) {
|
||||
x = x_;
|
||||
y = y_;
|
||||
}
|
||||
};
|
||||
|
||||
class Shape {
|
||||
protected:
|
||||
Position position;
|
||||
Colors color;
|
||||
public:
|
||||
Shape(Position position, Colors color);
|
||||
virtual ~Shape();
|
||||
virtual void draw() = 0;
|
||||
};
|
||||
|
||||
Shape::Shape(Position position, Colors color) {
|
||||
this->position = position;
|
||||
this->color = color;
|
||||
}
|
||||
|
||||
Shape::~Shape() = default;
|
||||
|
||||
class Point : public Shape{
|
||||
|
||||
public:
|
||||
explicit Point(int x, int y, Colors color);
|
||||
void draw() override;
|
||||
};
|
||||
|
||||
Point::Point(int x, int y, Colors color) : Shape(Position(x, y), color) {
|
||||
|
||||
}
|
||||
|
||||
void Point::draw() {
|
||||
ansiConsole.printText(position.x, position.y, "*", color);
|
||||
}
|
||||
|
||||
class Circle : public Shape{
|
||||
protected:
|
||||
int _radius;
|
||||
public:
|
||||
explicit Circle(int x = 0, int y = 0, int radius = 0, Colors color = Colors::GREEN);
|
||||
|
||||
void draw() override;
|
||||
};
|
||||
|
||||
Circle::Circle(int x, int y, int radius, Colors color) : Shape(Position(x, y), color) {
|
||||
_radius = radius;
|
||||
}
|
||||
|
||||
void Circle::draw() {
|
||||
/* see https://de.wikibooks.org/wiki/Formelsammlung_Mathematik:_Geometrie
|
||||
* Höhensatz des Euklid
|
||||
* */
|
||||
int x_start = position.x - _radius / 2;
|
||||
int x_stop = position.x + _radius / 2;
|
||||
|
||||
for (int i = x_start; i <= x_stop; i++) {
|
||||
double x_relative = double(i) - double(x_start);
|
||||
double h = sqrt(x_relative * (x_stop - x_start - x_relative));
|
||||
ansiConsole.printText(position.x + int(x_relative) - _radius / 2,
|
||||
static_cast<int>(position.y + h), "#",
|
||||
color);
|
||||
ansiConsole.printText(position.x + int(x_relative) - _radius / 2,
|
||||
static_cast<int>(position.y - h), "#",
|
||||
color);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class Rectangle : public Shape{
|
||||
protected:
|
||||
int width;
|
||||
int height;
|
||||
|
||||
public:
|
||||
explicit Rectangle(int x = 0, int y = 0, int width = 0, int height = 0, Colors color = Colors::WHITE);
|
||||
void draw() override;
|
||||
};
|
||||
|
||||
Rectangle::Rectangle(int x, int y, int width, int height, Colors color) : Shape(Position(x, y), color) {
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
void Rectangle::draw() {
|
||||
int x_start = position.x - (width / 2);
|
||||
int x_stop = position.x + (width / 2);
|
||||
|
||||
int y_start = position.y - (height / 2);
|
||||
int y_stop = position.y + (height / 2);
|
||||
|
||||
for(int i = x_start; i <= x_stop; i++) {
|
||||
ansiConsole.printText(i, position.y - (height / 2), "#", color);
|
||||
ansiConsole.printText(i, position.y + (height / 2), "#", color);
|
||||
}
|
||||
for(int i = y_start; i< y_stop; i++) {
|
||||
ansiConsole.printText(position.x + (width / 2), i, "#", color);
|
||||
ansiConsole.printText(position.x - (width / 2), i, "#", color);
|
||||
}
|
||||
}
|
||||
|
||||
class Scene {
|
||||
private:
|
||||
std::vector<Shape*> shapes;
|
||||
public:
|
||||
explicit Scene(std::vector<Shape*> shapes);
|
||||
void draw();
|
||||
~Scene();
|
||||
};
|
||||
|
||||
Scene::Scene(std::vector<Shape*> shapes) : shapes(std::move(shapes)) {
|
||||
|
||||
}
|
||||
|
||||
void Scene::draw() {
|
||||
ansiConsole.clearScreen();
|
||||
for(Shape* shape : shapes) {
|
||||
shape->draw();
|
||||
}
|
||||
}
|
||||
|
||||
Scene::~Scene() {
|
||||
for(Shape* shape : shapes) {
|
||||
delete shape;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::vector<Shape*> shapes;
|
||||
|
||||
shapes.push_back(new Point(30, 10, Colors::RED));
|
||||
shapes.push_back(new Point(28, 8, Colors::BLUE));
|
||||
shapes.push_back(new Point(32, 8, Colors::BLUE));
|
||||
|
||||
|
||||
shapes.push_back(new Circle(30, 10, 10, Colors::WHITE));
|
||||
shapes.push_back(new Circle(30, 20, 15, Colors::GREEN));
|
||||
|
||||
|
||||
shapes.push_back(new Rectangle(5, 21, 10, 10, Colors::MAGENTA));
|
||||
|
||||
|
||||
auto *s = new Scene(shapes);
|
||||
s->draw();
|
||||
|
||||
delete s;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
add_executable(05_OOa_MP
|
||||
MP/shapes_main.cpp
|
||||
MP/Shape.cpp
|
||||
MP/Position.h
|
||||
MP/Shape.h
|
||||
MP/Point.cpp
|
||||
MP/Point.h
|
||||
MP/Circle.cpp
|
||||
MP/Circle.h
|
||||
MP/Rectangle.cpp
|
||||
MP/Rectangle.h
|
||||
MP/Scene.cpp
|
||||
MP/Scene.h
|
||||
../../helpers/AnsiConsole.cpp
|
||||
)
|
||||
|
||||
add_executable(05_OOa_Testat
|
||||
Testat/shapes_main.cpp
|
||||
Testat/Shape.cpp
|
||||
Testat/Position.h
|
||||
Testat/Shape.h
|
||||
Testat/Point.cpp
|
||||
Testat/Point.h
|
||||
Testat/Circle.cpp
|
||||
Testat/Circle.h
|
||||
Testat/Rectangle.cpp
|
||||
Testat/Rectangle.h
|
||||
Testat/Scene.cpp
|
||||
Testat/Scene.h
|
||||
../../helpers/AnsiConsole.cpp
|
||||
)
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef C_C_SHAPE_H
|
||||
#define C_C_SHAPE_H
|
||||
|
||||
#include "../../helpers/AnsiConsole.h"
|
||||
#include "../../../helpers/AnsiConsole.h"
|
||||
#include "Position.h"
|
||||
|
||||
class Shape {
|
|
@ -0,0 +1,26 @@
|
|||
#include "Circle.h"
|
||||
#include <cmath>
|
||||
|
||||
Circle::Circle(int x, int y, int radius, Colors color) : Shape(Position(x, y), color) {
|
||||
_radius = radius;
|
||||
}
|
||||
|
||||
void Circle::draw() {
|
||||
/* see https://de.wikibooks.org/wiki/Formelsammlung_Mathematik:_Geometrie
|
||||
* Höhensatz des Euklid
|
||||
* */
|
||||
int x_start = position.x - _radius / 2;
|
||||
int x_stop = position.x + _radius / 2;
|
||||
|
||||
for (int i = x_start; i <= x_stop; i++) {
|
||||
double x_relative = double(i) - double(x_start);
|
||||
double h = sqrt(x_relative * (x_stop - x_start - x_relative));
|
||||
ansiConsole.printText(position.x + int(x_relative) - _radius / 2,
|
||||
static_cast<int>(position.y + h), "#",
|
||||
color);
|
||||
ansiConsole.printText(position.x + int(x_relative) - _radius / 2,
|
||||
static_cast<int>(position.y - h), "#",
|
||||
color);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef C_C_CIRCLE_H
|
||||
#define C_C_CIRCLE_H
|
||||
|
||||
#include "Shape.h"
|
||||
|
||||
class Circle : public Shape{
|
||||
protected:
|
||||
int _radius;
|
||||
public:
|
||||
explicit Circle(int x = 0, int y = 0, int radius = 0, Colors color = Colors::GREEN);
|
||||
void draw() override;
|
||||
};
|
||||
|
||||
#endif //C_C_CIRCLE_H
|
|
@ -0,0 +1,8 @@
|
|||
#include "Point.h"
|
||||
|
||||
Point::Point(int x, int y, Colors color) : Shape(Position(x, y), color) {
|
||||
}
|
||||
|
||||
void Point::draw() {
|
||||
ansiConsole.printText(position.x, position.y, "*", color);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef C_C_POINT_H
|
||||
#define C_C_POINT_H
|
||||
|
||||
#include "Shape.h"
|
||||
|
||||
class Point : public Shape{
|
||||
|
||||
public:
|
||||
explicit Point(int x, int y, Colors color);
|
||||
void draw() override;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef C_C_POSITION_H
|
||||
#define C_C_POSITION_H
|
||||
|
||||
struct Position {
|
||||
int x;
|
||||
int y;
|
||||
|
||||
explicit Position(int x_ = 0, int y_ = 0) {
|
||||
x = x_;
|
||||
y = y_;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,23 @@
|
|||
#include "Rectangle.h"
|
||||
|
||||
Rectangle::Rectangle(int x, int y, int width, int height, Colors color) : Shape(Position(x, y), color) {
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
void Rectangle::draw() {
|
||||
int x_start = position.x - (width / 2);
|
||||
int x_stop = position.x + (width / 2);
|
||||
|
||||
int y_start = position.y - (height / 2);
|
||||
int y_stop = position.y + (height / 2);
|
||||
|
||||
for(int i = x_start; i <= x_stop; i++) {
|
||||
ansiConsole.printText(i, position.y - (height / 2), "#", color);
|
||||
ansiConsole.printText(i, position.y + (height / 2), "#", color);
|
||||
}
|
||||
for(int i = y_start; i< y_stop; i++) {
|
||||
ansiConsole.printText(position.x + (width / 2), i, "#", color);
|
||||
ansiConsole.printText(position.x - (width / 2), i, "#", color);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
#include "Shape.h"
|
||||
|
||||
#ifndef C_C_RECTANGLE_H
|
||||
#define C_C_RECTANGLE_H
|
||||
|
||||
|
||||
class Rectangle : public Shape{
|
||||
protected:
|
||||
int width;
|
||||
int height;
|
||||
|
||||
public:
|
||||
explicit Rectangle(int x = 0, int y = 0, int width = 0, int height = 0, Colors color = Colors::WHITE);
|
||||
void draw() override;
|
||||
};
|
||||
|
||||
|
||||
#endif //C_C_RECTANGLE_H
|
|
@ -0,0 +1,19 @@
|
|||
#include "Scene.h"
|
||||
#include <vector>
|
||||
|
||||
Scene::Scene(std::vector<Shape*> shapes) : shapes(std::move(shapes)) {
|
||||
|
||||
}
|
||||
|
||||
void Scene::draw() {
|
||||
ansiConsole.clearScreen();
|
||||
for(Shape* shape : shapes) {
|
||||
shape->draw();
|
||||
}
|
||||
}
|
||||
|
||||
Scene::~Scene() {
|
||||
for(Shape* shape : shapes) {
|
||||
delete shape;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#include <vector>
|
||||
#include "Shape.h"
|
||||
|
||||
#ifndef C_C_SCENE_H
|
||||
#define C_C_SCENE_H
|
||||
|
||||
class Scene {
|
||||
private:
|
||||
std::vector<Shape*> shapes;
|
||||
public:
|
||||
explicit Scene(std::vector<Shape*> shapes);
|
||||
void draw();
|
||||
~Scene();
|
||||
};
|
||||
|
||||
|
||||
#endif //C_C_SCENE_H
|
|
@ -0,0 +1,9 @@
|
|||
#include "Position.h"
|
||||
#include "Shape.h"
|
||||
|
||||
Shape::Shape(Position position, Colors color) {
|
||||
this->position = position;
|
||||
this->color = color;
|
||||
}
|
||||
|
||||
Shape::~Shape() = default;
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef C_C_SHAPE_H
|
||||
#define C_C_SHAPE_H
|
||||
|
||||
#include "../../../helpers/AnsiConsole.h"
|
||||
#include "Position.h"
|
||||
|
||||
class Shape {
|
||||
protected:
|
||||
Position position;
|
||||
Colors color;
|
||||
public:
|
||||
Shape(Position position, Colors color);
|
||||
virtual ~Shape();
|
||||
virtual void draw() = 0;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,34 @@
|
|||
#include <vector>
|
||||
#include "Shape.h"
|
||||
#include "Point.h"
|
||||
#include "Circle.h"
|
||||
#include "Rectangle.h"
|
||||
#include "Scene.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::vector<Shape*> shapes;
|
||||
|
||||
shapes.push_back(new Point(30, 10, Colors::RED));
|
||||
shapes.push_back(new Point(28, 8, Colors::BLUE));
|
||||
shapes.push_back(new Point(32, 8, Colors::BLUE));
|
||||
|
||||
|
||||
shapes.push_back(new Circle(30, 10, 10, Colors::WHITE));
|
||||
shapes.push_back(new Circle(30, 20, 15, Colors::GREEN));
|
||||
|
||||
|
||||
shapes.push_back(new Rectangle(5, 21, 10, 10, Colors::MAGENTA));
|
||||
|
||||
shapes.push_back(new Point(5, 10, Colors::WHITE));
|
||||
shapes.push_back(new Point(15, 7, Colors::WHITE));
|
||||
shapes.push_back(new Point(7, 5, Colors::WHITE));
|
||||
|
||||
|
||||
auto *s = new Scene(shapes);
|
||||
s->draw();
|
||||
|
||||
delete s;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
add_executable(05_OOb_MP
|
||||
MP/shapes_main.cpp
|
||||
MP/Shape.cpp
|
||||
MP/Position.h
|
||||
MP/Shape.h
|
||||
MP/Point.cpp
|
||||
MP/Point.h
|
||||
MP/Circle.cpp
|
||||
MP/Circle.h
|
||||
MP/Rectangle.cpp
|
||||
MP/Rectangle.h
|
||||
MP/Scene.cpp
|
||||
MP/Scene.h
|
||||
../../helpers/AnsiConsole.cpp
|
||||
)
|
||||
|
||||
add_executable(05_OOb_Testat
|
||||
Testat/shapes_main.cpp
|
||||
Testat/Shape.cpp
|
||||
Testat/Position.h
|
||||
Testat/Shape.h
|
||||
Testat/Point.cpp
|
||||
Testat/Point.h
|
||||
Testat/Circle.cpp
|
||||
Testat/Circle.h
|
||||
Testat/Rectangle.cpp
|
||||
Testat/Rectangle.h
|
||||
Testat/Scene.cpp
|
||||
Testat/Scene.h
|
||||
../../helpers/AnsiConsole.cpp
|
||||
)
|
|
@ -0,0 +1,26 @@
|
|||
#include "Circle.h"
|
||||
#include <cmath>
|
||||
|
||||
Circle::Circle(int x, int y, int radius, Colors color) : Shape(Position(x, y), color) {
|
||||
_radius = radius;
|
||||
}
|
||||
|
||||
void Circle::draw() {
|
||||
/* see https://de.wikibooks.org/wiki/Formelsammlung_Mathematik:_Geometrie
|
||||
* Höhensatz des Euklid
|
||||
* */
|
||||
int x_start = position.x - _radius / 2;
|
||||
int x_stop = position.x + _radius / 2;
|
||||
|
||||
for (int i = x_start; i <= x_stop; i++) {
|
||||
double x_relative = double(i) - double(x_start);
|
||||
double h = sqrt(x_relative * (x_stop - x_start - x_relative));
|
||||
ansiConsole.printText(position.x + int(x_relative) - _radius / 2,
|
||||
static_cast<int>(position.y + h), "#",
|
||||
color);
|
||||
ansiConsole.printText(position.x + int(x_relative) - _radius / 2,
|
||||
static_cast<int>(position.y - h), "#",
|
||||
color);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef C_C_CIRCLE_H
|
||||
#define C_C_CIRCLE_H
|
||||
|
||||
#include "Shape.h"
|
||||
|
||||
class Circle : public Shape{
|
||||
protected:
|
||||
int _radius;
|
||||
public:
|
||||
explicit Circle(int x = 0, int y = 0, int radius = 0, Colors color = Colors::GREEN);
|
||||
void draw() override;
|
||||
};
|
||||
|
||||
#endif //C_C_CIRCLE_H
|
|
@ -0,0 +1,8 @@
|
|||
#include "Point.h"
|
||||
|
||||
Point::Point(int x, int y, Colors color) : Shape(Position(x, y), color) {
|
||||
}
|
||||
|
||||
void Point::draw() {
|
||||
ansiConsole.printText(position.x, position.y, "*", color);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef C_C_POINT_H
|
||||
#define C_C_POINT_H
|
||||
|
||||
#include "Shape.h"
|
||||
|
||||
class Point : public Shape{
|
||||
|
||||
public:
|
||||
explicit Point(int x, int y, Colors color);
|
||||
void draw() override;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef C_C_POSITION_H
|
||||
#define C_C_POSITION_H
|
||||
|
||||
struct Position {
|
||||
int x;
|
||||
int y;
|
||||
|
||||
explicit Position(int x_ = 0, int y_ = 0) {
|
||||
x = x_;
|
||||
y = y_;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,23 @@
|
|||
#include "Rectangle.h"
|
||||
|
||||
Rectangle::Rectangle(int x, int y, int width, int height, Colors color) : Shape(Position(x, y), color) {
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
void Rectangle::draw() {
|
||||
int x_start = position.x - (width / 2);
|
||||
int x_stop = position.x + (width / 2);
|
||||
|
||||
int y_start = position.y - (height / 2);
|
||||
int y_stop = position.y + (height / 2);
|
||||
|
||||
for(int i = x_start; i <= x_stop; i++) {
|
||||
ansiConsole.printText(i, position.y - (height / 2), "#", color);
|
||||
ansiConsole.printText(i, position.y + (height / 2), "#", color);
|
||||
}
|
||||
for(int i = y_start; i< y_stop; i++) {
|
||||
ansiConsole.printText(position.x + (width / 2), i, "#", color);
|
||||
ansiConsole.printText(position.x - (width / 2), i, "#", color);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
#include "Shape.h"
|
||||
|
||||
#ifndef C_C_RECTANGLE_H
|
||||
#define C_C_RECTANGLE_H
|
||||
|
||||
|
||||
class Rectangle : public Shape{
|
||||
protected:
|
||||
int width;
|
||||
int height;
|
||||
|
||||
public:
|
||||
explicit Rectangle(int x = 0, int y = 0, int width = 0, int height = 0, Colors color = Colors::WHITE);
|
||||
void draw() override;
|
||||
};
|
||||
|
||||
|
||||
#endif //C_C_RECTANGLE_H
|
|
@ -0,0 +1,19 @@
|
|||
#include "Scene.h"
|
||||
#include <vector>
|
||||
|
||||
Scene::Scene(std::vector<Shape*> shapes) : shapes(std::move(shapes)) {
|
||||
|
||||
}
|
||||
|
||||
void Scene::draw() {
|
||||
ansiConsole.clearScreen();
|
||||
for(Shape* shape : shapes) {
|
||||
shape->draw();
|
||||
}
|
||||
}
|
||||
|
||||
Scene::~Scene() {
|
||||
for(Shape* shape : shapes) {
|
||||
delete shape;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#include <vector>
|
||||
#include "Shape.h"
|
||||
|
||||
#ifndef C_C_SCENE_H
|
||||
#define C_C_SCENE_H
|
||||
|
||||
class Scene {
|
||||
private:
|
||||
std::vector<Shape*> shapes;
|
||||
public:
|
||||
explicit Scene(std::vector<Shape*> shapes);
|
||||
void draw();
|
||||
~Scene();
|
||||
};
|
||||
|
||||
|
||||
#endif //C_C_SCENE_H
|
|
@ -0,0 +1,9 @@
|
|||
#include "Position.h"
|
||||
#include "Shape.h"
|
||||
|
||||
Shape::Shape(Position position, Colors color) {
|
||||
this->position = position;
|
||||
this->color = color;
|
||||
}
|
||||
|
||||
Shape::~Shape() = default;
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef C_C_SHAPE_H
|
||||
#define C_C_SHAPE_H
|
||||
|
||||
#include "../../../helpers/AnsiConsole.h"
|
||||
#include "Position.h"
|
||||
|
||||
class Shape {
|
||||
protected:
|
||||
Position position;
|
||||
Colors color;
|
||||
public:
|
||||
Shape(Position position, Colors color);
|
||||
virtual ~Shape();
|
||||
virtual void draw() = 0;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,34 @@
|
|||
#include <vector>
|
||||
#include "Shape.h"
|
||||
#include "Point.h"
|
||||
#include "Circle.h"
|
||||
#include "Rectangle.h"
|
||||
#include "Scene.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::vector<Shape*> shapes;
|
||||
|
||||
shapes.push_back(new Point(30, 10, Colors::RED));
|
||||
shapes.push_back(new Point(28, 8, Colors::BLUE));
|
||||
shapes.push_back(new Point(32, 8, Colors::BLUE));
|
||||
|
||||
|
||||
shapes.push_back(new Circle(30, 10, 10, Colors::WHITE));
|
||||
shapes.push_back(new Circle(30, 20, 15, Colors::GREEN));
|
||||
|
||||
|
||||
shapes.push_back(new Rectangle(5, 21, 10, 10, Colors::MAGENTA));
|
||||
|
||||
shapes.push_back(new Point(5, 10, Colors::WHITE));
|
||||
shapes.push_back(new Point(15, 7, Colors::WHITE));
|
||||
shapes.push_back(new Point(7, 5, Colors::WHITE));
|
||||
|
||||
|
||||
auto *s = new Scene(shapes);
|
||||
s->draw();
|
||||
|
||||
delete s;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#include "Circle.h"
|
||||
#include <cmath>
|
||||
|
||||
Circle::Circle(int x, int y, int radius, Colors color) : Shape(Position(x, y), color) {
|
||||
_radius = radius;
|
||||
}
|
||||
|
||||
void Circle::draw() {
|
||||
/* see https://de.wikibooks.org/wiki/Formelsammlung_Mathematik:_Geometrie
|
||||
* Höhensatz des Euklid
|
||||
* */
|
||||
int x_start = position.x - _radius / 2;
|
||||
int x_stop = position.x + _radius / 2;
|
||||
|
||||
for (int i = x_start; i <= x_stop; i++) {
|
||||
double x_relative = double(i) - double(x_start);
|
||||
double h = sqrt(x_relative * (x_stop - x_start - x_relative));
|
||||
ansiConsole.printText(position.x + int(x_relative) - _radius / 2,
|
||||
static_cast<int>(position.y + h), "#",
|
||||
color);
|
||||
ansiConsole.printText(position.x + int(x_relative) - _radius / 2,
|
||||
static_cast<int>(position.y - h), "#",
|
||||
color);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef C_C_CIRCLE_H
|
||||
#define C_C_CIRCLE_H
|
||||
|
||||
#include "Shape.h"
|
||||
|
||||
class Circle : public Shape{
|
||||
protected:
|
||||
int _radius;
|
||||
public:
|
||||
explicit Circle(int x = 0, int y = 0, int radius = 0, Colors color = Colors::GREEN);
|
||||
void draw() override;
|
||||
};
|
||||
|
||||
#endif //C_C_CIRCLE_H
|
|
@ -0,0 +1,8 @@
|
|||
#include "Point.h"
|
||||
|
||||
Point::Point(int x, int y, Colors color) : Shape(Position(x, y), color) {
|
||||
}
|
||||
|
||||
void Point::draw() {
|
||||
ansiConsole.printText(position.x, position.y, "*", color);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef C_C_POINT_H
|
||||
#define C_C_POINT_H
|
||||
|
||||
#include "Shape.h"
|
||||
|
||||
class Point : public Shape{
|
||||
|
||||
public:
|
||||
explicit Point(int x, int y, Colors color);
|
||||
void draw() override;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef C_C_POSITION_H
|
||||
#define C_C_POSITION_H
|
||||
|
||||
struct Position {
|
||||
int x;
|
||||
int y;
|
||||
|
||||
explicit Position(int x_ = 0, int y_ = 0) {
|
||||
x = x_;
|
||||
y = y_;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,23 @@
|
|||
#include "Rectangle.h"
|
||||
|
||||
Rectangle::Rectangle(int x, int y, int width, int height, Colors color) : Shape(Position(x, y), color) {
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
void Rectangle::draw() {
|
||||
int x_start = position.x - (width / 2);
|
||||
int x_stop = position.x + (width / 2);
|
||||
|
||||
int y_start = position.y - (height / 2);
|
||||
int y_stop = position.y + (height / 2);
|
||||
|
||||
for(int i = x_start; i <= x_stop; i++) {
|
||||
ansiConsole.printText(i, position.y - (height / 2), "#", color);
|
||||
ansiConsole.printText(i, position.y + (height / 2), "#", color);
|
||||
}
|
||||
for(int i = y_start; i< y_stop; i++) {
|
||||
ansiConsole.printText(position.x + (width / 2), i, "#", color);
|
||||
ansiConsole.printText(position.x - (width / 2), i, "#", color);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
#include "Shape.h"
|
||||
|
||||
#ifndef C_C_RECTANGLE_H
|
||||
#define C_C_RECTANGLE_H
|
||||
|
||||
|
||||
class Rectangle : public Shape{
|
||||
protected:
|
||||
int width;
|
||||
int height;
|
||||
|
||||
public:
|
||||
explicit Rectangle(int x = 0, int y = 0, int width = 0, int height = 0, Colors color = Colors::WHITE);
|
||||
void draw() override;
|
||||
};
|
||||
|
||||
|
||||
#endif //C_C_RECTANGLE_H
|
|
@ -0,0 +1,19 @@
|
|||
#include "Scene.h"
|
||||
#include <vector>
|
||||
|
||||
Scene::Scene(std::vector<Shape*> shapes) : shapes(std::move(shapes)) {
|
||||
|
||||
}
|
||||
|
||||
void Scene::draw() {
|
||||
ansiConsole.clearScreen();
|
||||
for(Shape* shape : shapes) {
|
||||
shape->draw();
|
||||
}
|
||||
}
|
||||
|
||||
Scene::~Scene() {
|
||||
for(Shape* shape : shapes) {
|
||||
delete shape;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#include <vector>
|
||||
#include "Shape.h"
|
||||
|
||||
#ifndef C_C_SCENE_H
|
||||
#define C_C_SCENE_H
|
||||
|
||||
class Scene {
|
||||
private:
|
||||
std::vector<Shape*> shapes;
|
||||
public:
|
||||
explicit Scene(std::vector<Shape*> shapes);
|
||||
void draw();
|
||||
~Scene();
|
||||
};
|
||||
|
||||
|
||||
#endif //C_C_SCENE_H
|
|
@ -0,0 +1,9 @@
|
|||
#include "Position.h"
|
||||
#include "Shape.h"
|
||||
|
||||
Shape::Shape(Position position, Colors color) {
|
||||
this->position = position;
|
||||
this->color = color;
|
||||
}
|
||||
|
||||
Shape::~Shape() = default;
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef C_C_SHAPE_H
|
||||
#define C_C_SHAPE_H
|
||||
|
||||
#include "../../../helpers/AnsiConsole.h"
|
||||
#include "Position.h"
|
||||
|
||||
class Shape {
|
||||
protected:
|
||||
Position position;
|
||||
Colors color;
|
||||
public:
|
||||
Shape(Position position, Colors color);
|
||||
virtual ~Shape();
|
||||
virtual void draw() = 0;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,34 @@
|
|||
#include <vector>
|
||||
#include "Shape.h"
|
||||
#include "Point.h"
|
||||
#include "Circle.h"
|
||||
#include "Rectangle.h"
|
||||
#include "Scene.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::vector<Shape*> shapes;
|
||||
|
||||
shapes.push_back(new Point(30, 10, Colors::RED));
|
||||
shapes.push_back(new Point(28, 8, Colors::BLUE));
|
||||
shapes.push_back(new Point(32, 8, Colors::BLUE));
|
||||
|
||||
|
||||
shapes.push_back(new Circle(30, 10, 10, Colors::WHITE));
|
||||
shapes.push_back(new Circle(30, 20, 15, Colors::GREEN));
|
||||
|
||||
|
||||
shapes.push_back(new Rectangle(5, 21, 10, 10, Colors::MAGENTA));
|
||||
|
||||
shapes.push_back(new Point(5, 10, Colors::WHITE));
|
||||
shapes.push_back(new Point(15, 7, Colors::WHITE));
|
||||
shapes.push_back(new Point(7, 5, Colors::WHITE));
|
||||
|
||||
|
||||
auto *s = new Scene(shapes);
|
||||
s->draw();
|
||||
|
||||
delete s;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
add_executable(06_POLY_MP MP/shapes_main.cpp ../helpers/AnsiConsole.cpp)
|
||||
add_executable(06_POLY_Testat Testat/shapes_main.cpp ../helpers/AnsiConsole.cpp)
|
|
@ -0,0 +1,2 @@
|
|||
add_executable(07_STD_MP MP/grundgeruest.cpp)
|
||||
add_executable(07_STD_Testat Testat/grundgeruest.cpp)
|
|
@ -0,0 +1 @@
|
|||
add_executable(11_PUTT Test.cpp)
|
|
@ -1,26 +1,14 @@
|
|||
add_executable(01_ENV_MP 01_ENV/MP/main.c 01_ENV/MP/func1.c)
|
||||
target_link_libraries(01_ENV_MP m)
|
||||
add_executable(01_ENV_Testat 01_ENV/Testat/main.c 01_ENV/Testat/func1.c)
|
||||
add_subdirectory(01_ENV)
|
||||
add_subdirectory(02_MENT)
|
||||
add_subdirectory(03_FLOW)
|
||||
add_subdirectory(04_UDEF)
|
||||
add_subdirectory(05_OO)
|
||||
add_subdirectory(06_POLY)
|
||||
add_subdirectory(07_STD)
|
||||
add_subdirectory(08_PTRN)
|
||||
add_subdirectory(10_PITF)
|
||||
|
||||
add_executable(02_MENT_MP 02_MENT/MP/main_02_MENT.cpp)
|
||||
add_executable(02_MENT_Testat 02_MENT/Testat/main_02_MENT.cpp)
|
||||
|
||||
add_executable(03_FLOW_MP 03_FLOW/MP/main_mp2_FLOW_a.cpp helpers/AnsiConsole.cpp)
|
||||
add_executable(03_FLOW_Testat 03_FLOW/Testat/main_mp2_FLOW_a.cpp helpers/AnsiConsole.cpp)
|
||||
|
||||
add_executable(04_UDEF_MP 04_UDEF/MP/main_04_UDEF_e.cpp)
|
||||
target_link_libraries(04_UDEF_MP m)
|
||||
add_executable(04_UDEF_Testat 04_UDEF/Testat/main_04_UDEF_e.cpp)
|
||||
target_link_libraries(04_UDEF_Testat m)
|
||||
|
||||
add_executable(05_OO_MP 05_OO/MP/shapes_main.cpp helpers/AnsiConsole.cpp 05_OO/MP/Shape.cpp 05_OO/MP/Position.h 05_OO/MP/Shape.h 05_OO/MP/Point.cpp 05_OO/MP/Point.h 05_OO/MP/Circle.cpp 05_OO/MP/Circle.h 05_OO/MP/Rectangle.cpp 05_OO/MP/Rectangle.h 05_OO/MP/Scene.cpp 05_OO/MP/Scene.h)
|
||||
add_executable(05_OO_Testat 05_OO/Testat/shapes_main.cpp helpers/AnsiConsole.cpp)
|
||||
|
||||
add_executable(06_POLY_MP 06_POLY/MP/shapes_main.cpp helpers/AnsiConsole.cpp)
|
||||
add_executable(06_POLY_Testat 06_POLY/Testat/shapes_main.cpp helpers/AnsiConsole.cpp)
|
||||
|
||||
add_executable(07_STD_MP 07_STD/MP/grundgeruest.cpp)
|
||||
add_executable(07_STD_Testat 07_STD/Testat/grundgeruest.cpp)
|
||||
add_subdirectory(11_PUTT)
|
||||
|
||||
#add_executable(SequenceDiagram 11_PUTT/05_OO_b/SequenceDiagramCreator.cpp 11_PUTT/05_OO_b/main.cpp)
|
||||
|
||||
|
@ -29,5 +17,3 @@ add_executable(07_STD_Testat 07_STD/Testat/grundgeruest.cpp)
|
|||
#add_executable(CopyOnWrite 11_PUTT/CopyOnWrite/OneByOneMatrix.cpp 11_PUTT/CopyOnWrite/LargeCowMatrix.cpp 11_PUTT/CopyOnWrite/main.cpp)
|
||||
|
||||
#add_executable(Banking 10_PITF/MP/banking_base_rawptr.cpp)
|
||||
|
||||
add_executable(Test 11_PUTT/Test.cpp)
|
Loading…
Reference in New Issue