colored super ellipse [fltk]

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 12 Exercise 13
Using GUI library called FLTK (Fast Light Tool Kit, “full tick”).

Output: n = 4

//  Philipp Siedler
//  Bjarne Stroustrup's PP
//  Chapter 12 Exercise 13

#define _USE_MATH_DEFINES
#include "Simple_window.h"
#include "Graph.h"
#include <cmath>
using namespace Graph_lib;

int main()
try
{
Point tl(100, 100);
Simple_window win(tl, 600, 400, "Regular Polygons");

Point center(win.x_max() / 2, win.y_max() / 2);
Graph_lib::Open_polyline supEllipse0;
supEllipse0.set_color(Color::red);
Graph_lib::Open_polyline supEllipse1;
supEllipse1.set_color(Color::green);
Graph_lib::Open_polyline supEllipse2;
supEllipse2.set_color(Color::blue);
Graph_lib::Open_polyline supEllipse3;
supEllipse3.set_color(Color::black);

double a = 100;
double y;
double b = 100;
double n; // 1/2; 3/2; 2; 4;
n = 4.0;

for (int x = -100; x < 0; x++) {
y = b * pow(1 - pow(abs(x / a), n), 1 / n);
supEllipse0.add(Point(x + center.x, y + center.y));
}
for (int x = 0; x < 101; x++) {
y = b * pow(1 - pow(abs(x / a), n), 1 / n);
supEllipse1.add(Point(x + center.x, y + center.y));
}

for (int x = 100; x > 0; x--) {
y = b * pow(1 - pow(abs(x / a), n), 1 / n);
y = -y;
supEllipse2.add(Point(x + center.x, y + center.y));
}

for (int x = 0; x > -101; x--) {
y = b * pow(1 - pow(abs(x / a), n), 1 / n);
y = -y;
supEllipse3.add(Point(x + center.x, y + center.y));
}

win.attach(supEllipse0);
win.attach(supEllipse1);
win.attach(supEllipse2);
win.attach(supEllipse3);
win.wait_for_button();
}
catch (exception& e) {
cout << e.what() << endl;
return 1;
}
catch (...) {
cout << "Exiting" << endl;
return 2;
}

super ellipse [fltk]

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 12 Exercise 12
Using GUI library called FLTK (Fast Light Tool Kit, “full tick”).

Output: n = 2

Output: n = 1/2

Output: n = 3/2

Output: n = 4

//  Philipp Siedler
//  Bjarne Stroustrup's PP
//  Chapter 12 Exercise 12

#define _USE_MATH_DEFINES
#include "Simple_window.h"
#include "Graph.h"
#include <cmath>
using namespace Graph_lib;

int main()
try
{
Point tl(100, 100);
Simple_window win(tl, 600, 400, "Regular Polygons");

Point center(win.x_max() / 2, win.y_max() / 2);
Graph_lib::Closed_polyline supEllipse;
supEllipse.set_color(Color::black);

double a = 100;
double y;
double b = 100;
double n; // 1/2; 3/2; 2; 4;
n = 4.0;

for (int x = - 100; x < 100; x++) {
y = b * pow(1 - pow(abs(x / a), n), 1 / n);
supEllipse.add(Point(x + center.x, y + center.y));
}

for (int x = 100; x > -100; x--) {
y = b * pow(1 - pow(abs(x / a), n), 1 / n);
y = -y;
supEllipse.add(Point(x + center.x, y + center.y));
}

win.attach(supEllipse);
win.wait_for_button();
}
catch (exception& e) {
cout << e.what() << endl;
return 1;
}
catch (...) {
cout << "Exiting" << endl;
return 2;
}

convoluted polygons [fltk]

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 12 Exercise 11
Using GUI library called FLTK (Fast Light Tool Kit, “full tick”).

Output:

//  Philipp Siedler
//  Bjarne Stroustrup's PP
//  Chapter 12 Exercise 11

#define _USE_MATH_DEFINES
#include "Simple_window.h"
#include "Graph.h"
#include <cmath>
using namespace Graph_lib;

