#include<conio.h>
#include<dos.h>
#include<graphics.h>

void car(int x,int c)
{
setcolor(c);
line(x+150,100,x+242,100);
ellipse(x+242,105,0,90,10,5);
line(x+150,100,x+120,150);
line(x+252,105,x+280,150);
line(x+100,150,x+320,150);
line(x+100,150,x+100,200);
line(x+320,150,x+320,200);
line(x+100,200,x+110,200);
line(x+320,200,x+310,200);
arc(x+130,200,0,180,20);
arc(x+290,200,0,180,20);
line(x+270,200,x+150,200);
circle(x+130,200,17);
circle(x+290,200,17);

}


void main()
{
int gd=DETECT,gm=DETECT,i=-200;
int ch='g';
initgraph(&gd,&gm,"");

line(0,70,300,70);
line(450,70,630,70);
line(300,70,300,0);
line(450,70,450,0);
line(0,230,300,230);
line(450,230,630,230);
line(300,230,300,500);
line(450,230,450,500);
circle(280,50,10);
setfillstyle(SOLID_FILL,GREEN);
floodfill(280,50,15);
car(i,15);
while(1)
{
while(!kbhit())
{
if(ch=='r')
{
setfillstyle(SOLID_FILL,RED);
floodfill(280,50,15);
do{
while(!kbhit())
{
if(i<-20 || i>-10)
{
car(i++,0);
car(i,15);
delay(50);
}
}
ch=getch();
if(ch=='y')
{
setfillstyle(SOLID_FILL,YELLOW);
floodfill(280,50,15);
}
if(ch=='g')
{
setfillstyle(SOLID_FILL,GREEN);
floodfill(280,50,15);
}
}while(ch!='g'&&ch!=13);
}
else
{
car(i++,0);
car(i,15);
delay(50);
}
}
ch=getch();
if(ch==13)
break;
}


getch();
}

Posted by Dipin Krishna Tuesday, October 7, 2008

5 comments

  1. Springfairy Says:
  2. Wow! Dipin! You blog has helped me a lot!Keep up the good work! Could you please upload a simple C++ program demonstrating 2d transformations: scaling, translation and rotation.? Thanks!

     
  3. ejas Says:
  4. # include
    # include
    # include
    # include

    char IncFlag;
    int PolygonPoints[4][2] =
    {{10,100},{110,100},{110,200},{10,200}};

    int RefX = 10;
    int RefY = 100;

    void PolyLine()
    {
    int iCnt;
    cleardevice();
    line(0,240,640,240);
    line(320,0,320,480);
    for (iCnt=0; iCnt<4; iCnt++)
    {
    line(PolygonPoints[iCnt][0],PolygonPoints[iCnt][1],
    PolygonPoints[(iCnt+1)%4][0],PolygonPoints[(iCnt+1)%4][1]);
    }
    }

    void Translate(int Direction)
    {
    int iCnt;
    for (iCnt=0; iCnt<4; iCnt++)
    {
    PolygonPoints[iCnt][0] += Direction*RefX;
    PolygonPoints[iCnt][1] -= Direction*RefY;
    }
    }

    void Rotate()
    {
    float Angle;
    int iCnt;
    int Tx,Ty;
    Translate(-1);
    cout<<endl;
    Angle = 30.0*(22.0/7.0)/180.0;
    for (iCnt=0; iCnt<4; iCnt++)
    {
    Tx = PolygonPoints[iCnt][0];
    Ty = PolygonPoints[iCnt][1];
    PolygonPoints[iCnt][0] = (Tx - 320)*cos(Angle) -
    (Ty - 240)*sin(Angle) + 320;
    PolygonPoints[iCnt][1] = (Tx - 320)*sin(Angle) +
    (Ty - 240)*cos(Angle) + 240;
    }
    Translate(1);
    }

    void main()
    {
    int gDriver = DETECT, gMode;
    int iCnt;
    initgraph(&gDriver, &gMode, "C:\\TC\\BGI");
    for (iCnt=0; iCnt<4; iCnt++)
    {
    PolygonPoints[iCnt][0] += 320;
    PolygonPoints[iCnt][1] = 240 - PolygonPoints[iCnt][1];
    }
    PolyLine();
    getch();
    Rotate();
    PolyLine();
    getch();
    }

     
  5. poornima Says:
  6. we need explanation for programs

     
  7. nazia Says:
  8. it's a nice program please do more programs

     
  9. Sona Says:
  10. please uplod a c program to show the rocket populsion and also upload a c program to show ripples in a pond

     

Subscribe here

Get visitors map like this