-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathinterpolate.cpp
61 lines (54 loc) · 1.67 KB
/
interpolate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @file rough.cpp
* @author Sebastien Fourey (GREYC)
*
* @brief Illustrate the rough shape filter
*
* This source code is part of the Board project, a C++ library whose
* purpose is to allow simple drawings in EPS, FIG or SVG files.
* Copyright (C) 2007 Sebastien Fourey <https://fourey.users.greyc.fr>
*/
#include <Board.h>
using namespace LibBoard;
Group interpolate()
{
Group g;
Path a = {Point(0, 0), Point(50, 0), Point(100, 0), Point(150, 0), Point(200, 0)};
Path b = {Point(0, 100), Point(50, 150), Point(100, 100), Point(150, 150), Point(200, 100)};
Polyline pa(a, Color::Red);
Polyline pb(b, Color::Green);
g << pa << pb;
for (double t = 0.05; t < 1.0; t += 0.05) {
g << mix(pa, pb, t);
}
for (decltype(a.size()) i = 0; i < a.size(); ++i) {
g << Line(a[i], b[i], Color::Gray);
}
return g;
}
Group mustache()
{
Group g;
Path p = {Point(100, 100), Point(150, 150), Point(200, 100)};
Color c0 = Color::fromHueColormap(0.0f);
Color c1 = Color::fromHueColormap(0.999f);
Style style = Style::defaultStyle();
for (double r = 0.0; r <= 2.0; r += 0.1) {
const float t = static_cast<float>(r) / 2.0f;
style.penColor = Color::mixHSV(c0, c1, t);
g << Bezier::smoothedPolyline(p.points(), r, style);
}
return g;
}
int main(int, char *[])
{
Board board;
Board::disableLineWidthScaling();
board.setLineWidth(0.1);
board.setPenColor(Color::Blue);
board.setFillColor(Color::Red);
board.append(interpolate(), Direction::Right, Alignment::Center, 5);
board.append(mustache(), Direction::Right, Alignment::Center, 5);
board.saveSVG("interpolate.svg", PageSize::BoundingBox);
// system("svgviewer interpolate.svg");
}