#include <map> #include <set> #include <vector> #include <iostream> #include <algorithm> using namespace std; typedef pair<int,int> point; struct CoverSet { map<point,int> covcnt; set<point> cover1; void cover (const point& p, int mult = 1) { if (covcnt[p] == 1) { cover1.erase (p); } covcnt[p] += mult; if (covcnt[p] == 1) { cover1.insert (p); } } set<point>::const_iterator cover1_begin () const { return cover1.begin(); } set<point>::const_iterator cover1_end () const { return cover1.end(); } size_t size() const { return covcnt.size(); } }; int main (int ac, char **av) { size_t n = (ac > 1) ? atoi(av[1]) : 10; string scale = (ac > 2) ? av[2] : "10"; vector<point> newlist; newlist.push_back(point(0,0)); size_t tot = 0; bool dir = false; CoverSet c; cout << "%!PS-Adobe-2.0\n%%Orientation: Portrait\n%%Pages: 1\n%%BeginSetup\n%%EndSetup\n%%EndComments\n\n%%Page: 1 1\ngsave\n306 396 translate\n"; cout << scale << " " << scale << " scale\n.2 setlinewidth\n\n"; cout << "/hp {newpath moveto 0 -1 rmoveto 0 2 rlineto stroke} def\n"; cout << "/vp {newpath moveto -1 0 rmoveto 2 0 rlineto stroke} def\n"; cout << "0 0 1 setrgbcolor\n"; for (size_t round = 0; round < n; ++round) { if (round == n-1) { cout << "1 0 0 setrgbcolor\n"; } tot += newlist.size(); for (vector<point>::iterator i = newlist.begin(); i != newlist.end(); ++i) { c.cover(*i, 2); if (dir) { c.cover (point(i->first, i->second-1)); c.cover (point(i->first, i->second+1)); cout << i->first << " " << i->second << " hp\n"; } else { c.cover (point(i->first-1, i->second)); c.cover (point(i->first+1, i->second)); cout << i->first << " " << i->second << " vp\n"; } } dir = !dir; newlist.clear(); copy (c.cover1_begin(), c.cover1_end(), back_inserter(newlist)); } cout << "grestore\nshowpage\n%%EOF\n"; }