TASK_SRC = dummy.cc move_square.cc hit_shape.cc
TASK_OBJ = $(TASK_SRC:.cc=.task)
-all: main TAGS $(TASK_OBJ)
+all: mash main TAGS $(TASK_OBJ)
TAGS: *.cc *.h
etags *.cc *.h
intelligence.o
$(CXX) -lX11 $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
-art: art.o misc.o simple_window.o universe.o polygon.o map.o \
- task.o retina.o manipulator.o approximer.o intelligence.o
+mash: misc.o universe.o polygon.o xfig_tracer.o mash.o
$(CXX) -lX11 $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
%.task: %.cc misc.o universe.o polygon.o map.o task.o manipulator.o
cout << "Retina screen shot saved in /tmp/retina.ppm" << endl;
{
XFigTracer tracer("/tmp/universe.fig");
- universe.print_fig(&tracer);
+ universe.print_xfig(&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 xfig_tracer.o -L/usr/X11R6/lib/"; -*-
#include <iostream>
#include <fstream>
ys[k] = scalar_t(h)/2 + radius * sin(-alpha);
}
Polygon *p;
- p = new Polygon(1.0, 0.5, 0.5, 0.5, xs, ys, nb);
+ p = new Polygon(1.0, 0.0, 0.0, 0.0, xs, ys, nb);
p->set_position(scalar_t(w/2), scalar_t(h) * 0.75, 0);
p->set_speed(0, 0, 0);
universe.initialize(p);
cout << "n = " << n << " nb_edges = " << nb_edges << endl;
- blocks[i] = new Polygon(1.0, 1.0, 1.0, 0.0, xs, ys, nb_edges);
+ scalar_t red, green, blue;
do {
- blocks[i]->set_position(drand48() * w/2 + w/4, drand48() * h/2 + h/4, M_PI * drand48());
+ red = scalar_t(16 * int(drand48() * 16))/255.0;
+ green = scalar_t(16 * int(drand48() * 16))/255.0;
+ blue = scalar_t(16 * int(drand48() * 16))/255.0;
+ } while((red > 0.1 && green > 0.1 && blue > 0.1) ||
+ (red < 0.9 && green < 0.9 && blue < 0.9));
+ blocks[i] = new Polygon(1.0, red, green, blue, xs, ys, nb_edges);
+ do {
+ blocks[i]->set_position(drand48() * w * 0.9 + w * 0.05, drand48() * 3 * h / 4 + h/8, M_PI * drand48());
blocks[i]->set_speed(0, 0, 0);
// universe.initialize(blocks[i]);
for(int j = 0; j < i + 1; j++) {
char buffer[1024];
sprintf(buffer, "/tmp/mash_%06d.fig", n);
XFigTracer tracer(buffer);
- universe.print_fig(&tracer);
+ universe.print_xfig(&tracer);
cout << "Wrote " << buffer << endl;
}
}
XFigTracer tracer("/tmp/mash.fig");
- universe.print_fig(&tracer);
+ universe.print_xfig(&tracer);
exit(0);
}
return new Polygon(_mass, _red, _green, _blue, _relative_x, _relative_y, _nb_vertices);
}
-void Polygon::print_fig(XFigTracer *tracer) {
- tracer->draw_polygon(_nb_vertices, _x, _y);
+void Polygon::color_xfig(XFigTracer *tracer) {
+ tracer->add_color(int(255 * _red), int(255 * _green), int(255 * _blue));
+}
+
+void Polygon::print_xfig(XFigTracer *tracer) {
+ tracer->draw_polygon(int(255 * _red), int(255 * _green), int(255 * _blue),
+ _nb_vertices, _x, _y);
}
void Polygon::draw(SimpleWindow *window) {
Polygon *clone();
- void print_fig(XFigTracer *tracer);
+ void color_xfig(XFigTracer *tracer);
+ void print_xfig(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(XFigTracer *tracer) {
+void Universe::print_xfig(XFigTracer *tracer) {
for(int n = 0; n < _nb_polygons; n++) {
if(_polygons[n]) {
- _polygons[n]->print_fig(tracer);
+ _polygons[n]->color_xfig(tracer);
+ }
+ }
+ for(int n = 0; n < _nb_polygons; n++) {
+ if(_polygons[n]) {
+ _polygons[n]->print_xfig(tracer);
}
}
}
void apply_collision_forces(scalar_t dt);
bool update(scalar_t dt);
Polygon *pick_polygon(scalar_t x, scalar_t y);
- void print_fig(XFigTracer *tracer);
+ void print_xfig(XFigTracer *tracer);
void draw(SimpleWindow *window);
};
--- /dev/null
+
+////////////////////////////////////////////////////////////////////
+// START_IP_HEADER //
+// //
+// Written by Francois Fleuret //
+// Contact <francois.fleuret@idiap.ch> for comments & bug reports //
+// //
+// END_IP_HEADER //
+////////////////////////////////////////////////////////////////////
+
+ // ================================================
+ // (3.1) Color Pseudo-objects (user-defined colors)
+ // ================================================
+ // This is used to define arbitrary colors beyond the 32 standard colors.
+ // The color objects must be defined before any other Fig objects.
+
+ // First line:
+ // type name (brief description)
+ // ---- ---- -------------------
+ // int object_code (always 0)
+ // int color_number (color number, from 32-543 (512 total))
+ // hex string rgb values (hexadecimal string describing red,
+
+#include "xfig_tracer.h"
+
+XFigTracer::XFigTracer(const char *name) {
+ _file = new ofstream(name);
+ (*_file) << "#FIG 3.2" << endl;
+ (*_file) << "Portrait" << endl;
+ (*_file) << "Center" << endl;
+ (*_file) << "Metric" << endl;
+ (*_file) << "A4 " << endl;
+ (*_file) << "100.00" << endl;
+ (*_file) << "Single" << endl;
+ (*_file) << "-2" << endl;
+ (*_file) << "1200 2" << endl;
+ _nb_user_colors = 0;
+}
+
+XFigTracer::~XFigTracer() {
+ _file->flush();
+ delete _file;
+}
+
+int XFigTracer::user_color(int red, int green, int blue) {
+ for(int c = 0; c < _nb_user_colors; c++) {
+ if(red == _palette_red[c] &&
+ green == _palette_green[c] &&
+ blue == _palette_blue[c]) return 32 + c;
+ }
+ cerr << "Unknown color!" << endl;
+ exit(1);
+}
+
+void XFigTracer::add_color(int red, int green, int blue) {
+ for(int c = 0; c < _nb_user_colors; c++) {
+ if(red == _palette_red[c] &&
+ green == _palette_green[c] &&
+ blue == _palette_blue[c]) return;
+ }
+ if(_nb_user_colors < max_nb_user_colors) {
+ _palette_red[_nb_user_colors] = red;
+ _palette_green[_nb_user_colors] = green;
+ _palette_blue[_nb_user_colors] = blue;
+ char buffer[2];
+ (*_file) << "0 " << 32 + _nb_user_colors << " #";
+ sprintf(buffer, "%02x", _palette_red[_nb_user_colors]);
+ (*_file) << buffer;
+ sprintf(buffer, "%02x", _palette_green[_nb_user_colors]);
+ (*_file) << buffer;
+ sprintf(buffer, "%02x", _palette_blue[_nb_user_colors]);
+ (*_file) << buffer;
+ (*_file) << endl;
+ _nb_user_colors++;
+ } else {
+ cerr << "Too many colors!" << endl;
+ exit(1);
+ }
+}
+
+void XFigTracer::draw_polygon(int red, int green, int blue,
+ int nb_vertices, scalar_t *x, scalar_t *y) {
+ int c = user_color(red, green, blue);
+ (*_file) << "2 3 0 1 7 " << c << " 50 -1 20 0.000 0 0 -1 0 0 " << nb_vertices + 1 << endl;
+ (*_file) << " ";
+ for(int n = 0; n < nb_vertices; n++) (*_file) << " " << int(x[n]*10) << " " << int(y[n]*10);
+ (*_file) << " " << int(x[0]*10) << " " << int(y[0]*10);
+ (*_file) << endl;
+}
--- /dev/null
+
+////////////////////////////////////////////////////////////////////
+// START_IP_HEADER //
+// //
+// Written by Francois Fleuret //
+// Contact <francois.fleuret@idiap.ch> for comments & bug reports //
+// //
+// END_IP_HEADER //
+////////////////////////////////////////////////////////////////////
+
+#ifndef XFIG_TRACER_H
+#define XFIG_TRACER_H
+
+#include <iostream>
+#include <fstream>
+
+using namespace std;
+
+#include "misc.h"
+
+class XFigTracer {
+ ofstream *_file;
+ int _nb_user_colors;
+ static const int max_nb_user_colors = 100;
+ int _palette_red[max_nb_user_colors];
+ int _palette_green[max_nb_user_colors];
+ int _palette_blue[max_nb_user_colors],;
+ int user_color(int red, int green, int blue);
+public:
+ XFigTracer(const char *name);
+ ~XFigTracer();
+ void add_color(int red, int green, int blue);
+ void draw_polygon(int red, int green, int blue,
+ int nb_vertices, scalar_t *x, scalar_t *y);
+};
+
+#endif