Browse Source

no png for mac atm, tabs <> spaces, other defines for testing

master
Joshua Moerman 15 years ago
parent
commit
dcd8229010
  1. 214
      Canvas.cpp
  2. 2
      Projector.cpp
  3. 6
      defines.hpp

214
Canvas.cpp

@ -1,12 +1,12 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include <cstdint> //#include <cstdint>
using namespace std; using namespace std;
#include "pngwriter/pngwriter.h" //#include "pngwriter/pngwriter.h"
#include "Canvas.hpp" #include "Canvas.hpp"
@ -14,9 +14,9 @@ using namespace std;
Canvas::Canvas(unsigned int width, unsigned int height, unsigned int num_colors): Canvas::Canvas(unsigned int width, unsigned int height, unsigned int num_colors):
dim(2), width(width), height(height), num_colors(num_colors), v(0) { dim(2), width(width), height(height), num_colors(num_colors), v(0) {
int_array = new unsigned int[width*height*num_colors]; int_array = new unsigned int[width*height*num_colors];
size = new unsigned int[2]; size = new unsigned int[2];
size[0] = width; size[0] = width;
size[1] = height; size[1] = height;
assert(int_array != NULL); assert(int_array != NULL);
@ -131,117 +131,117 @@ void Canvas::output_file(const char * filename){
power[i] = 1; power[i] = 1;
} else { } else {
power[i] = 1; power[i] = 1;
}
if ( n <= 10 ) {
cout << "not enough data" << endl;
} }
}
if ( n <= 10 ) {
const double vibrancy = 2.0; cout << "not enough data" << endl;
double averagePower = 0; }
for ( unsigned int i = 0; i < num_colors; i++ ) { }
averagePower += power[i];
} const double vibrancy = 2.0;
averagePower /= (double)num_colors; double averagePower = 0;
for ( unsigned int i = 0; i < num_colors; i++ ) { for ( unsigned int i = 0; i < num_colors; i++ ) {
power[i] = vibrancy*power[i] + (1.0 - vibrancy)*averagePower; averagePower += power[i];
}
averagePower /= (double)num_colors;
for ( unsigned int i = 0; i < num_colors; i++ ) {
power[i] = vibrancy*power[i] + (1.0 - vibrancy)*averagePower;
} }
pngwriter * pngFile = new pngwriter(width, height, 0.0, filename); //pngwriter * pngFile = new pngwriter(width, height, 0.0, filename);
pngFile->setcompressionlevel(9); //pngFile->setcompressionlevel(9);
pngFile->settext("Attractor", "Joshua Moerman", "A awesome attractor", "AwesomeAttractor"); //pngFile->settext("Attractor", "Joshua Moerman", "A awesome attractor", "AwesomeAttractor");
for ( unsigned int x = 0; x < width; x++ ) { for ( unsigned int x = 0; x < width; x++ ) {
for ( unsigned int y = 0; y < height; y++ ) { for ( unsigned int y = 0; y < height; y++ ) {
double r = 0.0; double r = 0.0;
double g = 0.0; double g = 0.0;
double b = 0.0; double b = 0.0;
for ( unsigned int c = 0; c < num_colors; c++ ) { for ( unsigned int c = 0; c < num_colors; c++ ) {
const double norm_value = (double)int_array[x + y*width + c*width*height]/max_int[c]; const double norm_value = (double)int_array[x + y*width + c*width*height]/max_int[c];
switch(c){ switch(c){
case 0: { case 0: {
r = (pow(norm_value, power[c]))*3.5; r = (pow(norm_value, power[c]))*3.5;
break; break;
}
case 1: {
g = (pow(norm_value, power[c]))*3.0;
break;
}
case 2: {
b = (pow(norm_value, power[c]))*3.0;
break;
} }
case 1: { default:
g = (pow(norm_value, power[c]))*3.0; break;
break; }
} }
case 2: { //pngwriter clips values for me
b = (pow(norm_value, power[c]))*3.0; //pngFile->plot(x, y, r, g, b);
break; }
} }
default:
break;
}
}
//pngwriter clips values for me
pngFile->plot(x, y, r, g, b);
}
}
delete max_int; delete max_int;
delete power; delete power;
cout << "ready for writing file i suppose" << endl; cout << "ready for writing file i suppose" << endl;
ofstream file(filename); ofstream file(filename);
if ( !file ) { if ( !file ) {
cout << "jij hebt pech, geen png voor jou" << endl; cout << "jij hebt pech, geen png voor jou" << endl;
} }
cout << filename << endl; cout << filename << endl;
pngFile->close(); //pngFile->close();
} }
void Canvas::output_file(){ void Canvas::output_file(){
char filename[50]; char filename[50];
time_t t = time(0); time_t t = time(0);
struct tm* lt = localtime(&t); struct tm* lt = localtime(&t);
int r = rand() % 10; int r = rand() % 10;
sprintf(filename, "render/attractor_%04d-%02d-%02d_%02d-%02d-%02d-%01d.png", lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, r); sprintf(filename, "render/attractor_%04d-%02d-%02d_%02d-%02d-%02d-%01d.png", lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, r);
output_file(filename); output_file(filename);
} }
void Canvas::output_raw(const char * filename){ void Canvas::output_raw(const char * filename){
ofstream outfile (filename, ofstream::binary); ofstream outfile (filename, ofstream::binary);
outfile.write(reinterpret_cast<char*>(int_array), sizeof(unsigned int)*width*height*num_colors); outfile.write(reinterpret_cast<char*>(int_array), sizeof(unsigned int)*width*height*num_colors);
} }
void Canvas::output_raw(){ void Canvas::output_raw(){
char filename[52]; char filename[52];
time_t t = time(0); time_t t = time(0);
struct tm* lt = localtime(&t); struct tm* lt = localtime(&t);
int r = rand() % 10; int r = rand() % 10;
sprintf(filename, "render/canv%dx%d_%04d-%02d-%02d_%02d-%02d-%02d-%01d.canv", width, height, lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, r); sprintf(filename, "render/canv%dx%d_%04d-%02d-%02d_%02d-%02d-%02d-%01d.canv", width, height, lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec, r);
output_raw(filename); output_raw(filename);
} }
void Canvas::input_raw(const char * filename){ void Canvas::input_raw(const char * filename){
ifstream infile(filename, ifstream::binary); ifstream infile(filename, ifstream::binary);
if ( ! infile ) { if ( ! infile ) {
cout << "poep" << endl; cout << "poep" << endl;
return; return;
} }
infile.seekg (0, ios::end); infile.seekg (0, ios::end);
int length = infile.tellg(); int length = infile.tellg();
infile.seekg (0, ios::beg); infile.seekg (0, ios::beg);
cout << "length: " << length << " =? " << static_cast<int>(width*height*num_colors*sizeof(unsigned int)) << endl; cout << "length: " << length << " =? " << static_cast<int>(width*height*num_colors*sizeof(unsigned int)) << endl;
infile.read (reinterpret_cast<char*>(int_array), sizeof (unsigned int)*width*height*num_colors); infile.read (reinterpret_cast<char*>(int_array), sizeof (unsigned int)*width*height*num_colors);
} }

