drawing lines with a delay

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
the_metro_man
Forum Newbie
Posts: 1
Joined: Tue Dec 22, 2009 3:02 am

drawing lines with a delay

Post by the_metro_man »

how do you draw lines with a delay of, say 5 seconds, between each line - below is my code - the problem is that the statement ImagePng($handle) draws the image after the plot and doesn't seem to accept being called more than once:

$x1=0;
$y1=0;
$first_one="yes";
while($nt=mysql_fetch_array($qt)){

$x2=$x1+$x_gap; // Shifting in X axis
$y2=$y_max-$nt[sales]; // Coordinate of Y axis

if($first_one=="no"){ // this is to prevent from starting $x1= and $y1=0
imageline ($handle,$x1, $y1,$x2,$y2,$txt_color); // Drawing the line between two points

ImagePng ($handle);
sleep(2);
}
$x1=$x2; // Storing the value for next draw
$y1=$y2;
$first_one="no"; // Now flag is set to allow the drawing
}

ImagePng ($handle);


thanks

Abbey
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: drawing lines with a delay

Post by requinix »

PHP can't do things with a delay like that.

The easiest solution is to load the first image and use JavaScript to load the second, third, etc.

The best solution would be to create an animated GIF instead, but PHP's GD can't do that. You'd need something like ImageMagick or some other third-party extension/application.
Post Reply