int main()
try
{
Point tl(100, 100);
Simple_window win(tl, 600, 400, "Regular Polygons");

Graph_lib::Closed_polyline triangle;
triangle.set_color(Color::black);

triangle.add(Point(300, 200 - (tan((60 * (M_PI / 180))) * 40)));

Graph_lib::Closed_polyline pentagon;
pentagon.set_color(Color::black);

Point center(300, (240 - (tan((60 * (M_PI / 180))) * 40)));
Graph_lib::Circle cl(center, 2);
cl.set_color(Color::black);

double s1 = sin((2 * M_PI) / 5) * radius;
double c1 = cos(M_PI / 5) * radius;

double s2 = sin((2 * M_PI) / 5) * radius;
double c2 = cos((4 * M_PI) / 5) * radius;

vector<double> pentaX;
vector<double> pentaY;

for (int i = 0; i < 5; i++) {
pentaX.push_back(radius * cos(2 * M_PI*i / 5));
pentaY.push_back(radius * sin(2 * M_PI*i / 5));
}
for (int i = 0; i < 5; i++) {
pentagon.add(Point(pentaX[i] + center.x + 6, pentaY[i] + center.y));
}

win.attach(cl);
win.attach(triangle);
win.attach(pentagon);

win.wait_for_button();
}
catch (exception& e) {
cout << e.what() << endl;
return 1;
}
catch (...) {
cout << "Exiting" << endl;
return 2;
}

drawing a diagram [fltk]

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 12 Exercise 10
Using GUI library called FLTK (Fast Light Tool Kit, “full tick”).

Output:

//  Philipp Siedler
//  Bjarne Stroustrup's PP
//  Chapter 12 Exercise 10

#include "Simple_window.h"
#include "Graph.h"
using namespace Graph_lib;

