TAGS: *.cc *.h
etags *.cc *.h
-main: main.o misc.o simple_window.o universe.o polygon.o map.o \
- task.o retina.o manipulator.o approximer.o intelligence.o
+main: main.o misc.o \
+ simple_window.o \
+ universe.o \
+ xfig_tracer.o \
+ polygon.o \
+ map.o \
+ task.o \
+ retina.o \
+ manipulator.o \
+ approximer.o \
+ intelligence.o
$(CXX) -lX11 $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
art: art.o misc.o simple_window.o universe.o polygon.o map.o \
#include "retina.h"
#include "manipulator.h"
#include "intelligence.h"
+#include "xfig_tracer.h"
// To train
// ./main --task hit_shape.task 0 --action-mode=random --nb-ticks=5000 --proportion-for-training=0.5 --save-file=dump.mem --no-window
retina.save_as_ppm("/tmp/retina.ppm");
cout << "Retina screen shot saved in /tmp/retina.ppm" << endl;
{
- ofstream out("/tmp/universe.fig");
- universe.print_fig(out);
+ XFigTracer tracer("/tmp/universe.fig");
+ universe.print_fig(&tracer);
}
}
else if(strcmp(se.key, "Shift_L") == 0 || strcmp(se.key, "Shift_R") == 0) press_shift = true;
-// -*- compile-command:"g++ -lX11 -Wall -g -O3 -o mash misc.o universe.o polygon.o mash.cc -L/usr/X11R6/lib/"; -*-
+// -*- compile-command:"g++ -lX11 -Wall -g -O3 -o mash misc.o universe.o polygon.o mash.cc xfig_tracer.o -L/usr/X11R6/lib/"; -*-
#include <iostream>
#include <fstream>
#include "universe.h"
int main(int argc, char **argv) {
- int nb_heur = 75;
+ int nb_heur = 50;
int w = 1000, h = 1000;
Universe universe(nb_heur + 1, w, h);
if(y < 0) y = 0;
else if(y >= nb_max_edges) y = nb_max_edges-1;
}
- fail = (n < 8) || (x != 0) || (y != 0);
+ fail = (n < 10) || (x != 0) || (y != 0);
} while(fail);
scalar_t xs[nb_max_edges], ys[nb_max_edges];
for(int l = 0; l < n; l++) {
int pl = (l + n - 1)%n, nl = (l + 1)%n;
if(xt[nl] - xt[l] != xt[l] - xt[pl] || yt[nl] - yt[l] != yt[l] - yt[pl]) {
- xs[nb_edges] = scalar_t(xt[l]) * 15;
- ys[nb_edges] = scalar_t(yt[l]) * 15;
+ xs[nb_edges] = scalar_t(xt[l]) * 25;
+ ys[nb_edges] = scalar_t(yt[l]) * 25;
nb_edges++;
}
}
if(n%1000 == 0) {
char buffer[1024];
sprintf(buffer, "/tmp/mash_%06d.fig", n);
- ofstream os(buffer);
- universe.print_fig(os);
+ XFigTracer tracer(buffer);
+ universe.print_fig(&tracer);
cout << "Wrote " << buffer << endl;
}
}
- ofstream os("/tmp/mash.fig");
- universe.print_fig(os);
+ XFigTracer tracer("/tmp/mash.fig");
+ universe.print_fig(&tracer);
exit(0);
}
return new Polygon(_mass, _red, _green, _blue, _relative_x, _relative_y, _nb_vertices);
}
-void Polygon::print_fig(ostream &os) {
- // os << "2 3 0 1 0 7 50 -1 20 0.000 0 0 -1 0 0 " << _nb_vertices + 1 << endl;
- int c;
- do { c = int(drand48() * 32); } while(c == 7);
- os << "2 3 0 1 0 6 50 -1 20 0.000 0 0 -1 0 0 " << _nb_vertices + 1 << endl;
- // os << "2 3 0 0 0 " << c << " 50 -1 20 0.000 0 0 -1 0 0 " << _nb_vertices + 1 << endl;
- // os << "2 3 0 2 7 " << c << " 50 -1 20 0.000 0 0 -1 0 0 " << _nb_vertices + 1 << endl;
- os << " ";
- for(int n = 0; n < _nb_vertices; n++) os << " " << int(_x[n]*10) << " " << int(_y[n]*10);
- os << " " << int(_x[0]*10) << " " << int(_y[0]*10);
- os << endl;
+void Polygon::print_fig(XFigTracer *tracer) {
+ tracer->draw_polygon(_nb_vertices, _x, _y);
}
void Polygon::draw(SimpleWindow *window) {
#include "misc.h"
#include "simple_window.h"
+#include "xfig_tracer.h"
class Polygon {
struct Triangle {
Polygon *clone();
- void print_fig(ostream &os);
+ void print_fig(XFigTracer *tracer);
void draw(SimpleWindow *window);
void draw_contours(SimpleWindow *window);
void set_vertex(int k, scalar_t x, scalar_t y);
return 0;
}
-void Universe::print_fig(ostream &os) {
- os << "#FIG 3.2" << endl;
- os << "Portrait" << endl;
- os << "Center" << endl;
- os << "Metric" << endl;
- os << "A4 " << endl;
- os << "100.00" << endl;
- os << "Single" << endl;
- os << "-2" << endl;
- os << "1200 2" << endl;
- for(int n = 0; n < _nb_polygons; n++) if(_polygons[n]) _polygons[n]->print_fig(os);
+void Universe::print_fig(XFigTracer *tracer) {
+ for(int n = 0; n < _nb_polygons; n++) {
+ if(_polygons[n]) {
+ _polygons[n]->print_fig(tracer);
+ }
+ }
}
void Universe::draw(SimpleWindow *window) {
void apply_collision_forces(scalar_t dt);
bool update(scalar_t dt);
Polygon *pick_polygon(scalar_t x, scalar_t y);
- void print_fig(ostream &os);
+ void print_fig(XFigTracer *tracer);
void draw(SimpleWindow *window);
};