#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace LibBoard;
const int NbColors = 4;
{
if (!n) {
return ShapeList() << (
Group() << LibBoard::rectangle(0, 0, 10, 10,
Color(
"#404040"), Color::Null, 0.1, DashStyle));
}
if (n == 1) {
switch (rand() % 2) {
case 0:
return ShapeList() << LibBoard::circle(0, 0, 5, Colors[rand() % NbColors], Color::Null, 1.0);
case 1:
return ShapeList() << LibBoard::rectangle(0, 0, 10, 10, Colors[rand() % NbColors], Color::Null, 1.0);
}
}
int count[4] = {0, 0, 0, 0};
while (count[0] + count[1] + count[2] + count[3] != n) {
count[rand() % 4] += 1;
}
ShapeList topRight = generateGroup(count[1]);
ShapeList bottomLeft = generateGroup(count[2]);
ShapeList bottomRight = generateGroup(count[3]);
top << topLeft;
top.
append(topRight, ShapeList::Right, ShapeList::AlignCenter, 0.0, UseLineWidth);
bottom << bottomLeft;
bottom.
append(bottomRight, ShapeList::Right, ShapeList::AlignCenter, 0.0, UseLineWidth);
top.
append(bottom, ShapeList::Bottom, ShapeList::AlignCenter, 0.0, UseLineWidth);
if (n >= 2) {
group << top;
Rect r = top.bbox(UseLineWidth);
group << LibBoard::rectangle(r, Color::Black, Color::Null, 0.1);
list << group;
return list;
} else {
list << top;
return list;
}
}
{
try {
ShapeList::size_type n = 0;
while (true) {
++n;
}
}
return result;
}
int main(int, char *[])
{
srand(1000);
Style::setDefaultLineWidth(0.5);
Style::setDefaultPenColor(Color::Blue);
Style::setDefaultFillColor(Color::Null);
cross <<
Line(0, 0, 10, 10, Color::Green) <<
Line(0, 10, 10, 0, Color::Green);
int n = 25;
while (n--) {
int r = rand() % 3;
switch (r) {
case 0:
board.
append(LibBoard::circle(0, 0, 5.0), Board::Right, Board::AlignCenter);
break;
case 1:
board.
append(LibBoard::rectangle(0, 0, 10, 10), Board::Right, Board::AlignCenter);
break;
case 2:
board.
append(cross, Board::Right, Board::AlignCenter);
break;
}
}
ShapeList rectangles = findAll<Polyline>(board);
board.
append(
Text(0, 0,
"Everything", LibBoard::Fonts::Helvetica, 7), Board::Right, Board::AlignCenter, 10.0);
board.
append(circles, Board::Bottom, Board::AlignLeft);
board.
append(rectangles, Board::Bottom, Board::AlignLeft);
board.
append(crosses, Board::Bottom, Board::AlignLeft);
for (
Shape & s : circles) {
}
board.
append(circles, Board::Bottom, Board::AlignRight);
std::cout << "List of shapes at to level\n";
std::cout << "==========================\n";
for (
const Shape & s : board) {
std::cout << s.
name() <<
", ";
}
std::cout << "\n\n";
std::cout << "Beadth-First traversal of the shapes tree\n";
std::cout << "=========================================\n";
while (bfi != bfe) {
std::cout << (*bfi).name() << ", ";
++bfi;
}
std::cout << "\n\n";
std::cout << "Depth-First traversal of the shapes tree\n";
std::cout << "========================================\n";
while (dfi != dfe) {
std::cout << (*dfi).name() << ", ";
++dfi;
}
std::cout << "\n\n";
board.append(generateGroup(50), ShapeList::Bottom, ShapeList::AlignCenter);
std::cout << "Size is " << board.size() << std::endl;
std::cout << "Board deep size is " << board.deepSize() << std::endl;
std::cout << "Tree deep size is " << deepSize << std::endl;
std::size_t counter = 0;
while (dfi != dfe) {
if (!r) {
r =
dynamic_cast<Ellipse *
>(dfi.pointer());
}
if (r) {
shade.
setRGBf(0.2f + 0.8f * (counter / (
float)deepSize), 0, 0, 1.0);
points << LibBoard::circle(r->
center(), 1, Color::Null, shade, 0.0);
}
++dfi;
++counter;
}
std::cout << counter << " shapes visited.\n";
board << points;
board <<
Polyline(path,
Color(
"#00c000"), Color::Null, 0.5, SolidStyle, RoundCap, RoundJoin);
board.saveSVG("traversal.svg");
}