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
|
<?php
class css_shadow {
/** Create a point */
public static function xy($x, $y) {
return array('x'=>$x, 'y'=>$y);
}
/** Draw a "line" of shadows between two points */
public static function draw_line($p1, $p2, $steps, $color) {
$x1 = $p1['x'];
$y1 = $p1['y'];
$x2 = $p2['x'];
$y2 = $p2['y'];
$xstep = ($x2-$x1)/($steps-1);
$ystep = ($y2-$y1)/($steps-1);
$x = $x1;
$y = $y1;
$str = '';
for ($i=0; $i<$steps; $i++) {
$str.= sprintf ("\t%fem %fem %s,\n", $x, $y, $color);
$x+=$xstep;
$y+=$ystep;
}
return $str;
}
/** Connect the dots */
public static function draw_multiline($points, $steps, $color) {
$str = '';
foreach ($points as $point) {
if (isset($prev_point)) {
$str.= self::draw_line($prev_point, $point, $steps, $color);
}
$prev_point = $point;
}
return $str;
}
public static function points_border($args) {
$left = $right = $top = $bottom = $xoffset = $yoffset = 0;
if (isset($args['width'])) {
$left = $right = $top = $bottom = $args['width'];
}
if (isset($args['x'])) {
$left = $right = $args['x'];
}
if (isset($args['y'])) {
$top = $bottom = $args['y'];
}
if (isset($args['left'])) {
$left = $args['left'];
}
if (isset($args['right'])) {
$right = $args['right'];
}
if (isset($args['top'])) {
$top = $args['top'];
}
if (isset($args['bottom'])) {
$bottom = $args['bottom'];
}
if (isset($args['xoffset'])) {
$xoffset = $args['xoffset'];
}
if (isset($args['yoffset'])) {
$yoffset = $args['yoffset'];
}
$p = array('tl'=>self::xy($xoffset-$left , $yoffset-$top ),
'tr'=>self::xy($xoffset+$right, $yoffset-$top ),
'bl'=>self::xy($xoffset-$left , $yoffset+$bottom),
'br'=>self::xy($xoffset+$right, $yoffset+$bottom));
return $p;
}
public static function points_border_drop($args) {
$xoffset = $yoffset = $xdrop = $ydrop = 0;
if (isset($args['xoffset'])) {
$xoffset = $args['xoffset'];
}
if (isset($args['yoffset'])) {
$yoffset = $args['yoffset'];
}
if (isset($args['drop'])) {
$xdrop = $ydrop = $args['drop'];
}
if (isset($args['xdrop'])) {
$xdrop = $args['xdrop'];
}
if (isset($args['ydrop'])) {
$ydrop = $args['ydrop'];
}
$base = self::points_border($args);
if ($xdrop==$ydrop && $xdrop==0) { return $base; }
$args['xoffset'] = $xoffset+$xdrop;
$args['yoffset'] = $yoffset+$ydrop;
$drop = self::points_border($args);
$right = ($xdrop > 0);
$bottom = ($ydrop > 0);
/* 0|1
* -+-
* 2|3
*/
$q = 0;
if ($right) $q+=1;
if ($bottom) $q+=2;
switch ($q) {
case 0: // top-left (or bottom-right)
// clockwise, start in top-left
$ret = array($drop['tl'],
$drop['tr'],
$base['tr'],
$base['br'],
$base['bl'],
$drop['bl'],
$drop['tl']);
return $ret;
case 1: // top-right (or bottom-left)
// clockwise, start in top-right
$ret = array($drop['tr'],
$drop['br'],
$base['br'],
$base['bl'],
$base['tl'],
$drop['tl'],
$drop['tr']);
return $ret;
case 2: /* TODO */ break;
case 3: // top-left (or bottom-right)
// clockwise, start in top-left
$ret = array($base['tl'],
$base['tr'],
$drop['tr'],
$drop['br'],
$drop['bl'],
$base['bl'],
$base['tl']);
return $ret;
}
}
public static function draw_border($args) {
$steps = 0; $color = '#000000';
if (isset($args['steps'])) { $steps = $args['steps']; }
if (isset($args['color'])) { $color = $args['color']; }
return self::draw_multiline(self::points_border_drop($args), $steps, $color);
}
}
|