2

I am making a program with graphics.h in C.I am trying to implement the matrix screen saver but I am stuck here in the code.The alphabets fall just once.I want them to keep on falling (removing the text before).Please guide me how to clear the old contents

void main_page(void)
{
    int  i,j,k,l,m,n,size;
    setcolor(BLUE);
    for(i=0;i<500;i+=50)
    {
            settextstyle(GOTHIC_FONT,1,1);
            outtextxy(50,50+i,"a b c");
            outtextxy(100,150+i,"H I J");
            outtextxy(150,250+i,"X Y Z");
            outtextxy(300,50+i,"D E F");
            outtextxy(350,350+i,"D E F");
            outtextxy(400,350+i,"D E F");
            outtextxy(450,350+i,"D E F");
            outtextxy(500,50+i,"D E F");
            outtextxy(550,350+i,"D E F");
            outtextxy(600,350+i,"D E F");

            delay(100);
    }

alt text

genpfault
  • 51,148
  • 11
  • 85
  • 139

1 Answers1

1

Don't you have to erase or over-write the characters in the old locations? So you might do it bottom-up rather than top-down, and, last, finally print some blanks?

ADDED: Well, here's a really brute-force way to do it, that I don't like. Replace the code inside your loop with this:

            settextstyle(GOTHIC_FONT,1,1);
            outtextxy( 50, 50+i,"a b c");
            outtextxy(100,150+i,"H I J");
            outtextxy(150,250+i,"X Y Z");
            outtextxy(300, 50+i,"D E F");
            outtextxy(350,350+i,"D E F");
            outtextxy(400,350+i,"D E F");
            outtextxy(450,350+i,"D E F");
            outtextxy(500, 50+i,"D E F");
            outtextxy(550,350+i,"D E F");
            outtextxy(600,350+i,"D E F");

            delay(100);

            outtextxy( 50, 50+i,"     ");
            outtextxy(100,150+i,"     ");
            outtextxy(150,250+i,"     ");
            outtextxy(300, 50+i,"     ");
            outtextxy(350,350+i,"     ");
            outtextxy(400,350+i,"     ");
            outtextxy(450,350+i,"     ");
            outtextxy(500, 50+i,"     ");
            outtextxy(550,350+i,"     ");
            outtextxy(600,350+i,"     ");
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
  • I did not get how would that help. –  Nov 15 '10 at 18:04
  • @fahad: Generally, if I want to display moving objects on the screen I need to figure out how to remove/replace the old images. Maybe I don't completely understand what you're doing, but I've done a lot with dynamic graphics on low-bandwidth devices. BTW, a useful technique is double-buffering, i.e. paint to a background bitmap and blt it to the screen. Perceptively, it's instantaneous. – Mike Dunlavey Nov 15 '10 at 20:24
  • @mike: how do I add a bitmap image to a program? –  Nov 16 '10 at 12:30
  • @fahad: I do it all the time in Windows. With graphics.h I'm not sure if you can do it. In Windows, there's a few steps involved. First you stub the clear-background message. On the paint message, you create a display context based on a device-compatible bitmap. You do all your painting to that display context. At the very end, you copy that image to the original display context, which makes it visible. That way there's no flashing. – Mike Dunlavey Nov 16 '10 at 12:57
  • @Mike:that sounds quite typical in,I would stick to flashing,but still I dont know how to proceed in it. –  Nov 16 '10 at 13:42
  • Well this trick looks good but it does not work because when you print a space in graphics it actually prints nothing there so the old contents remains there. –  Nov 17 '10 at 06:54
  • I found one..I worked on each one of the pixel's individually and finally got the work done –  Nov 18 '10 at 22:07