Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: Нарисовать график y=cos(x) [2]
Форумы портала PHP.SU » » Вопросы новичков » Нарисовать график y=cos(x)

Страниц (2): « 1 [2]
 

16. CrazySparrow_99 - 17 Апреля, 2013 - 19:48:09 - перейти к сообщению
<?php
$im = imageCreateTrueColor(500,500);
$white = imageColorAllocate($im,255,255,255);
$c = imageColorAllocate($im,120,120,120);
imageline($im,250,0,250,500,$c);
imageline($im,0,250,500,250,$c);
$n = 30;
$x = -10;
for($i=0;$x<2000;$i++){
$y = cos($x);
$y1 = -1*($n*$y);
$x1 = $n*$x;
$x +=0.01;
$y2 = -1*($n*$y);
$x2 = $n*$x;
imageline($im,$x1+250,$y1+250,$x2+251,$y2+251,$white);
}
header("content-type: image/png");
imagePng($im);
imageDestroy($im);
?>
17. ratz - 22 Июля, 2013 - 14:05:17 - перейти к сообщению
Вот так вот:
<?php
$im = imageCreateTrueColor(800, 800);
$c = ImageColorAllocate($im, 255 , 255, 255);
$c2 = ImageColorAllocate($im, 0 , 255, 255);
imageline($im, 0, 200, 800, 200, $c);
imageline($im, 100, 0, 100, 800, $c);
$y = 0;
for ($x=0; $x<(3*3.14); $x +=0.01)
{
$y = -cos($x);
$y = round($y,4);
$x2 = $x*50;
$y2 = $y*50;
imageline($im, $x2+100, $y2+200, $x2+100.01, $y2+200.01, $c2);
}
header("Content-type:image/png");
imagePng($im);
imageDestroy($im);
?>

 

Powered by ExBB FM 1.0 RC1