1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
// Osman Zakir
// 3 / 20 / 2017
// Bjarne Stroustrup: Programming: Priniples and Practice Using C++ 2nd Edition
// Chapter 12 Exercise 1
// File chapter12ex1.cpp
// Exercise specifications:
/**
* Draw a rectangle as a Rectangle and as a Polygon. Make the lines of the
* Polygon red and the lines of the Rectangle blue.
*/
#include "../../Simple_window.h"
#include "../../Graph.h"
int main()
{
using namespace Graph_lib;
Point tl{ 100, 100 };
Simple_window s_window{ tl, 600, 400, "Rectangle exercise" };
try
{
constexpr int rect_width = 100;
constexpr int rect_height = 50;
Graph_lib::Rectangle rect{ Point{100, 140}, rect_width, rect_height };
rect.set_color(Color::blue);
s_window.attach(rect);
Graph_lib::Polygon poly_rect;
poly_rect.add(Point{ 388, 140 });
poly_rect.add(Point{ 488, 140 });
poly_rect.add(Point{ 488, 190 });
poly_rect.add(Point{ 388, 190 });
poly_rect.set_color(Color::red);
s_window.attach(poly_rect);
s_window.wait_for_button();
}
catch (runtime_error &rte)
{
Text message_start{ Point{100, 200}, "Runtime_error: " };
Text message{ Point{200, 200}, rte.what() };
message_start.set_color(Color::black);
message.set_color(Color::black);
s_window.attach(message_start);
s_window.attach(message);
s_window.wait_for_button();
return 1;
}
}
|