Man In Rain...

277 views
Skip to first unread message

subin sebastien

unread,
Oct 27, 2009, 5:47:48 AM10/27/09
to LUG Trivandrum Trivandrum, Sharoon Thomas, Samuel Stefan
I'm attaching the source code of a C++ program that is compiled with Turbo C++ compiler on virtual box. The program is intended to make an animation of a man walking in
rain with an umbrella. Anyone with some C++ skills can patch the code. Clearly comment any changes. Anything that seems to be good should done to the source code. And
make your suggestions at the end. And please try to manage a SDL Linux alternative of
the program on the move. Manage the source code as follows.

  • When you change a line comment the previous one and code in the alternative.
  • When you add something, document it clearly
  • Manage the same source code.
  • After making changes compile it and push back.
  • Do not stick with the latest source code but with the best.
  • Don't spam please.
  • Try to make portable code...
---------------------------------------------------------------------------

//Here is the code...
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
//Subroutine for generating oscillating values between 0 and 3
int sineGen(int cntr)
    {
        int k=cntr%7;
        switch(k)
        {
            case 0:
            case 6:
                return 0;
            case 1:
            case 5:
                return 1;
            case 2:
            case 4:
                return 2;
            case 3:
                return 3;
        }
    }
 
//A cartition coordinate
struct Mpoints
{
    int x;
    int y;
};
//Draws and manages the man
class Man
{
    Mpoints p[14];
    int a,b;
    int step0[14][2];
    int step1[14][2];
    int step2[14][2];
    int step3[14][2];
    int stepcntr;
public:
    Man(int da,int db)
    {
        a=da;            b=db;
 
        step0[0][0]=0;        step0[0][1]=0;
        step0[1][0]=0;        step0[1][1]=15;
        step0[2][0]=0;        step0[2][1]=30;
        step0[3][0]=-15;    step0[3][1]=55;
        step0[4][0]=15;        step0[4][1]=80;
        step0[5][0]=-15;    step0[5][1]=55;
        step0[6][0]=15;        step0[6][1]=80;
        step0[7][0]=0;        step0[7][1]=80;
        step0[8][0]=15;        step0[8][1]=115;
        step0[9][0]=15;        step0[9][1]=115;
        step0[10][0]=-15;    step0[10][1]=150;
        step0[11][0]=-15;    step0[11][1]=150;
        step0[12][0]=0;        step0[12][1]=150;
        step0[13][0]=0;        step0[13][1]=150;
 
        step1[0][0]=0;        step1[0][1]=0;
        step1[1][0]=0;        step1[1][1]=15;
        step1[2][0]=0;        step1[2][1]=30;
        step1[3][0]=-10;    step1[3][1]=57;
        step1[4][0]=17;        step1[4][1]=73;
        step1[5][0]=-20;    step1[5][1]=53;
        step1[6][0]=10;        step1[6][1]=76;
        step1[7][0]=0;        step1[7][1]=80;
        step1[8][0]=10;        step1[8][1]=115;
        step1[9][0]=25;        step1[9][1]=110;
        step1[10][0]=-25;    step1[10][1]=145;
        step1[11][0]=-5;    step1[11][1]=145;
        step1[12][0]=-10;    step1[12][1]=150;
        step1[13][0]=10;    step1[13][1]=148;
 
        step2[0][0]=0;        step2[0][1]=0;
        step2[1][0]=0;        step2[1][1]=15;
        step2[2][0]=0;        step2[2][1]=30;
        step2[3][0]=5;        step2[3][1]=55;
        step2[4][0]=30;        step2[4][1]=60;
        step2[5][0]=-30;    step2[5][1]=50;
        step2[6][0]=-10;    step2[6][1]=70;
        step2[7][0]=0;        step2[7][1]=80;
        step2[8][0]=-2;        step2[8][1]=115;
        step2[9][0]=25;        step2[9][1]=110;
        step2[10][0]=-35;    step2[10][1]=135;
        step2[11][0]=-5;    step2[11][1]=145;
        step2[12][0]=-25;    step2[12][1]=145;
        step2[13][0]=10;    step2[13][1]=148;
 
        step3[0][0]=0;        step3[0][1]=0;
        step3[1][0]=0;        step3[1][1]=15;
        step3[2][0]=0;        step3[2][1]=30;
        step3[3][0]=10;        step3[3][1]=55;
        step3[4][0]=40;        step3[4][1]=40;
        step3[5][0]=-36;    step3[5][1]=35;
        step3[6][0]=-30;    step3[6][1]=67;
        step3[7][0]=0;        step3[7][1]=80;
        step3[8][0]=-10;    step3[8][1]=110;
        step3[9][0]=35;        step3[9][1]=105;
        step3[10][0]=-45;    step3[10][1]=125;
        step3[11][0]=15;    step3[11][1]=135;
        step3[12][0]=-38;    step3[12][1]=135;
        step3[13][0]=25;    step3[13][1]=140;
 
 
 
    stepcntr=1;
    }
    forMan(int at,int push)
    {
        if(a>=640)
            a=-100;
        else
            a+=push;
        int i=0;
        switch(at)
        {
        case 0:
            for(i=0;i<14;i++)
            {
                p[i].x=a+step0[i][0];
                p[i].y=b+step0[i][1];
            }
            break;
        case 1:
            for(i=0;i<14;i++)
            {
                p[i].x=a+step1[i][0];
                p[i].y=b+step1[i][1];
            }
            break;
        case 2:
            for(i=0;i<14;i++)
            {
                p[i].x=a+step2[i][0];
                p[i].y=b+step2[i][1];
            }
            break;
        case 3:
            for(i=0;i<14;i++)
            {
                p[i].x=a+step3[i][0];
                p[i].y=b+step3[i][1];
            }
            break;
 
        default:break;
        }
 
    }
    drawMan()
    {
        setcolor(15);
        circle(p[0].x,p[0].y,15);
        line(p[1].x,p[1].y,p[2].x,p[2].y);
        line(p[2].x,p[2].y,p[3].x,p[3].y);
        line(p[2].x,p[2].y,p[5].x,p[5].y);
        line(p[2].x,p[2].y,p[7].x,p[7].y);
 
        line(p[3].x,p[3].y,p[4].x,p[4].y);
        line(p[5].x,p[5].y,p[6].x,p[6].y);
 
        line(p[7].x,p[7].y,p[8].x,p[8].y);
        line(p[7].x,p[7].y,p[9].x,p[9].y);
 
        line(p[8].x,p[8].y,p[10].x,p[10].y);
        line(p[9].x,p[9].y,p[11].x,p[11].y);
 
        line(p[10].x,p[10].y,p[12].x,p[12].y);
        line(p[11].x,p[11].y,p[13].x,p[13].y);
        return 0;
    }
    eraseMan()
    {
        setcolor(0);
        circle(p[0].x,p[0].y,15);
        line(p[1].x,p[1].y,p[2].x,p[2].y);
        line(p[2].x,p[2].y,p[3].x,p[3].y);
        line(p[2].x,p[2].y,p[5].x,p[5].y);
        line(p[2].x,p[2].y,p[7].x,p[7].y);
 
        line(p[3].x,p[3].y,p[4].x,p[4].y);
        line(p[5].x,p[5].y,p[6].x,p[6].y);
 
        line(p[7].x,p[7].y,p[8].x,p[8].y);
        line(p[7].x,p[7].y,p[9].x,p[9].y);
 
        line(p[8].x,p[8].y,p[10].x,p[10].y);
        line(p[9].x,p[9].y,p[11].x,p[11].y);
 
        line(p[10].x,p[10].y,p[12].x,p[12].y);
        line(p[11].x,p[11].y,p[13].x,p[13].y);
        return 0;
    }
};
 
 
//Draws and manages a RainDrop...!
class RainDrop
{
    int x,y;
public:
    RainDrop()
    {
        x=random(639);y=random(30);
    }
    drawDrop()
    {
        setcolor(15);
        putpixel(x,y,15);
        putpixel(x+1,y-1,7);
        putpixel(x+2,y-2,8);
        return 0;
    }
    eraseDrop()
    {
 
        putpixel(x,y,getbkcolor());
        putpixel(x+1,y-1,getbkcolor());
        putpixel(x+2,y-2,getbkcolor());
        return 0;
    }
    stepDrop(int step)
    {
        eraseDrop();
        if(x<=0) x=random(639);
        else x-=step;
        if(y>=400) y=0;
        else y+=step;
        drawDrop();
        return 0;
    }
};
//Add one more class that can draw & manage an umbrella...
int main()
{
    int a=DETECT,b;
    initgraph(&a,&b,"..\\bgi");
    RainDrop Rain[1024];
    Man M(-300,300);
    int i=0,k=0;
    getch();
    do
          {
        Rain[i++].stepDrop(random(i%64));
        i=i>=1023?0:i+1;
 
          if(i%1000==0)
          {
            M.forMan(sineGen(k++),10);
            M.drawMan();
 
          for(int tt=0;tt<1000;tt++)
            {    Rain[i++].stepDrop(random(i%64));
            i=i>=1023?0:i+1;
             }
 
            M.eraseMan();
          }
 
 
          }
    while(!kbhit());
    return 0;
}
//TODO
//Do anything that seems to be good.
//Make a SDL diff of the program

