68 lines
2.0 KiB
C++
68 lines
2.0 KiB
C++
#include "cmdopt.hpp"
|
|
#include "functor.hpp"
|
|
#include "geom/aabb.hpp"
|
|
#include "geom/sample.hpp"
|
|
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
#include <random>
|
|
|
|
|
|
template <size_t S>
|
|
class util::geom::surface::sampler<util::extent<S,float>> {
|
|
public:
|
|
sampler (util::extent<S,float> _target):
|
|
target (_target)
|
|
{ ; }
|
|
|
|
template <typename GeneratorT>
|
|
util::point<S,float>
|
|
operator() (GeneratorT &&gen) const noexcept
|
|
{
|
|
util::point<S,float> p;
|
|
for (size_t i = 0; i < S; ++i)
|
|
p[i] = std::uniform_real_distribution<float> (0, target[i]) (gen);
|
|
return p;
|
|
}
|
|
|
|
private:
|
|
util::extent<S,float> target;
|
|
};
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
struct height {
|
|
float
|
|
operator() (util::point2f p) const { return std::pow (p.y / 100, 3.f); }
|
|
};
|
|
|
|
|
|
int
|
|
main (int argc, char **argv)
|
|
{
|
|
util::extent2f area {256, 256};
|
|
float distance = 5.f;
|
|
int samples = 15;
|
|
|
|
util::cmdopt::parser opts;
|
|
opts.add<util::cmdopt::option::value<float>> ('w', "width", "width of the space to fill", area.w);
|
|
opts.add<util::cmdopt::option::value<float>> ('h', "height", "height of the space to fill", area.h);
|
|
opts.add<util::cmdopt::option::value<float>> ('d', "distance", "minimum distance between samples", distance);
|
|
opts.add<util::cmdopt::option::value<int>> ('s', "samples", "number of samples per iteration", samples);
|
|
|
|
opts.scan (argc, argv);
|
|
|
|
std::cout << "<svg height='" << area.h << "' width='" << area.h << "'>";
|
|
for (auto p: util::geom::surface::poisson (util::geom::surface::sampler (area),
|
|
std::default_random_engine (),
|
|
util::functor::constant (distance),
|
|
samples))
|
|
{
|
|
std::cout << "<circle cx='" << p.x << "' cy='" << p.y << "' r='1' />";
|
|
}
|
|
|
|
std::cout << "</svg>\n";
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|