update page now

Voting

: five plus four?
(Example: nine)

The Note You're Voting On

CPHaxer
16 years ago
Sorry for the long intro of my function, but i just want to tell how it works and - how silly sometimes the ideas are to make such functions. Have fun ;D

<?php

  //@FunctionName:    drawPlot
  //@Parameters:      drawPlot(img &$image, int $red, int $green, int $blue, int $x, int $y)
  //
  //                  img $image
  //                    The Image it will draw on. The Image will be modified; there is no return value.
  //
  //                  int $red, int $green, int $blue
  //                    The Colorvalues to draw with
  //
  //                  int $x, int $y
  //                    The Location to draw the Plot.
  //                    And this is the Mainpart, because $x and $y
  //                    NEED NOT be rounded!
  //                    If you want to make a Plot at [253.643891, 482];
  //                    It will draw the Plot there. Exact at the Coordinates.
  //                    You could use this to make smooth lines.
  //                    They have rational Coordinates, too.
  //
  //@Author:          Alexander Rath (*Feb 9th, 1996 ; 13 Years old)
  //
  //@Idea:            We have in Math Geometrie now. And as the only Computerfreak
  //                  In the class, i asked me: "How would it be, to mirror something
  //                  At a NOT FLAT LINE."
  //                  So I started thinking about it. First i tought about degresses - Nah!
  //                  Then i saw:
  //                  A point to mirror, has the SHORTEST way to the Line;
  //                  so i just needed to make the result smooth.
  //                  Unlike the other ways to draw pixels.
  //                                ~I started developing this:
  // PS: Sorry for bad english ( I am german )

  //Lets create a TrueColor Image Resource
  $image = imagecreatetruecolor(640, 480);
  
  //Lets make it Alpha
  imagealphablending($image, true);
  imagesavealpha($image, true);
  
  //...with White Background to draw on.
  imagefilledrectangle($image, 0, 0, 640, 480, imagecolorallocate($image, 255, 255, 255));
  
  //This is my little "Example"-Script
  for($x = 0; $x <= 640; $x = $x + 0.01) {
    $y = $x / (tan($x) + 1);
    drawPlot($image, 0, 0, 0, $x, $y);
  }
  
  header("Content-type: image/png");
  imagepng($image);
  
  function drawPlot(&$func_image, $func_red, $func_green, $func_blue, $func_x, $func_y) {
    $func_Right = $func_x - floor($func_x);
      $func_Left = 1 - $func_Right;
    
      $func_Bottom = $func_y - floor($func_y);
      $func_Top = 1 - $func_Bottom;
    
    $func_RightAlpha = $func_Right * 127;
    $func_LeftAlpha = $func_Left * 127;

    $func_LeftTop = $func_LeftAlpha * $func_Top;
    $func_RightTop = $func_RightAlpha * $func_Top;
    $func_LeftBottom = $func_LeftAlpha * $func_Bottom;
    $func_RightBottom = $func_RightAlpha * $func_Bottom;
    
    $func_x = floor($func_x);
    $func_y = floor($func_y);
    
    imagesetpixel($func_image, $func_x, $func_y, imagecolorallocatealpha($func_image, $func_red, $func_green, $func_blue, 127 - $func_LeftTop));
    imagesetpixel($func_image, $func_x + 1, $func_y, imagecolorallocatealpha($func_image, $func_red, $func_green, $func_blue, 127 - $func_RightTop));
    imagesetpixel($func_image, $func_x + 1, $func_y + 1, imagecolorallocatealpha($func_image, $func_red, $func_green, $func_blue, 127 - $func_RightBottom));
    imagesetpixel($func_image, $func_x, $func_y + 1, imagecolorallocatealpha($func_image, $func_red, $func_green, $func_blue, 127 - $func_LeftBottom));
  }
  
?>

Have fun ;D

<< Back to user notes page

To Top