---------------------------------------------------------------

Subin Sebastian

College Of Engineering, Munnar
+91-944-6475-826
"Support Free Software"

Rajeev J Sebastian

unread,
Oct 27, 2009, 6:16:37 AM10/27/09
to ilug...@googlegroups.com
On Tue, Oct 27, 2009 at 3:17 PM, subin sebastien <subinse...@yahoo.com> wrote:
I'm attaching the source code of a C++ program that is compiled with Turbo C++ compiler on virtual box. The program is intended to make an animation of a man walking in
rain with an umbrella. Anyone with some C++ skills can patch the code. Clearly comment any changes. Anything that seems to be good should done to the source code. And
make your suggestions at the end. And please try to manage a SDL Linux alternative of
the program on the move. Manage the source code as follows.

  • When you change a line comment the previous one and code in the alternative.
  • When you add something, document it clearly
  • Manage the same source code.
  • After making changes compile it and push back.
  • Do not stick with the latest source code but with the best.
  • Don't spam please.
  • Try to make portable code...

Yeesh ... bad practices.

The best thing to do is, check in to bitbucket, github/gitorius ... or even a gist.

 Do not comment the previous line and code the alternative ... simply remove it.

Use Qt and QPainter on a custom widget... will make your life much easier.

Regards
Rajeev J Sebastian

