#include "task.h"
#include "simple_window.h"
#include "universe.h"
+#include "plotter.h"
#include "retina.h"
#include "manipulator.h"
#include "intelligence.h"
retina.save_as_ppm("/tmp/retina.ppm");
cout << "Retina screen shot saved in /tmp/retina.ppm" << endl;
+ {
+ Plotter plotter(int(universe.width()), int(universe.height()), 4);
+ plotter.save_as_ppm(&universe, "/tmp/plotter.ppm", 16);
+ }
+
{
XFigTracer tracer("/tmp/universe.fig");
universe.print_xfig(&tracer);
}
}
-void Plotter::save_as_ppm(Universe *universe, const char *filename) {
+void Plotter::save_as_ppm(Universe *universe, const char *filename, int downscale) {
reset();
for(int p = 0; p < universe->_nb_polygons; p++) {
if(universe->_polygons[p]) {
}
fill();
- unsigned char *image = new unsigned char[_width * _height * 3];
+ unsigned char *image = new unsigned char[(_width/downscale) * (_height/downscale) * 3];
int n = 0;
- for(int y = 0; y < _height / _scaling; y++) {
- for(int x = 0; x < _width / _scaling; x++) {
- image[n++] = red_sum(x * _scaling, y * _scaling, (x + 1) * _scaling, (y + 1) * _scaling) / scalar_t(_scaling * _scaling);
- image[n++] = green_sum(x * _scaling, y * _scaling, (x + 1) * _scaling, (y + 1) * _scaling) / scalar_t(_scaling * _scaling);
- image[n++] = blue_sum(x * _scaling, y * _scaling, (x + 1) * _scaling, (y + 1) * _scaling) / scalar_t(_scaling * _scaling);
+ for(int y = 0; y < _height / downscale; y++) {
+ for(int x = 0; x < _width / downscale; x++) {
+ image[n++] = int(255 * red_sum(x * downscale, y * downscale, (x + 1) * downscale, (y + 1) * downscale) / scalar_t(downscale * downscale));
+ image[n++] = int(255 * green_sum(x * downscale, y * downscale, (x + 1) * downscale, (y + 1) * downscale) / scalar_t(downscale * downscale));
+ image[n++] = int(255 * blue_sum(x * downscale, y * downscale, (x + 1) * downscale, (y + 1) * downscale) / scalar_t(downscale * downscale));
}
}
ofstream out(filename);
out << "P6" << endl;
- out << _width << " " << _height << endl;
+ out << _width/downscale << " " << _height/downscale << endl;
out << 255 << endl;
- out.write((char *) image, _width * _height * 3);
+ out.write((char *) image, (_width/downscale) * (_height/downscale) * 3);
out.flush();
delete[] image;