Board 0.9.6
examples/koch.cpp
#include <Board.h>
using namespace LibBoard;
void Koch(Polyline & curve, Point p1, Point p2, int depth)
{
if (depth > 0) {
Point v = p2 - p1;
Point a = p1 + (v / 3.0);
Point b = p1 + 2 * (v / 3.0);
Point c = b.rotated(60 * Board::Degree, a);
Koch(curve, p1, a, depth - 1);
Koch(curve, a, c, depth - 1);
Koch(curve, c, b, depth - 1);
Koch(curve, b, p2, depth - 1);
} else {
curve << p2;
}
}
int main(int, char *[])
{
Board board;
Board::disableLineWidthScaling();
board.setLineWidth(0.0);
board.setPenColor(Color::Null);
Point a(-100, 0);
Point c(100, 0);
Point b = c.rotated(60 * Board::Degree, a);
Polyline curve(Path::Closed, Color::Null, Color::Green, 0.0, SolidStyle, RoundCap, RoundJoin);
const int recursions = 5;
Koch(curve, a, b, recursions);
Koch(curve, b, c, recursions);
Koch(curve, c, a, recursions);
board << curve;
Tools::notice << curve.vertexCount() << " points in the curve after " << recursions << " recursions.\n";
board.saveFIG("koch.fig", 200, 200);
board.saveEPS("koch.eps", PageSize::A4);
board.scaleToWidth(25, UseLineWidth);
board.saveSVG("koch.svg", PageSize::BoundingBox, 0.0, Unit::Centimeter);
}
Declaration of the Board class.
int main(int argc, char *argv[])
Definition arithmetic.cpp:16
void Koch(Polyline &curve, Point p1, Point p2, int depth)
Definition koch.cpp:14
Definition Board.h:55
Class for EPS, FIG or SVG drawings.
Definition Board.h:61
Board & setPenColor(const Color &color)
Definition Board.cpp:244
void saveFIG(const char *filename, PageSize size=PageSize::BoundingBox, double margin=0.0, Unit unit=Unit::Millimeter) const
Definition Board.cpp:636
void saveEPS(std::ostream &out, PageSize size=PageSize::BoundingBox, double margin=0.0, Unit unit=Unit::Millimeter, const std::string &title=std::string()) const
Definition Board.cpp:539
Board & setLineWidth(double width)
Definition Board.cpp:274
void saveSVG(const char *filename, PageSize size=PageSize::BoundingBox, double margin=0.0, Unit unit=Unit::Millimeter) const
Definition Board.cpp:765
Struct representing a 2D point.
Definition Point.h:42
Point rotated(double angle) const
Definition Point.h:413
A polygonal line described by a series of 2D points.
Definition Polyline.h:38
Shape & scaleToWidth(double w, LineWidthFlag lineWidthFlag)
Definition Shape.cpp:85