-
Notifications
You must be signed in to change notification settings - Fork 0
/
SVGPrinter.cpp
62 lines (53 loc) · 2.64 KB
/
SVGPrinter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "SVGPrinter.h"
#include "Maze.h"
#include <fstream>
#include <iostream>
#define PIX 20
using namespace std;
void SVGPrinter::print(Maze const& mz){
Matrix<Cell>* m=mz.m;
int dim=mz.dim;
ofstream out,solution;
out.open("out.svg");
solution.open("solution.svg");
out<< "<?xml version=\"1.0\" encoding=\"utf-8\"?>" << endl ;
out<< "<svg width=\"" <<PIX*dim <<"px\" height=\""<<PIX*dim<<"px\" xmlns=\"http://www.w3.org/2000/svg\">" << endl ;
out<< "<rect width=\"" << PIX*dim << "\" height=\"" << PIX*dim <<"\" style=\"fill:rgb(0,0,0)\"/>" << endl ;
solution<< "<?xml version=\"1.0\" encoding=\"utf-8\"?>" << endl ;
solution<< "<svg width=\"" <<PIX*dim <<"px\" height=\""<<PIX*dim<<"px\" xmlns=\"http://www.w3.org/2000/svg\">" << endl ;
solution<< "<rect width=\"" << PIX*dim << "\" height=\"" << PIX*dim <<"\" style=\"fill:rgb(0,0,0)\"/>" << endl ;
for(int i=0;i<dim;i++){
for(int j=0;j<dim;j++){
Cell c = m->get(i,j);
int x00,x01,x10,x11;
x00=x01=j*PIX;
x10=x11=j*PIX+PIX-1;
int y00,y01,y10,y11;
y00=y10=i*PIX;
y01=y11=i*PIX+PIX-1;
if(c.up()){
out<< "<line x1=\"" << x00 <<"\" y1=\"" << y00 << "\" x2=\"" <<x10<< "\" y2=\"" << y10 <<"\" style=\"stroke:rgb(255,0,0);stroke-width:2\" />" << endl ;
solution<< "<line x1=\"" << x00 <<"\" y1=\"" << y00 << "\" x2=\"" <<x10<< "\" y2=\"" << y10 <<"\" style=\"stroke:rgb(255,0,0);stroke-width:2\" />" << endl ;
}
if(c.left()){
out<< "<line x1=\"" << x00 <<"\" y1=\"" << y00 << "\" x2=\"" <<x01<< "\" y2=\"" << y01 <<"\" style=\"stroke:rgb(255,0,0);stroke-width:2\" />" << endl ;
solution<< "<line x1=\"" << x00 <<"\" y1=\"" << y00 << "\" x2=\"" <<x01<< "\" y2=\"" << y01 <<"\" style=\"stroke:rgb(255,0,0);stroke-width:2\" />" << endl ;
}
if(c.right()){
out<< "<line x1=\"" << x10 <<"\" y1=\"" << y10 << "\" x2=\"" <<x11<< "\" y2=\"" << y11 <<"\" style=\"stroke:rgb(255,0,0);stroke-width:2\" />" << endl ;
solution<< "<line x1=\"" << x10 <<"\" y1=\"" << y10 << "\" x2=\"" <<x11<< "\" y2=\"" << y11 <<"\" style=\"stroke:rgb(255,0,0);stroke-width:2\" />" << endl ;
}
if(c.down()){
out<< "<line x1=\"" << x01 <<"\" y1=\"" << y01 << "\" x2=\"" <<x11<< "\" y2=\"" << y11 <<"\" style=\"stroke:rgb(255,0,0);stroke-width:2\" />" << endl ;
solution<< "<line x1=\"" << x01 <<"\" y1=\"" << y01 << "\" x2=\"" <<x11<< "\" y2=\"" << y11 <<"\" style=\"stroke:rgb(255,0,0);stroke-width:2\" />" << endl ;
}
if(c.isSolution()){
solution<< "<circle cx=\"" << x00 + PIX/2 <<"\" cy=\"" << y00 + PIX/2 <<"\" r=\"" << PIX/4 <<"\" fill=\"white\" />" << endl ;
}
}
}
out << "</svg>" << endl ;
solution << "</svg>" << endl ;
out.close();
solution.close();
}