|
@ -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); |
|
|
} |
|
|
} |
|
|