Advertisement
7heSama

svg fiddle

Aug 11th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.30 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <head>
  3.     <link rel="stylesheet" type="text/css" href="style.css">
  4. </head>
  5.  
  6. <body>
  7.     <?php
  8.         // draws a box at the coords
  9.         // stroke given in 1/2 width
  10.         function drawBox($x, $y, $edge, $width, $stroke)
  11.         {
  12.             $lastY = $y - ($width / 2);
  13.             $negEdge = -$edge;
  14.            
  15.             return "<path d=\"M $x $y h $edge v $edge h $negEdge L $x $lastY\" stroke=\"$stroke\" stroke-width=\"$width\" fill=\"none\"/>";
  16.         }
  17.        
  18.         function drawJig($keys, $xArr, $yArr, $stroke, $width)
  19.         {
  20.             $cmd = 'M';
  21.             $svg = '<path class=\"jig\" d="';
  22.             foreach ($keys as $place)
  23.             {
  24.                 $x = $xArr[$place] + 10;
  25.                 $y = $yArr[$place] + 10;
  26.                 $svg .= $cmd . " $x $y ";
  27.                 $cmd = 'L';
  28.             }
  29.             $svg .= "\" stroke=\"$stroke\" stroke-width=\"$width\" fill=\"none\"/>";
  30.             return $svg;
  31.         }
  32.        
  33.         function label($x, $y, $text)
  34.         {
  35.             return "<g font-size=\"24\" font-family=\"sans-serif\" fill=\"white\" stroke=\"none\" text-anchor=\"start\"> <text x=\"$x\" y=\"$y\">$text</text></g>";
  36.         }
  37.     ?>
  38.    
  39.     <svg width="1400" height="700">
  40.         <defs>
  41.             <linearGradient id="pulse" x1="0%" y1="0%" x2="100%" y2="0%">
  42.                 <stop offset="0%" stop-color="gray">
  43.                     <animate attributeName="offset" from="0%" to="100%" dur="10s" repeatCount="indefinite" />
  44.                 </stop>
  45.                 <stop offset="10%" stop-color="white">
  46.                     <animate attributeName="offset" from="10%" to="100%" dur="10s" repeatCount="indefinite" />
  47.                 </stop>
  48.                 <stop offset="20%" stop-color="gray">
  49.                     <animate attributeName="offset" from="10%" to="100%" dur="10s" repeatCount="indefinite" />
  50.                 </stop>
  51.             </linearGradient>
  52.         </defs>
  53.        
  54.         <?php
  55.             $edge = 20;
  56.             $longs = array();
  57.             $lats = array();
  58.            
  59.             $keys = array(
  60.                 "Atlantis",
  61.                 "Beggard",
  62.                 "Protomorika",
  63.                 "Amorika",
  64.                 "Los Alamos",
  65.                 "Fort Roanoke",
  66.                 "Kill Devil Hills",
  67.                 "Kitty Hawk",
  68.                 "Jarvis",
  69.                 "Manteo"
  70.             );
  71.            
  72.             foreach ($keys as $name)
  73.             {
  74.                 $x = rand($edge, 1360);
  75.                 $y = rand($edge, 660);
  76.                 $longs[$name] = $x;
  77.                 $lats[$name] = $y;
  78.             }
  79.         ?>
  80.        
  81.         <g>
  82.             <?=drawJig($keys, $longs, $lats, "url(#pulse)", 2)?>;
  83.         </g>
  84.        
  85.         <?php
  86.             foreach ($keys as $name)
  87.             {
  88.                 $x = $longs[$name];
  89.                 $y = $lats[$name];
  90.                 echo (drawBox($x, $y, $edge, 2, "gray"));
  91.                 echo label($x + ($edge/2), $y + ($edge/2), $name);
  92.             }
  93.         ?>
  94.     </svg>
  95. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement