Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi. I using GD package to make wave. But it does not work.
use GD::Simple;
$i = GD::Simple->new(400,400);
($x1,$y1) = (0,0);
for ($x2=0; $x2<=400; $x2+=10) {
    $y2 = sin($x2)*400;
    $i->moveTo($x1,$y1);
    $i->lineTo($x2,$y2);
    ($x1,$y1) = ($x2,$y2);
}
print $i->png;
How do I get right value for y2? Thank.

Replies are listed 'Best First'.
Re: Make sin wave with GD
by pme (Monsignor) on Jul 01, 2015 at 17:05 UTC
    sin() takes argument in the form of radian.
      Ok. Thank you. I convert to radians but now wave is upsidedown and clipped.
        The 0,0 point is the upper left corner of your 400x400 GD plane if i am not mistaken.