Board 0.9.6
examples/rough.cpp
#include <Board.h>
#include <board/Debug.h>
#include <ctime>
using namespace LibBoard;
{
Group g;
Point a(30, 10);
Point b(60, 50);
Point v1(5, 5);
Point v2(-5, 5);
g << Bezier(a, a + v1, b, b + v2, Color::Red).rotated(45);
RoughVisitor::slideRandomly(a, 1);
RoughVisitor::slideRandomly(b, 1);
g << Bezier(a, a + v1, b, b + v2, Color::Green).rotated(45);
v.setRepeat(1);
Shape * rline = Line(0, 0, 20, 20, Color::Red).accept(v);
try {
g << *rline;
} catch (const char * message) {
std::cerr << message << std::endl;
}
delete rline;
return g;
}
{
Path p = {Point(100, 100), Point(150, 150), Point(200, 100)};
Path p2 = {Point(100, 100), Point(150, 50), Point(200, 100)};
Group g;
for (double r = 0.0; r <= 1.0; r += 0.1) {
g << mix(Polyline(p, Color::Red), Polyline(p2, Color::Yellow), r);
}
return g;
}
{
Polyline poly = rectangle(0, 0, 50, 50, Color::Gray, Color::Green);
l.append(poly, Direction::Right, Alignment::Center);
Arrow arrow(0, 0, 60, 60, Arrow::ExtremityType::Stick, Color::Red, Color::White);
l.append(arrow, Direction::Right, Alignment::Center);
Ellipse e(0, 0, 15, 25, Color::Red, Color::Brown);
e.rotate(10 * Board::Degree);
l.append(e, Direction::Right, Alignment::Center);
Ellipse c = circle(10, 10, 15, Color::Green, Color::Lime);
l.append(c);
Group g;
g.append(l, Direction::Right, Alignment::Center);
g.append(makeRough(l, 1, SketchyCrossingHachure, 25 * Board::Degree), Direction::Bottom, Alignment::Center);
g.append(framed(boardFontText(Point(0, 0), "Hello world!", 10, Color::DarkGreen, 1.5), 5.0, Color::Black, Color::Null, 2.0), Direction::Right, Alignment::Center, 5);
return g;
}
{
Group g;
Style::setDefaultLineWidth(2);
Polyline p = rectangle(0, 0, 100, 100);
g << p;
square << p;
square << hachures(p.path(), StraightHachure, Color::Red, 1, 3, 15 * Board::Degree);
g.append(square, Direction::Right, Alignment::Center, 3);
p.rotate(10 * Board::Degree);
square.clear();
square << p;
square << hachures(p.path(), StraightHachure, Color::Red, 1, 3);
g.append(square, Direction::Right, Alignment::Center, 3);
square.clear();
Path path = p.path();
std::swap(path[1], path[2]);
square << Polyline(path);
ShapeList h = hachures(path, StraightHachure, Color::Red, 1, 3);
square << h;
g.append(square, Direction::Right, Alignment::Center, 3);
path = {Point(0, 0), Point(0, 100), Point(40, 70), Point(100, 0), Point(100, 100), Point(40, 70)};
path.close();
return g;
}
{
Group g;
Path path = {Point(0, 0), Point(50, 100), Point(75, 75), Point(100, 90), Point(150, 50), Point(200, 0), Point(180, 100)};
path.close();
g << hachures(path, StraightHachure, Color::Red, 0.5, 2, 30 * Board::Degree);
return g;
}
{
Group g;
Style::setDefaultLineWidth(2.5);
Style::setDefaultFillColor(Color::Cyan);
Style::setDefaultPenColor(Color(20, 20, 20));
Polyline p = rectangle(0, 0, 100, 100).rotate(10 * Board::Degree);
g << p;
Path path = p.path();
std::swap(path[1], path[2]);
g.append(Polyline(path).rotate(25 * Board::Degree));
path = {Point(0, 0), Point(0, 100), Point(40, 70), Point(100, 0), Point(100, 100), Point(40, 70)};
path.close();
g.append(Polyline(path).rotate(12 * Board::Degree));
return g;
}
{
Group g;
Path path = {Point(0, 0), Point(0, 100), Point(40, 70), Point(100, 0), Point(100, 100), Point(40, 70)};
path.close();
g << hachures(path, StraightHachure, Color::Red, 0.5, 2, 0 * Board::Degree);
return g;
}
{
Group g;
Style::setDefaultLineWidth(0.5);
Ellipse e(0, 0, 60, 30, Color::Red, Color::Green);
e.rotate(35 * Board::Degree);
// g << e;
// g << rectangle(e.boundingBox(UseLineWidth), Color::Red, Color::Null, 2.0);
// Polyline r = rectangle(0, 0, 50, 40, Color::Blue, Color::Aqua, 2.0);
// g.append(r);
// g.append(makeRough(r, 2, NoFilling, 10 * Board::Degree, 0.0), Direction::Right);
// g.append(makeRough(r, 2, StraightHachure, 0.0 * Board::Degree, 0.0), Direction::Right);
// g.append(makeRough(r, 2, SketchyHachure, 0.0 * Board::Degree, 0.0), Direction::Right);
// g.append(makeRough(r, 2, SketchyCrossingHachure, 14.0 * Board::Degree, 2.0), Direction::Right);
// r.setPenColor(Color::Null);
// g.append(makeRough(r, 2, StraightHachure, 0.0 * Board::Degree, 0.0), Direction::Right);
// g.append(makeRough(r, 2, SketchyCrossingHachure, 0.0 * Board::Degree, 2.5), Direction::Right);
// g.append(makeRough(e, 1, PlainFilling, 10 * Board::Degree, 0.0), Direction::Right);
Group eh;
Style s = e.style();
s.penColor = Color::Green;
// eh << hachures(e, s, StraightHachure, 4, 0 * Board::Degree);
e.setPenColor(Color::Black);
e.setFillColor(Color::Brown);
eh << e;
g.append(eh, Direction::Right);
// g.append(makeRough(e, 2, StraightHachure, 10 * Board::Degree, 0.0), Direction::Right);
// g.append(makeRough(e, 2, CrossingHachure, 10 * Board::Degree, 0.0), Direction::Right);
g.append(makeRough(e, 2, SketchyHachure, 10 * Board::Degree, 0.0), Direction::Right);
g.append(makeRough(e, 1, SketchyCrossingHachure, 45 * Board::Degree, 3.0));
// g.append(e);
return g;
}
int main(int, char *[])
{
auto t = time(nullptr);
// t = 1589104684;
Tools::initBoardRand(static_cast<unsigned long>(t));
Board board;
Board::disableLineWidthScaling();
board.setLineWidth(1.0);
board.setPenColor(Color::Blue);
board.setFillColor(Color::Red);
// Style::setDefaultLineWidth(0.5);
Path r = rectangle(0, 0, 10, 10).path();
std::cout << Style::defaultStyle() << std::endl;
// Style::setDefaultPenColor(Color::Blue);
// board.append(Bezier::smoothedPolyline(r, 1.5), Direction::Right, Alignment::Center);
// board.append(slide(), Direction::Right, Alignment::Center);
// board.append(diamond(), Direction::Right, Alignment::Center);
board.append(hachures(), Direction::Right, Alignment::Center);
board.append(polygons(), Direction::Bottom, Alignment::Center);
board.append(makeRough(polygons(), 1, PlainFilling), Direction::Bottom, Alignment::Center);
board.append(makeRough(polygons(), 2, PlainFilling), Direction::Bottom, Alignment::Center);
board.append(makeRough(polygons(), 2, SketchyHachure, 20 * Board::Degree, 2), Direction::Bottom, Alignment::Center);
board.append(rough(), Direction::Right, Alignment::Center);
board.append(framed(ell()), Direction::Right, Alignment::Center);
board.append(hachuresBis());
board.append(hachuresTer(), Direction::Bottom, Alignment::Center);
// board.append(framed(boardFontText(Point(0, 0), "Hello", 24), Color::Red, 2, 5, 1));
// board.append(makeRough(framed(boardFontText(Point(0, 0), "Hello", 24), Color::Red, 2, 5), 1));
// board.append(makeRough(framed(boardFontText(Point(0, 0), "HELLO", 24), Color::Red, 2, 5), 1));
// board.append(framed(board), Direction::Bottom);
board.saveSVG("rough.svg", PageSize::BoundingBox);
// board.saveFIG("rough.fig", PageSize::BoundingBox);
// system("svgviewer rough.svg");
}
Declaration of the Board class.
The Exception type. @copyright This source code is part of the Board project, a C++ library whose pur...
int main(int argc, char *argv[])
Definition arithmetic.cpp:16
Structure representing an RGB triple.
Definition Color.h:43
T square(const T &t)
Definition Tools.h:168
Definition Board.h:55
Path mix(const Path &a, const Path &b, double time)
Interpolate two paths according to a time (0 is a, 1 is b)
Definition Path.cpp:390
Ellipse circle(double x, double y, double radius, Color penColor=Style::defaultPenColor(), Color fillColor=Style::defaultFillColor(), double lineWidth=Style::defaultLineWidth(), const LineStyle lineStyle=Style::defaultLineStyle())
Definition Ellipse.cpp:371
ShapeList makeRough(const Shape &shape, int repeat=1, SketchFilling filling=PlainFilling, double hachureAngle=0.0, double hachureSpacing=0.0)
Definition SketchFilter.cpp:171
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
Group framed(const Shape &shape, double margin=0.0, const Color &penColor=Style::defaultPenColor(), const Color &fillColor=Style::defaultFillColor(), double lineWidth=Style::defaultLineWidth(), LineStyle lineStyle=Style::defaultLineStyle(), int sketchyCount=0)
Surround a shape with a rectangular frame.
Definition Board.cpp:1081
Group boardFontText(Point baselineStart, const std::string &text, double size, Color penColor=Style::defaultPenColor(), double lineWidth=0.0)
Create a text with board's font.
Definition BoardFontText.cpp:320
Group rough()
Definition rough.cpp:52
Group hachures()
Definition rough.cpp:71
Group diamond()
Definition rough.cpp:41
Group hachuresBis()
Definition rough.cpp:108
Group slide()
Definition rough.cpp:16
Group ell()
Definition rough.cpp:150
Group polygons()
Definition rough.cpp:117
Group hachuresTer()
Definition rough.cpp:141
A line between two points with an arrow at one extremity.
Definition Arrow.h:38
A Bezier curve described by two series of 2D points (curve points and control points).
Definition Bezier.h:42
Bezier rotated(double angle, const Point &center) const
Rotated copy of the curve.
Definition Bezier.cpp:119
Class for EPS, FIG or SVG drawings.
Definition Board.h:61
Board & setPenColor(const Color &color)
Definition Board.cpp:244
Board & setFillColor(const Color &color)
Definition Board.cpp:268
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
An ellipse.
Definition Ellipse.h:38
A group of shapes. A group is basically a ShapeList except that when rendered in either an SVG of a F...
Definition Group.h:40
A line between two points.
Definition Line.h:38
virtual void accept(ShapeVisitor &visitor) override
Accepts a visitor object.
Definition Line.cpp:200
A path, according to Postscript and SVG definition.
Definition Path.h:45
void close()
Close the path.
Definition Path.h:453
Struct representing a 2D point.
Definition Point.h:42
A polygonal line described by a series of 2D points.
Definition Polyline.h:38
const Path & path() const
Definition Polyline.h:461
Polyline & rotate(double angle, const Point &center) override
Definition Polyline.cpp:61
Definition RoughVisitor.h:46
void setRepeat(int n)
Definition RoughVisitor.cpp:47
A group of shapes.
Definition ShapeList.h:47
ShapeList & append(const Shape &shape, Direction direction=Direction::Right, Alignment alignment=Alignment::Center, double margin=0.0, LineWidthFlag lineWidthFlag=UseLineWidth)
Definition ShapeList.cpp:232
Abstract structure for a 2D shape.
Definition Shape.h:64
Definition Style.h:69
Color penColor
Definition Style.h:70