perform simple rotation
Posted: Fri Jul 09, 2010 2:24 pm
Hi,
I'm trying to create a simple rotation animation using php.
Here's the code
Essentially this creates a box ($image = imagecreatetruecolor(400,400);) and is supposed to rotate a primitive clock hand through ten iterations (using the iteration variable $j and multiplying it by 0.2).
Though I can get given rotation points to work (say by nixing the for loop and inserting some arbitrary $angle) it does not actually perform an animation. I don't really know if this is the right way to go about it.
I don't have much experience with using php so I don't really know what the best approach would be.
And of course there are more efficient ways of handling certain elements esp. the use of two arrays to perform the transformation from modelspace to screenspace, I know that, I just didn't want to get into matrix manipulations until I got the underlying system down ( please, no lectures on graphics math!)
Thanks in advance for any information on how to perform this animation.
Jeff
I'm trying to create a simple rotation animation using php.
Here's the code
Code: Select all
function convertArray($myarray)
{
$num_vertices =4;
$newvalues = array();
$convertedvalues = array();
$counter = 0;
for ($j=0;$j < $num_vertices;$j++)
{
$newvalues[]= $myarray[$counter]+ 200;
$counter++;
$newvalues[]= (-1*$myarray[$counter])+ 200 ;
$counter++;
}
return $newvalues;
}
function angleConvertArray($myarray,$angle)
{
$num_vertices =4;
$newvalues = array();
$counter = 0;
for ($j=0;$j < $num_vertices;$j++)
{
$x=$myarray[$counter];
$counter++;
$y=$myarray[$counter];
$counter++;
$newx=$x*cos($angle)-$y*sin($angle);
$newy=$x*sin($angle)+$y*cos($angle);
$newvalues[]=$newx;
$newvalues[]=$newy;
}
return $newvalues;
}
//*****************************************************
$values = array( 10, 0, 0, 100, -10, 0, 10, 0);
for ($j=0;$j < 10;$j++)
{
$angle = $j * 0.2 ;
$angledvalues = angleConvertArray($values,$angle);
$convertedvalues = convertArray($angledvalues);
$image = imagecreatetruecolor(400, 400);
$bg = imagecolorallocate($image, 200, 200, 200);
$blue = imagecolorallocate($image, 0, 0, 255);
imagefilledpolygon($image, $convertedvalues, 4, $blue);
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
}
Though I can get given rotation points to work (say by nixing the for loop and inserting some arbitrary $angle) it does not actually perform an animation. I don't really know if this is the right way to go about it.
I don't have much experience with using php so I don't really know what the best approach would be.
And of course there are more efficient ways of handling certain elements esp. the use of two arrays to perform the transformation from modelspace to screenspace, I know that, I just didn't want to get into matrix manipulations until I got the underlying system down ( please, no lectures on graphics math!)
Thanks in advance for any information on how to perform this animation.
Jeff