Shino Jacob

unread,
Oct 27, 2009, 11:22:49 AM10/27/09
to ilug...@googlegroups.com
>>Subin
This was a good example of OOP(Object oriented programming).Although not completely following OO paradigm.
you should have attached the source rather than typing every thing here.

subin sebastien

unread,
Oct 28, 2009, 12:23:56 AM10/28/09
to ilug...@googlegroups.com
Yes. That's it....



Subin Sebastian

College Of Engineering, Munnar
+91-944-6475-826
"Support Free Software"


--- On Tue, 10/27/09, Shino Jacob <shino...@gmail.com> wrote:
MANINRAI.CPP

Subin

unread,
Oct 28, 2009, 2:14:31 AM10/28/09
to Free Software Users Group, Thiruvananthapuram
Yes I know. But this is for someone who starts programming...
And understand how git, launchpad or any other cvs works basically...
Turbo C++ is not a free-ware too you know...
Just coding....

On Oct 27, 6:16 am, Rajeev J Sebastian <rajeev.sebast...@gmail.com>
wrote:
> On Tue, Oct 27, 2009 at 3:17 PM, subin sebastien
> <subinsebast...@yahoo.com>wrote:
>
>
>
> > I'm attaching the source code of a C++ program that is compiled with Turbo
> > C++ compiler on virtual box. The program is intended to make an animation of
> > a man walking in
> > rain with an umbrella. Anyone with some C++ skills can patch the code.
> > Clearly comment any changes. Anything that seems to be good should done to
> > the source code. And
> > make your suggestions at the end. And please try to manage a SDL Linux
> > alternative of
> > the program on the move. Manage the source code as follows.
>
> >    - When you change a line comment the previous one and code in the
> >    alternative.
> >    - When you add something, document it clearly
> >    - Manage the same source code.
> >    - After making changes compile it and push back.
> >    - Do not stick with the latest source code but with the best.
> >    - Don't spam please.
> >    - Try to make portable code...

Anoop Jacob Thomas

unread,
Oct 28, 2009, 12:52:22 PM10/28/09
to ilug...@googlegroups.com
You can get graphics.h work in GNU/Linux with few simple steps. Follow the link,

http://sector-zero.blogspot.com/2007/07/graphicsh-in-gnulinux.html

Posted by Rajiv R Nair.

If you want to do mouse programming using int86() using dos.h then probably you will have to do that with Turbo C and DosBox. If you are working for the labs then I think you need to learn the mouse programming also, so you have to use Turbo C.

These things are not applicable for a common man, as BGI Graphics is now used only in Colleges to teach the basics of computer graphics.

--
Anoop Jacob Thomas
Trivandrum

http://anoop.caremedia.org

Syam Krishnan

unread,
Oct 28, 2009, 9:56:32 PM10/28/09
to ilug...@googlegroups.com
On 10/28/2009 10:22 PM, Anoop Jacob Thomas wrote:
> These things are not applicable for a common man, as BGI Graphics is
> now used only in Colleges to teach the basics of computer graphics.

Indeed. For GUI programs, one should use a modern toolkit like Qt. I've
heard that 'Allegro' (http://alleg.sourceforge.net/) is a good library
for graphics/game programming. It's cross-platform too.

@Subin
It's good to see some nice cleanly indented code! Kudos to you.
You should really get rid of this archaic TurboC compiler and try some
newer standards compliant compilers.

Syam

Kenney Jacob

unread,
Oct 28, 2009, 11:24:57 PM10/28/09
to ilug...@googlegroups.com
Reminds me of my college lab days.

www.kenneyjacob.com
Kenney Jacob
Ayruz Web Holdings
Mobile :- +91-9846831128


Chat Google Talk: kenney.jacob Skype: kenney.jacob

Subin

unread,
Oct 30, 2009, 3:48:47 AM10/30/09
to Free Software Users Group, Thiruvananthapuram
Thank for the reply to all.
I'm still in my college...!
And if anybody suggest a SDL diff of the program...Just code it....
regards to all.....

On Oct 28, 11:24 pm, Kenney Jacob <kenney.ja...@gmail.com> wrote:
> Reminds me of my college lab days.
>
> www.kenneyjacob.com
> Kenney Jacob
> Ayruz Web Holdings
> Mobile :- +91-9846831128
>
> <http://www.barcampkerala.org>
> Chat Google Talk: kenney.jacob Skype: kenney.jacob
Reply all
Reply to author
Forward
0 new messages