-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard.php
More file actions
170 lines (124 loc) · 4.46 KB
/
Copy pathboard.php
File metadata and controls
170 lines (124 loc) · 4.46 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
$v = urldecode($_REQUEST['vector']);
#$v = 'sol,name=0.07936855820532118,m=9,n=10:o,2,o,2,o,2,o,2,o,1,2,o,2,o,2,o,2,o,2,o,o,3,o,3,o,2,o,2,o,2,2,o,3,o,2,o,2,o,3,o,o,2,o,1,o,2,o,2,o,2,2,o,1,o,2,o,3,o,2,o,o,2,o,2,o,3,o,3,o,2,2,o,1,o,3,o,2,o,3,o,o,1,o,2,o,1,o,1,o,1,';
if ($_REQUEST['fmt']) {
$fmt = urldecode($_REQUEST['fmt']);
} else {
$fmt = "quadratic";
$fmt = "triangular";
}
if ($_REQUEST['d']) {
$d = urldecode($_REQUEST['d']);
} else {
$d = 35;
}
$pat = '(mines|sol),name=([^,]+),m=([0-9]+),n=([0-9]+):([0-9\*,\o\-_\?]+)$';
ereg($pat,$v,$regs);
$name = $regs[2];
$m = $regs[3];
$n = $regs[4];
$brd = $regs[5];
$bord = split( ",", $brd);
$board = array();
for ($i = 0; $i<$m; $i++) {
for ($j = 0; $j < $n; $j++ ) {
$board[$i][$j] = $bord[$i*$n + $j];
if ($board[$i][$j]==='_') $board[$i][$j] = '-';
}
}
//print_r($board);
//exit;
/*$board = array();
$board[0][0] = '1';
$board[0][1] = '';
$board[1][0] = '*';
$board[1][1] = '?';
*/
$nx = (count($board,1)/count($board,0) - 1);
$ny = count($board,0);
if ($fmt=="quadratic")
{
$cellwidth = $d*50/35;
$cellheight = $d*50/35;
$cellborder = 3;
$boardborder = 3;
$im_side_x = 2*$boardborder + $nx*($cellwidth + $cellborder) - $cellborder;
$im_side_y = 2*$boardborder + $ny*($cellwidth + $cellborder);
$im = imagecreatetruecolor( $im_side_x, $im_side_y );
$white = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 170,10, 10);
putenv('GDFONTPATH=' . realpath('.'));
$font_file = './FreeSansBold.ttf';
$font_size = 16*$d/35;
for ($i = 0; $i < $ny; $i++) {
for ($j = 0; $j < $nx; $j++ ) {
$x1 = $boardborder + $j*($cellwidth + $cellborder);
$y1 = $boardborder + $i*($cellwidth + $cellborder);
$x2 = $boardborder + ($j+1)*($cellwidth + $cellborder) - $cellborder;
$y2 = $boardborder + ($i+1)*($cellwidth + $cellborder) - $cellborder;
imagefilledrectangle($im, $x1,$y1,$x2,$y2, $white);
imagettftext($im, $font_size, 0, ($x1+$x2-$font_size/2)/2, ($y1+$y2+$font_size)/2, $textcolor, $font_file, $board[$i][$j]);
// imagestring($im, 5, ($x1+$x2-$cellborder)/2, ($y1+$y2-$cellborder)/2, $board[$i][$j], $textcolor);
}
}
}
else if ($fmt == "triangular")
{
$im_side_x = $d*($nx+2)*sqrt(3);
$im_side_y = $d*($ny+2);
$im = imagecreatetruecolor( $im_side_x, $im_side_y );
$white = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 170,10, 10);
putenv('GDFONTPATH=' . realpath('.'));
$font_file = './FreeSansBold.ttf';
$font_size = 16*$d/35;
imagefilledrectangle($im, 0,0,$im_side_x,$im_side_y, $white);
for ($i = 1; $i <= $ny; $i++) {
for ($j = 1; $j <= $nx; $j++ ) {
$b[$i][$j]['y'] = $d*$i ;
$b[$i][$j]['x'] = $d*sqrt(3)*$j;
if (($i + $j) % 2 == 0) {
$a[$i][$j][1]['y'] = $d*$i;
$a[$i][$j][1]['x'] = $d*sqrt(3)*($j-1/2);
$a[$i][$j][2]['y'] = $d*($i+1);
$a[$i][$j][2]['x'] = $d*sqrt(3)*($j+1/2);
$a[$i][$j][3]['y'] = $d*($i-1);
$a[$i][$j][3]['x'] = $d*sqrt(3)*($j+1/2);
imageline($im, $a[$i][$j][1]['x'], $a[$i][$j][1]['y'], $a[$i][$j][2]['x'], $a[$i][$j][2]['y'], $textcolor);
imageline($im, $a[$i][$j][2]['x'], $a[$i][$j][2]['y'], $a[$i][$j][3]['x'], $a[$i][$j][3]['y'], $textcolor);
imageline($im, $a[$i][$j][3]['x'], $a[$i][$j][3]['y'], $a[$i][$j][1]['x'], $a[$i][$j][1]['y'], $textcolor);
}
if ( ($i % 2 == 0) && ($j == 1) ) {
imageline($im, $d*sqrt(3)*(1/2), $d*($i-1), $d*sqrt(3)*(1/2), $d*($i+1), $textcolor);
}
if ( ($j % 2 == 0) && ($i == 1) ) {
imageline($im, $d*sqrt(3)*($j-1/2), 0, $d*sqrt(3)*($j+1/2), $d, $textcolor);
}
if ( ($j % 2 != 0) && ($i == $ny) ) {
if ($i % 2 == 0) {
imageline($im, $d*sqrt(3)*($j-1/2), $d*($ny+1), $d*sqrt(3)*($j+1/2), $d*$ny, $textcolor);
}
}
else if ( ($j % 2 == 0) && ($i == $ny) ) {
if ($i % 2 != 0) {
imageline($im, $d*sqrt(3)*($j-1/2), $d*($ny+1), $d*sqrt(3)*($j+1/2), $d*$ny, $textcolor);
}
}
$x1 = $b[$i][$j]['x'];
$y1 = $b[$i][$j]['y'];
if (($i + $j) % 2 != 0) {
$x1 = $x1 - $d/3;
// $y1 = $y1 - $d/10;
}
else {
$x1 = $x1 + $d/10;
}
$y1 = $y1 - $d/5;
$x1 = $x1 + $d/6;
imagettftext($im, $font_size, 0, $x1-$font_size/2, $y1+$font_size, $textcolor, $font_file, $board[$i-1][$j-1]);
}
}
}
header('Content-type: image/png');
imagepng($im);
?>