Advertisement
gundambison

grafik

Jun 24th, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.90 KB | None | 0 0
  1. <?php
  2.  
  3. $res = array();
  4. $i = (float) -15.0;
  5.  
  6.         $i = (float) -15.0;
  7.         while ($i < 360 ) {
  8.             $i2=deg2rad($i)*2;
  9.             $n = abs( sin($i2) )* 50;//$i*6 + 7  ;
  10.             //$i0=(string)$i;
  11.             $res[] = array($i, $n);
  12.             $i += .1;
  13.             //echo $n;
  14.         }
  15.         //echo_r($res);die;
  16.  
  17.         ksort($res);
  18.         $minX = $minY = $maxX = $maxY = 0;
  19.         foreach ($res as $row) {
  20.             $x = $row[0];
  21.             $y = $row[1];
  22.             if ($minX > $x) {
  23.                 $minX = $x;
  24.             }
  25.             if ($minY > $y) {
  26.                 $minY = $y;
  27.             }
  28.             //===========max
  29.             if ($maxX < $x) {
  30.                 $maxX = $x;
  31.             }
  32.             if ($maxY < $y) {
  33.                 $maxY = $y;
  34.             }
  35.         }
  36.  
  37.         $lenX = $maxX - $minX;
  38.         $lenY = $maxY - $minY;
  39.  
  40.         $size =$size0= 500;
  41.         $mulX = round($size / $lenX);
  42.         $mulY = round($size / $lenY);
  43.         $border = 20;
  44.         $config = array(
  45.             'x' => array($minX, $maxX, $lenX),
  46.             'y' => array($minY, $maxY, $lenY),
  47.             'mul' => array($mulX, $mulY),
  48.             'data' => $res,
  49.             'size' => array(500, 500),
  50.             'border' => $border
  51.         );
  52.         //echo_r($res);
  53.         //echo_r($config);
  54.         $line = generate_line($config);
  55.  
  56.         //echo_r($line);die;
  57.         $size += ($border * 3);
  58.         $img = imagecreatetruecolor($size, $size);
  59.         $white = imagecolorallocate($img, 255, 255, 255);
  60.         $black = imagecolorallocate($img, 0, 0, 0);
  61.         $gray = imagecolorallocate($img, 125, 0, 125);
  62.        
  63.         imagefilledrectangle($img, 0, 0, $size, $size, $white);
  64.         //line x
  65.         imageline($img, $border, $line['yLine'], ($border+$size0), $line['yLine'], $gray);
  66.         //line y
  67.         imageline($img, $line['xLine'], $border, $line['xLine'], ($border+$size0), $gray);     
  68.  
  69.         foreach ($line['line'] as $n => $pos) {
  70.             if ($n != 0) {
  71.                 $x0 = $line['line'][$n - 1][0];
  72.                 $y0 = $line['line'][$n - 1][1];
  73.                 imageline($img, $x0, $y0, $pos[0], $pos[1], $black);
  74.             }
  75.         }
  76.         header("Content-type: image/png");
  77.         //imageline($palette, $startx, $starty, $endx, $endy, $colour)
  78.  
  79.         imagepng($img);
  80.         die;
  81.  
  82.  
  83.     function params_exist($params, $key, $default = FALSE) {
  84.         if (isset($params[$key])) {
  85.             return $params[$key];
  86.         }
  87.         if (is_array($params)) {
  88.             log_local('params_exist key (' . $key . ' ?):' . json_encode(array_keys($params)));
  89.         } else {
  90.             log_local('params_exist (' . $key . ' ?) key:' . print_r($params, 1));
  91.         }
  92.         return $default;
  93.     }
  94.  
  95.        
  96.     function generate_line($params = FALSE) {
  97.         $result = array(
  98.             'xLine'=>0,
  99.             'yLine'=>0
  100.         );
  101.         $result[]=$params;
  102.         $size = params_exist($params, 'size', array(500, 500));
  103.         $x = params_exist($params, 'x', array(0, 10));
  104.         $y = params_exist($params, 'y', array(0, 10));
  105.         $data = params_exist($params, 'data', FALSE);
  106.         $border = params_exist($params, 'border', 11);
  107.  
  108.         $lenX = $x[1] - $x[0];
  109.         $lenY = $y[1] - $y[0];
  110.         $mulX = round($size[0] / $lenX);
  111.         $mulY = round($size[1] / $lenY);
  112.         $result[] = array($mulX, $mulY);
  113.         foreach ($data as $row ) { //$pos_x => $pos_y
  114.             $pos_x=$row[0];
  115.             $pos_y=$row[1];
  116.             $pos_x1 = $border + ( ($pos_x + abs($x[0]) ) * $mulX);
  117.             $pos_y1 = $border + ( ($y[1] - $pos_y) * $mulY);
  118.             //( ($pos_y-$y[1]) * $mulY);
  119.             $line[ ] = array($pos_x1, $pos_y1);
  120.         }
  121.        
  122.         $result['xLine']= $border + (abs($x[0])*$mulX);
  123.         $result['yLine']= $border + (abs($y[1])*$mulY);
  124.         $result['line'] = $line;
  125.         return $result;
  126.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement