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.

146 lines
3.6 KiB

#include "Logger.hpp"
#include <iostream>
#include <fstream>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include "Attractor.hpp"
#include "Canvas.hpp"
#include "Projector.hpp"
#include "canvae/PNG.hpp"
#include "ostream_helpers.h"
#include "defines.hpp"
#include "AwesomeAttractorConfig.h"
int verbose;
void showHelpText() {
14 years ago
std::cout <<
"Awesome Attractor, version " __DATE__ "\n"
"Usage: AwesomeAttractor [OPTION]* [FILE]\n"
14 years ago
"Optons:\n"
" -h, --help Shows this help\n"
" -q quiet mode\n"
" -v verbose mode\n"
" -V loud mode\n"
" -W N Sets width of output image (1024)\n"
" -H N Sets height of output image (1024)\n"
" -I N Sets number of milions of iterations (100)\n"
" -R Random attractor (no file will be read)\n"
14 years ago
<< std::endl;
exit(0);
}
int main(int argc, char* argv[]) {
14 years ago
verbose = 0;
std::string attractorFile = "";
std::string output_path = "render/";
bool generate_random = false;
14 years ago
unsigned int iterations = DEFAULT_ITERATIONS;
unsigned int width = DEFAULT_WIDTH;
unsigned int height = DEFAULT_HEIGHT;
srand(time(0));
14 years ago
if(argc <= 1) {
14 years ago
showHelpText();
}
for(int i = 1; i < argc; ++i) {
if(strcmp(argv[i], "-v") == 0) {
14 years ago
verbose = 1;
} else if(strcmp(argv[i], "-V") == 0) {
verbose = 3;
} else if(strcmp(argv[i], "-q") == 0) {
14 years ago
verbose = -1;
} else if(strcmp(argv[i], "--help") == 0) {
14 years ago
showHelpText();
14 years ago
} else if(strcmp(argv[i], "-h") == 0) {
showHelpText();
} else if(strcmp(argv[i], "-W") == 0) {
14 years ago
width = atoi(argv[++i]);
14 years ago
} else if(strcmp(argv[i], "-H") == 0) {
14 years ago
height = atoi(argv[++i]);
14 years ago
} else if(strcmp(argv[i], "-I") == 0) {
14 years ago
iterations = atoi(argv[++i]);
} else if(strcmp(argv[i], "-P") == 0) {
output_path = argv[++i];
} else if(strcmp(argv[i], "-R") == 0) {
generate_random = true;
14 years ago
} else {
attractorFile = argv[i];
}
}
LogInfo("Awesome Attractor, version %s\n", __DATE__);
Attractor* my_attractor_ptr = 0;
if(attractorFile != "")
my_attractor_ptr = new Attractor(attractorFile);
else if(generate_random)
my_attractor_ptr = new Attractor();
if(my_attractor_ptr == 0){
LogError("Nothing todo\n");
exit(0);
}
Attractor& myAttractor = *my_attractor_ptr;
myAttractor.projector->canvas = new PNG(width, height, 1);
14 years ago
myAttractor.init_range();
14 years ago
LogInfo("\nRendering\n");
14 years ago
clock_t start, end;
start = clock();
for(unsigned int j = 1; j <= iterations; ++j) {
for(unsigned int i = 0; i < 1000000; ++i) {
14 years ago
myAttractor.iterate();
myAttractor.plot();
}
//if (j%16 == 0) sleep(1);
if(verbose >= 0) {
std::cout << "\r" << j << " out of " << iterations << " done." << std::flush;
14 years ago
}
}
end = clock();
double totalIterations = 1000000.0*iterations;
14 years ago
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);
14 years ago
// saving output
char filename[256];
time_t t = time(0);
struct tm* lt = localtime(&t);
int r = rand() % 10;
sprintf(filename, (output_path+"attractor_%04d-%02d-%02d_%02d-%02d-%02d-%01d").c_str(), lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, r);
14 years ago
start = clock();
myAttractor.projector->canvas->output_file(filename);
14 years ago
end = clock();
14 years ago
totalTime = ((double)(end-start)/(double)(CLOCKS_PER_SEC));
14 years ago
LogInfo("Total clock time for writing png: %f\n", totalTime);
{
std::string path(filename);
path += ".stf";
std::ofstream file(path.c_str());
file << myAttractor.stf_output() << std::endl;
}
delete my_attractor_ptr;
14 years ago
return 0;
}