note 89189 added to function.imagesetpixel

From: Date: Wed, 25 Feb 2009 21:35:10 +0000
Subject: note 89189 added to function.imagesetpixel
Groups: php.notes 
Request: Send a blank email to php-notes+get-151136@lists.php.net to get a copy of this message
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 ---- Server IP: 69.147.83.197 Probable Submitter: 84.166.5.92 ---- Manual Page -- http://www.php.net/manual/en/function.imagesetpixel.php Edit -- https://master.php.net/note/edit/89189 Del: integrated -- https://master.php.net/note/delete/89189/integrated Del: useless -- https://master.php.net/note/delete/89189/useless Del: bad code -- https://master.php.net/note/delete/89189/bad+code Del: spam -- https://master.php.net/note/delete/89189/spam Del: non-english -- https://master.php.net/note/delete/89189/non-english Del: in docs -- https://master.php.net/note/delete/89189/in+docs Del: other reasons-- https://master.php.net/note/delete/89189 Reject -- https://master.php.net/note/reject/89189 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#151136) next »