Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $res = array();
- $i = (float) -15.0;
- $i = (float) -15.0;
- while ($i < 360 ) {
- $i2=deg2rad($i)*2;
- $n = abs( sin($i2) )* 50;//$i*6 + 7 ;
- //$i0=(string)$i;
- $res[] = array($i, $n);
- $i += .1;
- //echo $n;
- }
- //echo_r($res);die;
- ksort($res);
- $minX = $minY = $maxX = $maxY = 0;
- foreach ($res as $row) {
- $x = $row[0];
- $y = $row[1];
- if ($minX > $x) {
- $minX = $x;
- }
- if ($minY > $y) {
- $minY = $y;
- }
- //===========max
- if ($maxX < $x) {
- $maxX = $x;
- }
- if ($maxY < $y) {
- $maxY = $y;
- }
- }
- $lenX = $maxX - $minX;
- $lenY = $maxY - $minY;
- $size =$size0= 500;
- $mulX = round($size / $lenX);
- $mulY = round($size / $lenY);
- $border = 20;
- $config = array(
- 'x' => array($minX, $maxX, $lenX),
- 'y' => array($minY, $maxY, $lenY),
- 'mul' => array($mulX, $mulY),
- 'data' => $res,
- 'size' => array(500, 500),
- 'border' => $border
- );
- //echo_r($res);
- //echo_r($config);
- $line = generate_line($config);
- //echo_r($line);die;
- $size += ($border * 3);
- $img = imagecreatetruecolor($size, $size);
- $white = imagecolorallocate($img, 255, 255, 255);
- $black = imagecolorallocate($img, 0, 0, 0);
- $gray = imagecolorallocate($img, 125, 0, 125);
- imagefilledrectangle($img, 0, 0, $size, $size, $white);
- //line x
- imageline($img, $border, $line['yLine'], ($border+$size0), $line['yLine'], $gray);
- //line y
- imageline($img, $line['xLine'], $border, $line['xLine'], ($border+$size0), $gray);
- foreach ($line['line'] as $n => $pos) {
- if ($n != 0) {
- $x0 = $line['line'][$n - 1][0];
- $y0 = $line['line'][$n - 1][1];
- imageline($img, $x0, $y0, $pos[0], $pos[1], $black);
- }
- }
- header("Content-type: image/png");
- //imageline($palette, $startx, $starty, $endx, $endy, $colour)
- imagepng($img);
- die;
- function params_exist($params, $key, $default = FALSE) {
- if (isset($params[$key])) {
- return $params[$key];
- }
- if (is_array($params)) {
- log_local('params_exist key (' . $key . ' ?):' . json_encode(array_keys($params)));
- } else {
- log_local('params_exist (' . $key . ' ?) key:' . print_r($params, 1));
- }
- return $default;
- }
- function generate_line($params = FALSE) {
- $result = array(
- 'xLine'=>0,
- 'yLine'=>0
- );
- $result[]=$params;
- $size = params_exist($params, 'size', array(500, 500));
- $x = params_exist($params, 'x', array(0, 10));
- $y = params_exist($params, 'y', array(0, 10));
- $data = params_exist($params, 'data', FALSE);
- $border = params_exist($params, 'border', 11);
- $lenX = $x[1] - $x[0];
- $lenY = $y[1] - $y[0];
- $mulX = round($size[0] / $lenX);
- $mulY = round($size[1] / $lenY);
- $result[] = array($mulX, $mulY);
- foreach ($data as $row ) { //$pos_x => $pos_y
- $pos_x=$row[0];
- $pos_y=$row[1];
- $pos_x1 = $border + ( ($pos_x + abs($x[0]) ) * $mulX);
- $pos_y1 = $border + ( ($y[1] - $pos_y) * $mulY);
- //( ($pos_y-$y[1]) * $mulY);
- $line[ ] = array($pos_x1, $pos_y1);
- }
- $result['xLine']= $border + (abs($x[0])*$mulX);
- $result['yLine']= $border + (abs($y[1])*$mulY);
- $result['line'] = $line;
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement