My old project for strange attractors
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 

62 lines
1.7 KiB

//
// render.hpp
// AwesomeAttract0r
//
// Created by Joshua Moerman on 1/8/12.
// Copyright (c) 2012 Vadovas. All rights reserved.
//
#ifndef AwesomeAttract0r_render_hpp
#define AwesomeAttract0r_render_hpp
#include <stdexcept>
#include "stf.hpp"
#include "Logger.hpp"
#include "Random.hpp"
#include "Attractor.hpp"
namespace details {
struct empty_canvas : public std::runtime_error {
empty_canvas()
: std::runtime_error("Canvas is too empty (no chaos)")
{ }
};
template <typename C>
void render(Attractor & myAttractor, C & canvas, unsigned int iterations){
Progressbar progress(std::cout, LOG_INFO, "rendering");
for(unsigned int j = 1; j <= iterations; ++j) {
for(unsigned int i = 0; i < 1000000; ++i) {
myAttractor.iterate();
myAttractor.project();
canvas.plot(myAttractor.projector->projectedPoint, 0);
auto c = Random::in_circle(0.3);
double blur[2] = {myAttractor.projector->projectedPoint[0] + c.first, myAttractor.projector->projectedPoint[1] + c.second};
canvas.plot(blur, 1);
}
progress.show(j, iterations);
if(j == iterations/4) if(!filled(canvas, 0.01)) throw empty_canvas();
if(j == iterations/4 * 2) if(!filled(canvas, 0.02)) throw empty_canvas();
if(j == iterations/4 * 3) if(!filled(canvas, 0.03)) throw empty_canvas();
}
}
}
template <typename C>
void render(C & canvas, std::string const & attractorFile, stfu::node & stf_output, unsigned int iterations) {
Attractor my_attractor(attractorFile);
my_attractor.init_range();
logger.start("rendering");
details::render(my_attractor, canvas, iterations);
logger.stop();
if(!filled(canvas, 0.04))
throw details::empty_canvas();
stf_output = stfu::to_stf(my_attractor);
}
#endif