Guest User

Untitled

a guest
Nov 24th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.92 KB | None | 0 0
  1. <?php
  2. if (isset($_GET["tri"])) {
  3. $checked = "checked";
  4. }
  5. ?>
  6. <form action="rand.php" method="get" style="font-family:arial">
  7. <span id="table">
  8. <table border="0" cellpadding="2">
  9. <th>Point 1</th><th>Point 2</th><tr />
  10. <td>x co-ord <input type="text" name="x1"  value="<?php echo $_GET["x1"]; ?>" /></td><td>x co-ord <input type="text" name="x2" value="<?php echo $_GET["x2"]; ?>" /></td><tr />
  11. <td>y co-ord <input type="text" name="y1" value="<?php echo $_GET["y1"]; ?>" /></td><td>y co-ord <input type="text" name="y2" value="<?php echo $_GET["y2"]; ?>" /></td><tr />
  12. <td><input type="submit" value="Generate Line" /> <input type="button" onClick="parent.location='?rand'" value="Random Line" /></td><td>
  13. </table>
  14. </span>
  15. </form>
  16.  
  17. <?php
  18.  
  19. create_image();
  20. print "<img src=image.png?".date("U").">";
  21.  
  22. function  create_image() {
  23.         $im = @imagecreate(1160, 1000) or die("Cannot Initialize new GD image stream");
  24.         $background_color = imagecolorallocate($im, 255, 255, 255);   // yellow
  25.        
  26.        
  27.         $red = imagecolorallocate($im, 255, 0, 0);                  // red
  28.         $blue = imagecolorallocate($im, 0, 0, 255);                 // blue
  29.                 $gray = imagecolorallocate($im, 190, 190, 190);
  30.        
  31.         imageline ($im, 480, 0, 480, 960, $red);
  32.         imageline ($im, 0, 480, 960, 480, $red);
  33.        
  34.         $grady = 953;
  35.          while ($i < 97) {
  36.                 imagestring($im, 2, 475, $grady, "-", $red);
  37.                 imagestring($im, 2, $gradx-2, 477, "|", $red);       
  38.                 $grady = $grady - 10;
  39.                 $gradx = $gradx + 10;
  40.                 $i++;
  41.          
  42.          }
  43.          
  44.          if (isset($_GET["rand"])) {
  45.                 header("location:?x1=" . mt_rand(-48,48) . "&y1=" .  mt_rand(-48,48) . "&x2=" . mt_rand(-48,48) . "&y2=" . mt_rand(-48,48));
  46.          }
  47.  
  48.          $x1 = 480 + $_GET["x1"]*10;
  49.          $y1 = 480 - ($_GET["y1"])*10;
  50.          $x2 =  480 + $_GET["x2"]*10;
  51.          $y2 = 480 - ($_GET["y2"])*10;
  52.        
  53.  
  54.         $m = ($_GET["y2"] - $_GET["y1"]) / ($_GET["x2"] - $_GET["x1"]);
  55.        
  56.        
  57.         $midx = ($_GET[ "x1"] + $_GET["x2"]) / 2;
  58.         $midy = ($_GET[ "y1"] + $_GET["y2"]) / 2;
  59.        
  60.         $yinter = $_GET["y1"] - ($m*$_GET["x1"]);
  61.         $yinter = $_GET["y1"] - ($m*$_GET["x1"]);      
  62.        
  63.    
  64.                            
  65.              
  66.         # Define points
  67.                imageline ($im, $x1, $y1, $x2, $y2, $blue);  # User line
  68.                imagestring($im, 2, $x1, $y1, "(" . round($_GET["x1"], 2) . ", " . round($_GET["y1"], 2) . ")", $red);
  69.                imagestring($im, 2, $x2, $y2, "(" . round($_GET["x2"], 2) . ", " . round($_GET["y2"], 2) . ")", $red);      
  70.                imagefilledellipse($im, 480+($midx)*10, 480-($midy)*10, 5, 5, $red);
  71.                imagefilledellipse($im, round($x1, 2), round($y1, 2), 5, 5, $red);      
  72.                imagefilledellipse($im, round($x2, 2), round($y2, 2), 5, 5, $red);            
  73.                imagestring($im, 2,  480+($midx)*10, 480-($midy)*10, "(" . round($midx, 2) . ", " . round($midy, 2) . ")", $red);               
  74.                
  75.                
  76.                /* Remove comment markers to plot y-intercept
  77.                
  78.                imagefilledellipse($im, 480, 480-($yinter)*10, 5, 5, $red);     
  79.                imagestring($im, 2, 490, 490-($yinter)*10, "(0, " . round($yinter, 2) . ")", $red);     
  80.                imageline($im, 480, 480-($yinter)*10, 490, 490-($yinter)*10, $red);
  81.                */
  82.                
  83.                
  84.         # Create triangle
  85.             if (isset($_GET["tri"])) {
  86.                     imageline ($im, $x1*-1, $y1, $x2, $y2, $blue);             
  87.                     imageline ($im, $x1, $y1, $x2*-1, $y2, $blue);                         
  88.                }
  89.                
  90.                
  91.         # Show info    
  92.            imagestring($im, 2, 1000, 20, "Gradient: " . round($m, 2), $red);
  93.            imagestring($im, 2, 1000, 40, "Y-intercept: " . round($yinter, 2), $red);
  94.            imagestring($im, 2, 1000, 60, "Mid-point: (" . round($midx, 2) . ", " . round($midy, 1) . ")", $red);       
  95.            imagestring($im, 2, 1000, 80, "Equation: y = " . round($m, 2) . "x + " . $yinter, $red);    
  96.            imagestring($im, 2, 1000, 100, "Written by Jake Browning", $gray);      
  97.        
  98.        
  99.    
  100.         imagepng($im,"image.png");
  101.         imagedestroy($im);
  102. }
  103.  
  104. ?>
Add Comment
Please, Sign In to add comment