2
Projector.cpp

@ -93,7 +93,7 @@ void Projector::plot(const double * point) {
//cout << x << ", " << y << endl; //cout << x << ", " << y << endl;
canvas->plot(x+0.01*rand()/(double)RAND_MAX-0.005, y+0.01*rand()/(double)RAND_MAX-0.005); canvas->plot(x, y);
if ( even(point[2]*17) ) if ( even(point[2]*17) )
canvas->plot(x, y, 1); canvas->plot(x, y, 1);
if ( even(point[2]*17+0.6) ) if ( even(point[2]*17+0.6) )

6
defines.hpp

@ -1,15 +1,15 @@
//TODO: do this with files //TODO: do this with files
#define ATTRACTOR_FILE "attractors/testPolynomial.stf" #define ATTRACTOR_FILE "attractors/testLorenz.stf"
#ifdef UNI_BUILD #ifdef UNI_BUILD
#warning Building for the RU, are you sure? #warning Building for the RU, are you sure?
#define WIDTH 8000 #define WIDTH 8000
#define HEIGHT 8000 #define HEIGHT 8000
#define ITERATIONS 800000000 #define ITERATIONS 4200000000
#else #else
#define WIDTH 800 #define WIDTH 800
#define HEIGHT 800 #define HEIGHT 800
#define ITERATIONS 200000 #define ITERATIONS 20000000
#endif #endif