A modest collection of PHP libraries used at SparkFun.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
2.8 KiB

10 years ago
  1. <?php
  2. namespace SparkLib\Util;
  3. /*
  4. This class can be used to obtain svg path snippets for some basic shapes
  5. */
  6. class SvgShape {
  7. public static function shape($shape, $x, $y, $width, $fill)
  8. {
  9. $method = "self::{$shape}";
  10. if (is_callable($method, false, $callable_name)) {
  11. return call_user_func_array($callable_name, array_slice(func_get_args(), 1));
  12. }
  13. return FALSE;
  14. }
  15. public static function circle($x, $y, $width, $height, $fill = 'black') {
  16. $cpw = 0.166 * $width;
  17. return '<path fill="' . $fill . '" d="M ' . ($x + ($width / 2)) . ' ' . $y . ' C ' . ($x + $width + $cpw) . ' ' . $y . ' ' . ($x + $width + $cpw) . ' ' . ($y + $height) . ' ' . ($x + ($width / 2)) . ' ' . ($y + $height) . ' C ' . ($x - $cpw) . ' ' . ($y + $height) . ' ' . ($x - $cpw) . ' ' . $y . ' ' . ($x + ($width / 2)) . ' ' . $y . ' Z"/>';
  18. }
  19. public static function square($x, $y, $width, $height, $fill = 'black') {
  20. return '<path fill="' . $fill . '" d="M ' . $x . ' ' . $y . ' L ' . ($x + $width) . ' ' . $y . ' ' . ($x + $width) . ' ' . ($y + $height) . ' ' . $x . ' ' . ($y + $height) . ' Z"/>';
  21. }
  22. public static function triangle($x, $y, $width, $height, $fill = 'black') {
  23. return '<path fill="' . $fill . '" d="M ' . ($x + ($width / 2)) . ' ' . $y . ' L ' . ($x + $width) . ' ' . ($y + $height) . ' ' . $x . ' ' . ($y + $height) . ' ' . $x . ' ' . ($y + $height) . ' Z"/>';
  24. }
  25. public static function triangleDown($x, $y, $width, $height, $fill = 'black') {
  26. return '<path fill="' . $fill . '" d="M ' . $x . ' ' . $y . ' L ' . ($x + $width) . ' ' . $y . ' ' . ($x + ($width/2)) . ' ' . ($y + $height) . ' Z"/>';
  27. }
  28. public static function diamond($x, $y, $width, $height, $fill = 'black') {
  29. return '<path fill="' . $fill . '" d="M ' . ($x + ($width / 2)) . ' ' . $y . ' L ' . ($x + $width) . ' ' . ($y + ($height / 2)) . ' ' . ($x + ($width / 2)) . ' ' . ($y + $height) . ' ' . $x . ' ' . ($y + ($height / 2)) . ' Z"/>';
  30. }
  31. public static function triforce($x, $y, $width, $height, $fill = 'gold') {
  32. return '<path fill="' . $fill . '" d="M ' . ($x + ($width / 2)) . ' ' . $y . ' L ' . ($x + ($width - ($width / 4))) . ' ' . ($y + ($height / 2)) . ' ' . ($x + ($width / 4)) . ' ' . ($y + ($height / 2)) . ' ' . ($x + ($width / 4)) . ' ' . ($y + ($height / 2)) . ' Z"/>' .
  33. '<path fill="' . $fill . '" d="M ' . ($x + ($width / 4)) . ' ' . ($y + ($height / 2)) . ' L ' . ($x + ($width / 2)) . ' ' . ($y + $height) . ' ' . $x . ' ' . ($y + $height) . ' ' . $x . ' ' . ($y + $height) . ' Z"/>' .
  34. '<path fill="' . $fill . '" d="M ' . ($x + ($width - ($width / 4))) . ' ' . ($y + ($height / 2)) . ' L ' . ($x + $width) . ' ' . ($y + $height) . ' ' . ($x + ($width / 2)) . ' ' . ($y + $height) . ' ' . ($x + ($width / 2)) . ' ' . ($y + $height) . ' Z"/>';
  35. }
  36. }