Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.23 KB | None | 0 0
  1. <?php
  2.     function coordY($coord) {
  3.         return 800 - intval((floatval($coord) + 100) * 4);
  4.     }
  5.  
  6.     function coordX($coord) {
  7.         return intval((floatval($coord) + 100) * 4);
  8.     }
  9.  
  10.     $link = mysql_connect("localhost", "rk6stud", "rk6stud")
  11.         or die("Could not connect : " . mysql_error());
  12.     /* Выбор БД my_database */
  13.     mysql_select_db("femdb") or die("Could not select database");
  14.  
  15.     /* Выполнение SQL-запроса */
  16.     $query = "SELECT * FROM nodes";
  17.     $result = mysql_query($query) or die("Query failed : " . mysql_error());
  18.  
  19.     $nodes = array();
  20.     while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
  21.         $nodes[$line["id"]] = $line;
  22.  
  23.     mysql_free_result($result);
  24.  
  25.     /* Выполнение SQL-запроса */
  26.     $query = "SELECT * FROM elements";
  27.     $result = mysql_query($query) or die("Query failed : " . mysql_error());
  28.  
  29.     $elements = array();
  30.     while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
  31.         array_push($elements, $line);
  32.  
  33.     mysql_free_result($result);
  34.     mysql_close($link);
  35.  
  36.  
  37. /*###########################################################################*/
  38. //    var_dump($nodes);
  39. //    var_dump($elements);
  40.     header("Content-type: image/png");
  41.  
  42.     $img = @imagecreate(800, 800)
  43.         or die("Cannot Initialize new GD image stream");
  44.  
  45.     $background_color = imagecolorallocate($img, 255, 255, 255);
  46.     $point_color_pink = imagecolorallocate($img, 255, 20, 147);
  47.     $point_color = imagecolorallocate($img, 0, 0, 0);
  48.  
  49.     $i = 0;
  50.     foreach ($elements as $el) {
  51.         $color = $point_color;
  52.         if (($i % 2) == 0)
  53.             $color = $point_color_pink;
  54.  
  55.         imageline($img, coordX($nodes[$el["n1"]]["x"]), coordY($nodes[$el["n1"]]["y"]), coordX($nodes[$el["n2"]]["x"]), coordY($nodes[$el["n2"]]["y"]), $color);
  56.         imageline($img, coordX($nodes[$el["n2"]]["x"]), coordY($nodes[$el["n2"]]["y"]), coordX($nodes[$el["n3"]]["x"]), coordY($nodes[$el["n3"]]["y"]), $color);
  57.         imageline($img, coordX($nodes[$el["n3"]]["x"]), coordY($nodes[$el["n3"]]["y"]), coordX($nodes[$el["n1"]]["x"]), coordY($nodes[$el["n1"]]["y"]), $color);
  58.         $i++;
  59.     }
  60.  
  61.     imagepng($img);
  62.     imagedestroy($img);
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement