Browse Source

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

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

2
Projector.cpp

@ -93,7 +93,7 @@ void Projector::plot(const double * point) {
//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) )
canvas->plot(x, y, 1);
if ( even(point[2]*17+0.6) )

6
defines.hpp

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