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.
 
 
 

118 lines
3.0 KiB

#include "Logger.hpp"
#include <iostream>
#include <ctime>
#include <valarray>
#include <cstring>
#include "Attractor.hpp"
#include "Canvas.hpp"
#include "Projector.hpp"
#include "canvae/Raw.hpp"
#include "ostream_helpers.h"
#include "defines.hpp"
int verbose;
void showHelpText() {
std::cout << "Awesome Attractor, version " << __DATE__ << std::endl;
std::cout << "Usage: AwesomeAttractor [OPTION]... FILE" << std::endl << std::endl;
std::cout << "Optons:" << std::endl;
std::cout << " --help Shows this help" << std::endl;
std::cout << " -q quiet mode" << std::endl;
std::cout << " -v verbose mode" << std::endl;
std::cout << " -V loud mode" << std::endl;
std::cout << " -w N Sets width of output image to N" << std::endl;
std::cout << " -h N Sets height of output image to N" << std::endl;
std::cout << " -i N Sets number of iterations to N" << std::endl;
exit(0);
}
int main(int argc, char* argv[]) {
verbose = 0;
std::string attractorFile = DEFAULT_ATTRACTOR_FILE;
unsigned int iterations = DEFAULT_ITERATIONS;
unsigned int width = DEFAULT_WIDTH;
unsigned int height = DEFAULT_HEIGHT;
if(argc <= 1) {
showHelpText();
}
for(int i = 1; i < argc; ++i) {
if(strcmp(argv[i], "-v") == 0) {
verbose = 1;
} else if(strcmp(argv[i], "-q") == 0) {
verbose = -1;
} else if(strcmp(argv[i], "--help") == 0) {
showHelpText();
} else if(strcmp(argv[i], "-V") == 0) {
verbose = 3;
} else if(strcmp(argv[i], "-w") == 0) {
width = atoi(argv[++i]);
} else if(strcmp(argv[i], "-h") == 0) {
height = atoi(argv[++i]);
} else if(strcmp(argv[i], "-i") == 0) {
iterations = atoi(argv[++i]);
} else {
attractorFile = argv[i];
}
}
LogInfo("Awesome Attractor, version %s\n", __DATE__);
// initialising stuff
Attractor myAttractor(attractorFile);
/*unsigned int sizes[] = {128, 128, 128};
Canvas* canvas = new Raw(3, sizes);
projection.canvas = canvas;*/
myAttractor.init_range();
//projection.output();
LogInfo("\nRendering\n");
clock_t start, end;
start = clock();
for(unsigned int j = 1; j <= 100; ++j) {
for(unsigned int i = 0; i <= iterations; i++) {
myAttractor.iterate();
myAttractor.plot();
}
if(verbose >= 0) {
std::cout << "\r" << j << "% done" << std::flush;
}
}
end = clock();
double totalIterations = 100.0*iterations;
double totalTime = ((double)(end-start)/(double)(CLOCKS_PER_SEC));
LogInfo("\nTotal clock time: %f\n", totalTime);
LogMoreInfo("Average iterations per second: %f\n\n", totalIterations/totalTime);
// saving output
char filename[50];
time_t t = time(0);
struct tm* lt = localtime(&t);
int r = rand() % 10;
sprintf(filename, "render/attractor_%04d-%02d-%02d_%02d-%02d-%02d-%01d.raw", lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, r);
start = clock();
//canvas->output_file(filename);
end = clock();
totalTime = ((double)(end-start)/(double)(CLOCKS_PER_SEC));
LogInfo("Total clock time for writing png: %f\n", totalTime);
return 0;
}