int main()
try
{
Point tl(100, 100);
Simple_window win(tl, 800, 800, "File Diagram");

//Point.h
Text pointh(Point(50, 40), "Point.h:");
pointh.set_color(Color::black);

Text structPoint(Point(55, 70), "struct Point {...};");
structPoint.set_color(Color::black);

Graph_lib::Rectangle rect0(Point(50, 50), 150, 30);
rect0.set_color(Color::black);
rect0.set_fill_color(Color::yellow);

win.attach(rect0);
win.attach(pointh);
win.attach(structPoint);

//Graph.h
Text graphh(Point(50, 140), "Graph.h:");
graphh.set_color(Color::black);

Text graphing(Point(55, 170), "//graphing interface:");
Text graphing1(Point(55, 190), "struct Shape { ... };");
Text graphing2(Point(55, 210), "...");

graphing.set_color(Color::black);
graphing1.set_color(Color::black);
graphing2.set_color(Color::black);

Graph_lib::Rectangle rect1(Point(50, 150), 150, 70);
rect1.set_color(Color::black);
rect1.set_fill_color(Color::yellow);

win.attach(rect1);
win.attach(graphh);
win.attach(graphing);
win.attach(graphing1);
win.attach(graphing2);

//Graph.cpp
Text graphcpp(Point(20, 320), "Graph.cpp:");
graphcpp.set_color(Color::black);

Text graphcode(Point(25, 345), "Graph code");
graphcode.set_color(Color::black);

Graph_lib::Rectangle rect2(Point(20, 325), 100, 30);
rect2.set_color(Color::black);
rect2.set_fill_color(Color::yellow);

win.attach(rect2);
win.attach(graphcpp);
win.attach(graphcode);

//chapter12.cpp
Text chapter12cpp(Point(50, 450), "chapter12.cpp:");
chapter12cpp.set_color(Color::black);

Text includeGraphh(Point(55, 475), "#include \"Graph.h\"");
includeGraphh.set_color(Color::black);

Text includeSimpleWindow(Point(55, 490), "#include \"Simple_window.h\"");
includeSimpleWindow.set_color(Color::black);

Text intMain(Point(55, 505), "int Main() {...}");
intMain.set_color(Color::black);

Graph_lib::Rectangle rect3(Point(50, 455), 200, 60);
rect3.set_color(Color::black);
rect3.set_fill_color(Color::yellow);

win.attach(rect3);
win.attach(chapter12cpp);
win.attach(includeGraphh);
win.attach(includeSimpleWindow);
win.attach(intMain);

Graph_lib::Rectangle rect4(Point(350, 40), 100, 50);
rect4.set_color(Color::black);
rect4.set_fill_color(Color::yellow);

Graph_lib::Rectangle rect5(Point(345, 35), 100, 50);
rect5.set_color(Color::black);
rect5.set_fill_color(Color::yellow);

Graph_lib::Rectangle rect6(Point(340, 30), 100, 50);
rect6.set_color(Color::black);
rect6.set_fill_color(Color::yellow);

win.attach(rect6);
win.attach(rect5);
win.attach(rect4);

//Arrows
Graph_lib::Line line0(Point(120, 80), Point(120, 150));
line0.set_color(Color::black);

Graph_lib::Line line1(Point(120, 220), Point(110, 325));
line1.set_color(Color::black);

Graph_lib::Line line2(Point(140, 220), Point(150, 455));
line2.set_color(Color::black);

Graph_lib::Line line3(Point(170, 455), Point(270, 415));
line3.set_color(Color::black);

Graph_lib::Line line4(Point(450, 70), Point(540, 70));
line4.set_color(Color::black);

Graph_lib::Line line5(Point(420, 90), Point(420, 180));
line5.set_color(Color::black);

Graph_lib::Line line6(Point(440, 90), Point(600, 300));
line6.set_color(Color::black);

Graph_lib::Line line7(Point(600, 300), Point(450, 200));
line7.set_color(Color::black);

Graph_lib::Line line8(Point(370, 90), Point(150, 150));
line8.set_color(Color::black);

Graph_lib::Line line9(Point(420, 200), Point(420, 400));
line9.set_color(Color::black);

Graph_lib::Line line10(Point(400, 200), Point(300, 285));
line10.set_color(Color::black);

Graph_lib::Line line11(Point(420, 400), Point(480, 280));
line11.set_color(Color::black);

Graph_lib::Line line12(Point(550, 280), Point(600, 355));
line12.set_color(Color::black);

win.attach(line0);
win.attach(line1);
win.attach(line2);
win.attach(line3);
win.attach(line4);
win.attach(line5);
win.attach(line6);
win.attach(line7);
win.attach(line8);
win.attach(line9);
win.attach(line10);
win.attach(line11);
win.attach(line12);

//FLTK code
Text FLTKcode(Point(555, 80), "FLTK code");
FLTKcode.set_color(Color::black);

Graph_lib::Rectangle rect7(Point(550, 60), 100, 50);
rect7.set_color(Color::black);
rect7.set_fill_color(Color::yellow);

Graph_lib::Rectangle rect8(Point(545, 55), 100, 50);
rect8.set_color(Color::black);
rect8.set_fill_color(Color::yellow);

Graph_lib::Rectangle rect9(Point(540, 50), 100, 50);
rect9.set_color(Color::black);
rect9.set_fill_color(Color::yellow);

win.attach(rect9);
win.attach(rect8);
win.attach(rect7);
win.attach(FLTKcode);

//Window.h
Text windowh(Point(345, 140), "Window.h:");
windowh.set_color(Color::black);

Text windowInterface(Point(340, 160), "// window interface:");
windowInterface.set_color(Color::black);

Text classWindow(Point(340, 175), "class Window {...};");
classWindow.set_color(Color::black);

Text ddd(Point(340, 190), "...");
ddd.set_color(Color::black);

Graph_lib::Rectangle rect10(Point(330, 145), 150, 60);
rect10.set_color(Color::black);
rect10.set_fill_color(Color::yellow);

win.attach(rect10);
win.attach(windowh);
win.attach(windowInterface);
win.attach(classWindow);
win.attach(ddd);

//window.cpp
Text windowcpp(Point(200, 280), "Window.cpp:");
windowcpp.set_color(Color::black);

Text windowcode(Point(205, 300), "Window code:");
windowcode.set_color(Color::black);

Graph_lib::Rectangle rect11(Point(200, 285), 150, 30);
rect11.set_color(Color::black);
rect11.set_fill_color(Color::yellow);

win.attach(rect11);
win.attach(windowcpp);
win.attach(windowcode);

//Simpe_window.h
Text simpleWindowh(Point(250, 350), "Simple_Window.h:");
simpleWindowh.set_color(Color::black);

Text windowInterface1(Point(255, 370), "// window interface:");
windowInterface1.set_color(Color::black);

Text classSimpleWindow(Point(255, 385), "class Simple_window {...};");
classSimpleWindow.set_color(Color::black);

Text ddd1(Point(255, 400), "...");
ddd1.set_color(Color::black);

Graph_lib::Rectangle rect12(Point(250, 355), 200, 60);
rect12.set_color(Color::black);
rect12.set_fill_color(Color::yellow);

win.attach(rect12);
win.attach(simpleWindowh);
win.attach(windowInterface1);
win.attach(classSimpleWindow);
win.attach(ddd1);

//GUI.h:
Text guih(Point(450, 250), "GUI.h:");
guih.set_color(Color::black);

Text guiInterface(Point(455, 270), "// GUI interface:");
guiInterface.set_color(Color::black);

Text structInbox(Point(455, 285), "struct In_box {...};");
structInbox.set_color(Color::black);

Text ddd2(Point(455, 300), "...");
ddd2.set_color(Color::black);

Graph_lib::Rectangle rect13(Point(450, 255), 200, 60);
rect13.set_color(Color::black);
rect13.set_fill_color(Color::yellow);

win.attach(rect13);
win.attach(guih);
win.attach(guiInterface);
win.attach(structInbox);
win.attach(ddd2);

//GUI.cpp
Text guicpp(Point(470, 350), "GUI.cpp:");
guicpp.set_color(Color::black);

Text guicode(Point(475, 370), "GUI code");
guicode.set_color(Color::black);

Graph_lib::Rectangle rect14(Point(470, 355), 150, 30);
rect14.set_color(Color::black);
rect14.set_fill_color(Color::yellow);

win.attach(rect14);
win.attach(guicpp);
win.attach(guicode);

win.wait_for_button();
}
catch (exception& e) {
cout << e.what() << endl;
return 1;
}
catch (...) {
cout << "Exiting" << endl;
return 2;
}

