Board 0.9.6
examples/Julia.cpp
#include <Board.h>
#include <algorithm>
#include <board/Debug.h>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <limits>
#include <set>
#include <vector>
using namespace LibBoard;
using namespace std;
using Complex = std::complex<double>;
inline double normalized(double phi)
{
while (phi <= -M_PI) {
phi += 2 * M_PI;
}
while (phi > M_PI) {
phi -= 2 * M_PI;
}
return phi;
}
inline Point point(Complex z)
{
return Point(40 * z.real(), 40 * z.imag());
}
{
Group result;
std::vector<Complex> complexes;
std::vector<Complex> new_complexes;
const double STEP = 0.05;
for (double alpha = M_PI; alpha > -M_PI; alpha -= STEP) {
complexes.push_back(std::polar<double>(2, alpha));
}
int n = 6;
while (n--) {
Group g;
Color cLine = Color::fromRGBf(Tools::boardRandDouble(0, 1), //
Tools::boardRandDouble(0, 1), //
Tools::boardRandDouble(0, 1));
for (Complex & z : complexes) {
Complex zc = z - c;
Complex z2 = std::polar(std::sqrt(std::abs(zc)), normalized(std::arg(zc)) / 2.0);
new_complexes.push_back(z2);
new_complexes.push_back(-z2);
}
for (const Complex & zBefore : complexes) {
const Point p1 = point(zBefore);
double distanceMin = numeric_limits<double>::max();
Point closest;
for (const Complex & zAfter : new_complexes) {
const Point p2 = point(zAfter);
const double d = (p2 - p1).norm();
if (d < distanceMin) {
closest = p2;
distanceMin = (p2 - p1).norm();
}
}
g << Line(p1, closest, cLine);
}
complexes = new_complexes;
std::cout << complexes.size() << std::endl;
new_complexes.clear();
Color color(Tools::boardRandDouble(0, 1), Tools::boardRandDouble(0, 1), Tools::boardRandDouble(0, 1));
for (const Complex & z : complexes) {
g << Dot(point(z), color, 0.2);
}
result << g;
}
return result;
}
int main(int, char *[])
{
Board board;
Style::setDefaultLineWidth(0.1);
Tools::initBoardRand(time(nullptr));
board << julia(Complex{0.25, 0.75});
board.saveSVG("Julia.svg");
// system("display Julia.svg");
}
Declaration of the Board class.
The Exception type. @copyright This source code is part of the Board project, a C++ library whose pur...
double normalized(double phi)
Definition Julia.cpp:27
Group julia(Complex c)
Definition Julia.cpp:43
Point point(Complex z)
Definition Julia.cpp:38
std::complex< double > Complex
Definition Julia.cpp:25
#define M_PI
Definition Shape.h:46
int main(int argc, char *argv[])
Definition arithmetic.cpp:16
Structure representing an RGB triple.
Definition Color.h:43
Definition Board.h:55
Class for EPS, FIG or SVG drawings.
Definition Board.h:61
void saveSVG(const char *filename, PageSize size=PageSize::BoundingBox, double margin=0.0, Unit unit=Unit::Millimeter) const
Definition Board.cpp:765
A line between two points.
Definition Dot.h:42
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
Struct representing a 2D point.
Definition Point.h:42
ShapeList & push_back(Shape *shape)
Definition ShapeList.cpp:427