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);
}
Board.h
Declaration of the Board class.
main
int main(int argc, char *argv[])
Definition
arithmetic.cpp:16
Koch
void Koch(Polyline &curve, Point p1, Point p2, int depth)
Definition
koch.cpp:14
LibBoard
Definition
Board.h:55
LibBoard::Board
Class for EPS, FIG or SVG drawings.
Definition
Board.h:61
LibBoard::Board::setPenColor
Board & setPenColor(const Color &color)
Definition
Board.cpp:244
LibBoard::Board::saveFIG
void saveFIG(const char *filename, PageSize size=PageSize::BoundingBox, double margin=0.0, Unit unit=Unit::Millimeter) const
Definition
Board.cpp:636
LibBoard::Board::saveEPS
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
LibBoard::Board::setLineWidth
Board & setLineWidth(double width)
Definition
Board.cpp:274
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=PageSize::BoundingBox, double margin=0.0, Unit unit=Unit::Millimeter) const
Definition
Board.cpp:765
LibBoard::Point
Struct representing a 2D point.
Definition
Point.h:42
LibBoard::Point::rotated
Point rotated(double angle) const
Definition
Point.h:413
LibBoard::Polyline
A polygonal line described by a series of 2D points.
Definition
Polyline.h:38
LibBoard::Shape::scaleToWidth
Shape & scaleToWidth(double w, LineWidthFlag lineWidthFlag)
Definition
Shape.cpp:85
Generated by
1.9.7