note 80797 added to function.imageline
| From: | huirong dot jin at gmail dot com | Date: | Thu, 31 Jan 2008 21:57:05 +0000 |
| Subject: | note 80797 added to function.imageline | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135680@lists.php.net to get a copy of this message | ||
An example to draw Amplitude Modulation curve: y = c * sin (x/a) * sin (x/b) . You can easily modify
the codes to create your own oscilloscope application!
<?php
header ("Content-type: image/png");
$myImage = @imagecreatetruecolor(640, 480)
or die("Cannot Initialize new GD image stream");
$text_color = imagecolorallocate($myImage, 255, 255, 224);
$poly_color = imagecolorallocate($myImage, 124, 120, 224);
//calculate x-value and y-value point by point
$points = array();
for ($i=1; $i<640; $i=$i+1)
{
//define curve's function
$x = $i; //define x-value, which is $i itself
$y = 150*sin($x/80)*sin($x/5);//define y-value
//append a point's x-value and y-value
$points[] = $x; //x-value
$points[] = 240-$y; //y-value
}
//count points
$totalPoints = count($points)/2;
//drawing title
$title = "Final Plot ($totalPoints points)";
imagestring($myImage, 3, 5, 5, $title, $text_color);
/** drawing points one by one, notice if there
* are 10 points, we need to draw 9 lines:
* 1) point 0 to 1;
* 2) point 1 to 2;
* ...
* ...
* 9) point 8 to 9;
*/
for ($i=0; $i<$totalPoints-1; $i++)
{
imageLine($myImage, $points[2*$i], $points[1+2*$i], $points[2+2*$i], $points[3+2*$i],
$poly_color);
}
//finalizing
imagepng($myImage);
imagedestroy($myImage);
?>
----
Server IP: 66.207.199.35
Probable Submitter: 199.71.174.100
----
Manual Page -- http://www.php.net/manual/en/function.imageline.php
Edit -- https://master.php.net/note/edit/80797
Del: integrated -- https://master.php.net/note/delete/80797/integrated
Del: useless -- https://master.php.net/note/delete/80797/useless
Del: bad code -- https://master.php.net/note/delete/80797/bad+code
Del: spam -- https://master.php.net/note/delete/80797/spam
Del: non-english -- https://master.php.net/note/delete/80797/non-english
Del: in docs -- https://master.php.net/note/delete/80797/in+docs
Del: other reasons-- https://master.php.net/note/delete/80797
Reject -- https://master.php.net/note/reject/80797
Search -- https://master.php.net/manage/user-notes.php