summaryrefslogtreecommitdiff
path: root/css_shadow.php
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2011-09-25 00:05:54 -0700
committerLuke Shumaker <lukeshu@sbcglobal.net>2011-09-25 00:05:54 -0700
commit6b26bca2593f258cadbca656924b4e6b5c40a7c7 (patch)
treeef6a78f7fa4e6041d2f590da045e994f993024c3 /css_shadow.php
parent90d0a66ce3ca3e0edd696bdcab9854480783ff74 (diff)
meh do stuff
Diffstat (limited to 'css_shadow.php')
-rw-r--r--css_shadow.php151
1 files changed, 151 insertions, 0 deletions
diff --git a/css_shadow.php b/css_shadow.php
new file mode 100644
index 0000000..bdd4adb
--- /dev/null
+++ b/css_shadow.php
@@ -0,0 +1,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);
+ }
+}