Board 0.9.6
examples/arrows.cpp
#include <Board.h>
#include <board/Tools.h>
#include <sstream>
using namespace LibBoard;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
float random_gray()
{
return Tools::boardRand() / static_cast<float>(RAND_MAX);
}
int main(int, char *[])
{
Board board;
board.clear(Color(233, 250, 140));
board.setLineWidth(0.25);
Tools::initBoardRand(static_cast<unsigned int>(time(nullptr)));
double angle = 0.0;
board << LibBoard::rectangle(-8, 12, 16, 24, Color::Black, Color::Null, 0.1);
double radius = 10;
board.setFont(Fonts::CourierBold, 2);
for (int i = 0; i < 45; ++i) {
angle = i * (2 * M_PI / 45);
board.setFillColor(board.penColor());
board.drawArrow(0, 0, radius * cos(angle), radius * sin(angle));
radius += 0.4;
board.setLineWidth(0.1);
board.setPenColorRGBi(255, 0, 0);
board.drawDot(radius * cos(angle), radius * sin(angle));
std::stringstream s;
s << i;
board.drawText(radius * cos(angle), radius * sin(angle), s.str());
}
board.setPenColorRGBi(0, 0, 0);
board.setFont(Fonts::PalatinoRoman, 24);
board.drawText(0, 15, "Arrows");
board << LibBoard::rectangle(board.boundingBox(IgnoreLineWidth));
Rect rect = board.last<Polyline>().boundingBox(UseLineWidth);
board.setPenColor(Color::Red);
board.setFillColor(Color::Green);
board.setLineWidth(1);
board.drawArrow(rect.topLeft(), rect.bottomRight());
Rect rect2(10, 90, 40, 40);
board.drawArrow(rect2.topLeft(), rect2.topRight());
board.drawArrow(rect2.topRight(), rect2.bottomRight());
board.drawArrow(rect2.bottomRight(), rect2.bottomLeft());
board.drawArrow(rect2.bottomLeft(), rect2.topLeft());
// board.saveEPS( "arrows_A4.eps", PageSize::A4, 2.0, Unit::Centimeter );
// board.saveSVG( "arrows_A4.svg", PageSize::A4 );
// board.saveFIG( "arrows.fig" );
board.scaleToWidth(20, UseLineWidth);
board.saveSVG("arrows.svg", PageSize::BoundingBox, 0.0, Unit::Centimeter);
board.saveEPS("arrows.eps", PageSize::BoundingBox, 0.0, Unit::Centimeter);
board.saveFIG("arrows.fig", PageSize::BoundingBox, 0.0, Unit::Centimeter);
// system("display arrows.svg");
}
Declaration of the Board class.
#define M_PI
Definition Shape.h:46
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
int main(int argc, char *argv[])
Definition arithmetic.cpp:16
float random_gray()
Definition arrows.cpp:21
Structure representing an RGB triple.
Definition Color.h:43
Definition Board.h:55
Polyline rectangle(double left, double top, double width, double height, Color penColor=Style::defaultPenColor(), Color fillColor=Style::defaultFillColor(), double lineWidth=Style::defaultLineWidth(), const LineStyle lineStyle=Style::defaultLineStyle(), const LineCap cap=Style::defaultLineCap(), const LineJoin join=Style::defaultLineJoin())
Definition Polyline.cpp:569
Class for EPS, FIG or SVG drawings.
Definition Board.h:61
Board & setFont(const Fonts::Font font, double fontSize)
Definition Board.cpp:280
const Color & penColor() const
penColor
Definition Board.h:1084
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 drawArrow(double x1, double y1, double x2, double y2, Arrow::ExtremityType type=Arrow::ExtremityType::Plain)
Definition Board.cpp:313
Board & setPenColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Definition Board.cpp:232
void drawDot(double x, double y)
Definition Board.cpp:298
void drawText(double x, double y, const char *text)
Definition Board.cpp:428
Board & setPenColorRGBf(float red, float green, float blue, float alpha=1.0f)
Definition Board.cpp:238
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 & setFillColor(const Color &color)
Definition Board.cpp:268
Board & setLineWidth(double width)
Definition Board.cpp:274
void clear(const Color &color=Color::Null)
Definition Board.cpp:149
void saveSVG(const char *filename, PageSize size=PageSize::BoundingBox, double margin=0.0, Unit unit=Unit::Millimeter) const
Definition Board.cpp:765
A polygonal line described by a series of 2D points.
Definition Polyline.h:38
Struct representing a rectangle on the plane.
Definition Rect.h:40
Point topLeft() const
topLeft Top-left point of the rectangle
Definition Rect.h:77
Point bottomRight() const
bottomRight Bottom-right point of the rectangle
Definition Rect.h:95
Rect boundingBox(LineWidthFlag) const override
Definition ShapeList.cpp:405
T & last(const std::size_t position=0)
Definition ShapeList.h:505
Shape & scaleToWidth(double w, LineWidthFlag lineWidthFlag)
Definition Shape.cpp:85