image on screen [fltk]

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 12 Exercise 9
Using GUI library called FLTK (Fast Light Tool Kit, “full tick”).

Output:

//  Philipp Siedler
//  Bjarne Stroustrup's PP
//  Chapter 12 Exercise 9

#include "Simple_window.h"
#include "Graph.h"
using namespace Graph_lib;

int main()
try
{
Point tl(100, 100);
Simple_window win(tl, 600, 400, "The Lake");

Image myImage(Point(0, 0), "Input/Original-JPG-Image_large.jpg");
win.attach(myImage);

Text caption(Point(50, 50), "This is a fantastic picture of a lake and mountains in fogg.");
caption.set_color(Color::black);
caption.set_font_size(20);
win.attach(caption);

win.wait_for_button();
}
catch (exception& e) {
cout << e.what() << endl;
return 1;
}
catch (...) {
cout << "Exiting" << endl;
return 2;
}

olympic rings [fltk]

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 12 Exercise 8
Using GUI library called FLTK (Fast Light Tool Kit, “full tick”).

Output:

//  Philipp Siedler
//  Bjarne Stroustrup's PP
//  Chapter 12 Exercise 8

#include "Simple_window.h"
#include "Graph.h"
using namespace Graph_lib;

int main()
try
{
Point tl(100, 100);
Simple_window win(tl, 600, 400, "Canvas");

Circle c0(Point(150, 200), 50);
c0.set_color(Color::blue);
Circle c1(Point(230, 200), 50);
c1.set_color(Color::black);
Circle c2(Point(310, 200), 50);
c2.set_color(Color::red);
Circle c3(Point(190, 280), 50);
c3.set_color(Color::green);
Circle c4(Point(270, 280), 50);
c4.set_color(Color::yellow);

win.attach(c0);
win.attach(c1);
win.attach(c2);
win.attach(c3);
win.attach(c4);

win.wait_for_button();
}
catch (exception& e) {
cout << e.what() << endl;
return 1;
}
catch (...) {
cout << "Exiting" << endl;
return 2;
}

drawing a house [fltk]

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 12 Exercise 7
Using GUI library called FLTK (Fast Light Tool Kit, “full tick”).

Output:

//  Philipp Siedler
//  Bjarne Stroustrup's PP
//  Chapter 12 Exercise 7

#include "Simple_window.h"
#include "Graph.h"
using namespace Graph_lib;

int main()
try
{
Point tl(100, 100);
Simple_window win(tl, 600, 400, "Canvas");

Graph_lib::Rectangle body(Point(250, 320), 100, 80);
body.set_color(Color::black);

Graph_lib::Rectangle door(Point(300, 360), 20, 40);
door.set_color(Color::black);

Graph_lib::Polygon roof;
roof.set_color(Color::black);
roof.set_fill_color(Color::red);

win.attach(body);
win.attach(door);
win.attach(roof);

win.wait_for_button();
}
catch (exception& e) {
cout << e.what() << endl;
return 1;
}
catch (...) {
cout << "Exiting" << endl;
return 2;
}

