Sure. This example demonstrates cleaning up behind the pixel and not cleaning up behind the pixel. The principle is the same for a line. It also has a delay in the loop so that the animation slows down. Try playing around with it to see the differences.
Red pixel moves, blue pixel moves but leaves a tail. Press ESCape to quit.
PHP Code:
#include <allegro.h>
int x; // X coordinate of our pixels.
int main()
{
// Initialize Allegro.
allegro_init();
// Set the color depth to 32 bit.
set_color_depth(32);
// Set the resolution to 640 by 480 with SAFE autodetection.
set_gfx_mode(GFX_SAFE, 640, 480, 0, 0);
// Installing the keyboard handler.
install_keyboard();
// Printing text to the screen.
textout(screen, font, "Moving Pixel:", 1, 1, makecol(255,0,0));
textout(screen, font, "Growing line:", 1, 22, makecol(0,0,255));
// Looping until the ESCape key is pressed.
while(! key[KEY_ESC])
{
// Erase old moving pixel.
putpixel(screen, x-1, 12, 0);
// Draw new moving pixel.
putpixel(screen, x, 12, makecol(255,50,50));
// Draw growing line from pixels.
putpixel(screen, x, 32, makecol(50,50,255));
x++;
if(x>640)
x=0;
rest(2); // Slow down animation.
}
// Exit program.
allegro_exit();
return 0;
}
// Some Allegro magic to deal with WinMain().
END_OF_MAIN();