shape too big for window [fltk]

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 12 Exercise 6
Using GUI library called FLTK (Fast Light Tool Kit, “full tick”).

Output:

//  Philipp Siedler
//  Bjarne Stroustrup's PP
//  Chapter 12 Exercise 6

#include "Simple_window.h"
#include "Graph.h"
using namespace Graph_lib;

int main()
try
{
Point tl(100, 100);

//drawing a shape that does not fit inside a window
/*
Simple_window win(tl, 600, 400, "Canvas");
Graph_lib::Rectangle rect(Point(100, 100), 600, 400);
rect.set_color(Color::black);
*/

//drawing a window that does not fit on my screen
Simple_window win(tl, 2000, 2000, "Canvas");
Graph_lib::Rectangle rect(Point(100, 100), 600, 400);
rect.set_color(Color::black);

win.attach(rect);

win.wait_for_button();
}
catch (exception& e) {
cout << e.what() << endl;
return 1;
}
catch (...) {
cout << "Exiting" << endl;
return 2;
}

full screen and bold frame [fltk]

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 12 Exercise 5
Using GUI library called FLTK (Fast Light Tool Kit, “full tick”).

Output:

//  Philipp Siedler
//  Bjarne Stroustrup's PP
//  Chapter 12 Exercise 5

#include "Simple_window.h"
#include "Graph.h"
using namespace Graph_lib;

int main()
try
{
Point tl(100, 100);
Simple_window win(tl, 1920, 1040, "Canvas");

Graph_lib::Rectangle rect(Point(100, 100), (x_max() / 3) * 2, (y_max() / 4) * 3);
rect.set_color(Color::black);

Graph_lib::Rectangle frame(Point(50, 50), (x_max() / 3) * 2 + 100, (y_max() / 4) * 3 + 100);
frame.set_style(Line_style(Line_style::solid, 30));
frame.set_color(Color::red);

win.attach(rect);
win.attach(frame);

win.wait_for_button();
}
catch (exception& e) {
cout << e.what() << endl;
return 1;
}
catch (...) {
cout << "Exiting" << endl;
return 2;
}

tic-tac-toe board [fltk]

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 12 Exercise 4
Using GUI library called FLTK (Fast Light Tool Kit, “full tick”).

Output:

//  Philipp Siedler
//  Bjarne Stroustrup's PP
//  Chapter 12 Exercise 4

#include "Simple_window.h"
#include "Graph.h"
using namespace Graph_lib;

int main()
try
{
Point tl(100, 100);
Simple_window win(tl, 600, 600, "Canvas");

Graph_lib::Rectangle rect0(Point(0, 0), 200, 200);
Graph_lib::Rectangle rect1(Point(200, 0), 200, 200);
Graph_lib::Rectangle rect2(Point(400, 0), 200, 200);

Graph_lib::Rectangle rect3(Point(0, 200), 200, 200);
Graph_lib::Rectangle rect4(Point(200, 200), 200, 200);
Graph_lib::Rectangle rect5(Point(400, 200), 200, 200);

Graph_lib::Rectangle rect6(Point(0, 400), 200, 200);
Graph_lib::Rectangle rect7(Point(200, 400), 200, 200);
Graph_lib::Rectangle rect8(Point(400, 400), 200, 200);

rect0.set_fill_color(Color::black);
rect1.set_fill_color(Color::white);
rect2.set_fill_color(Color::black);

rect3.set_fill_color(Color::white);
rect4.set_fill_color(Color::black);
rect5.set_fill_color(Color::white);

rect6.set_fill_color(Color::black);
rect7.set_fill_color(Color::white);
rect8.set_fill_color(Color::black);

win.attach(rect0);
win.attach(rect1);
win.attach(rect2);

win.attach(rect3);
win.attach(rect4);
win.attach(rect5);

win.attach(rect6);
win.attach(rect7);
win.attach(rect8);

win.wait_for_button();
}
catch (exception& e) {
cout << e.what() << endl;
return 1;
}
catch (...) {
cout << "Exiting" << endl;
return 2;
}