Saturday, May 1, 2010

Animated Moving Car

// Add header files stdio.h  conio.h  graphics.h  dos.h  math.h
#include
#include
#include
#include
#include

void main()
{
int gd=DETECT,gm;
int i=0,m=0;
initgraph(&gd,&gm,"c:\\tc\\bgi");
while(!kbhit())
{
cleardevice();
i++;
if(i>getmaxx())
i-=670;
line(80+i,300,90+i,270);
line(90+i,270,120+i,270);
line(120+i,270,160+i,240);
line(160+i,240,230+i,240);
line(230+i,240,275+i,270);
line(275+i,270,310+i,270);
line(310+i,270,335+i,290);
line(335+i,290,335+i,300);
line(255+i,300,335+i,300);
line(180+i,300,210+i,300);
line(80+i,300,135+i,300);
arc(232+i,300,0,180,23);
arc(157+i,300,0,180,23);
circle(232+i,300,18);
circle(157+i,300,18);
pieslice(232+i,300,0+m,90+m,18);
pieslice(232+i,300,180+m,270+m,18);
pieslice(157+i,300,0+m,90+m,18);
pieslice(157+i,300,180+m,270+m,18);
if(m<-360)
m=90;
m-=3;
delay(5);
}
getch();
closegraph();
}

House

//Add header files  stdio.h  graphics.h  stdlib.h  math.h  conio.h
//Use DosBox 0.73 for Output
#include
#include
#include
#include
#include

void reset (int h[][2])
{
    int val[9][2] = {
            { 50, 50 },{ 75, 50 },{ 75, 75 },{ 100, 75 },
            { 100, 50 },{ 125, 50 },{ 125, 100 },{ 87, 125 },{ 50, 100 }
            };
    int i;
    for (i=0; i<9; i++)
    {
    h[i][0] = val[i][0]-50;
    h[i][1] = val[i][1]-50;
    }
}
void draw (int h[][2])
{
    int i;
    setlinestyle (DOTTED_LINE, 0, 1);
    line (320, 0, 320, 480);
    line (0, 240, 640, 240);
    setlinestyle (SOLID_LINE, 0, 1);
    for (i=0; i<8; i++)
    line (320+h[i][0], 240-h[i][1], 320+h[i+1][0], 240-h[i+1][1]);
    line (320+h[0][0], 240-h[0][1], 320+h[8][0], 240-h[8][1]);
}
void rotate (int h[][2], float angle)
{
    int i;
    for (i=0; i<9; i++)
    {
    int xnew, ynew;
    xnew = h[i][0] * cos (angle) - h[i][1] * sin (angle);
    ynew = h[i][0] * sin (angle) + h[i][1] * cos (angle);
    h[i][0] = xnew; h[i][1] = ynew;
    }
}
void scale (int h[][2], int sx, int sy)
{
    int i;
    for (i=0; i<9; i++)
    {
    h[i][0] *= sx;
    h[i][1] *= sy;
    }
}
void translate (int h[][2], int dx, int dy)
{
    int i;
    for (i=0; i<9; i++)
    {
    h[i][0] += dx;
    h[i][1] += dy;
    }
}
void reflect (int h[][2], int m, int c)
{
    int i;
    float angle;
    for (i=0; i<9; i++)
        h[i][1] -= c;
    angle = M_PI/2 - atan (m);
    rotate (h, angle);
    for (i=0; i<9; i++)
        h[i][0] = -h[i][0];
    angle = -angle;
    rotate (h, angle);
    for (i=0; i<9; i++)
        h[i][1] += c;
}

void ini()
{
    int gd=DETECT,gm;
    initgraph(&gd,&gm,"..\\bgi");
}
void dini()
{
    getch();
    closegraph();
}
void main()
{

    int h[9][2],sx,sy,x,y,m,c,choice;
    do
    {
        clrscr();
        printf("1. Scaling about the origin.\n");
        printf("2. Scaling about an arbitrary point.\n");
        printf("3. Reflection about the line y = mx + c.\n");
        printf("4. Exit\n");
        printf("Enter the choice: ");
        scanf("%d",&choice);
        switch(choice)
        {
            case 1: printf ("Enter the x- and y-scaling factors: ");
                scanf ("%d%d", &sx, &sy);
                ini();
                reset (h);
                draw (h);getch();
                scale (h, sx, sy);
                cleardevice();
                draw (h);
                dini();
                break;

            case 2: printf ("Enter the x- and y-scaling factors: ");
                scanf ("%d%d", &sx, &sy);
                printf ("Enter the x- and y-coordinates of the point: ");
                scanf ("%d%d", &x, &y);
                ini();
                reset (h);
                translate (h, x, y);// Go to arbitrary point
                draw(h); getch();//Show its arbitrary position
                cleardevice();
                translate(h,-x,-y);//Take it back to origin
                draw(h);
                getch();
                cleardevice();
                scale (h, sx, sy);//Now Scale it
                draw(h);
                getch();
                translate (h, x, y);//Back to Arbitrary point
                cleardevice();
                draw (h);
                putpixel (320+x, 240-y, WHITE);
                dini();
                break;

            case 3: printf ("Enter the values of m and c: ");
                scanf ("%d%d", &m, &c);
                ini();
                reset (h);
                draw (h); getch();
                reflect (h, m, c);
                cleardevice();
                draw (h);
                dini();
                break;

            case 4: exit(0);
        }
    }while(choice!=4);
}

Animated Moving Fish

//add header files as stdio.h  time.h  conio.h  stdlib.h  dos.h  graphics.h
#include
#include
#include
#include
#include
#include

void main()
{
    int gd=DETECT,gm;
    int x=10,y=200,x1=675,y1=380;
    int stangle=35,endangle=140,radius=90;

    initgraph(&gd,&gm,"..\\bgi");

    while(!kbhit())
    {
        cleardevice();
        setbkcolor(BLACK);

        if(x<640)
        {
            x+=5;
            y+=1;
            arc(x,y,stangle,endangle+35,radius);
            arc(x,y-110,190,323,radius+2);
            circle(x+40,y-60,5);
            line(x-90,y-90,x-90,y-8);
        }
        else
        {
            x1-=5;
            y1-=1;
            arc(x1,y1,stangle-30,endangle+4,radius);
            arc(x1,y1-110,217,350,radius+2);
            circle(x1-40,y1-60,5);
            line(x1+90,y1-90,x1+90,y1-10);
        }
        setcolor(YELLOW);
        delay(90);
    }
    closegraph();
}

Animated Analog Clock

//add header files as stdio.h  conio.h  graphics.h  dos.h  math.h
#include
#include
#include
#include
#include

#define arg_sec M_PI/30
#define arg_hour M_PI/6
#define arg_min M_PI/360
void main()
{
  int gd=DETECT,gm,sec=0,hour,min,x1=0,y1=0,x2=0,y2=0,x3=0,y3=0,i,dig_sec;
  char *k[12]={"1","2","3","4","5","6","7","8","9","10","11","12"};
  char Time_Dig[14];
  struct time t;
  initgraph(&gd,&gm,"c:\\tc\\bgi");
  setcolor(YELLOW);
  circle(300,200,200);
  circle(300,200,180);
  setfillstyle(2,RED);
  floodfill(300,390,YELLOW);
  settextstyle(DEFAULT_FONT,0,2);
//----------------------Constants----------------------//
    for(i=1;i<13;i++)
    {
       int a=160*cos(arg_hour*i-M_PI_2);
       int b=160*sin(arg_hour*i-M_PI_2);
    outtextxy(a+300,b+200,k[i-1]);
    }
  while(!kbhit())
   {
       settextstyle(7,0,4);
      outtextxy(264,100,"Babu");
      settextstyle(7,0,1);
      outtextxy(264,280,"Manisha");
      setcolor(BLACK);
      line(300,200,x1+300,y1+200);
      line(300,200,x2+300,y2+200);
      line(300,200,x3+300,y3+200);
      gettime(&t);
      if(sec!=t.ti_sec)
    {
       sound(5000);
       delay(1);
       nosound();
    }
      hour=t.ti_hour;
      sec=t.ti_sec;
      min=t.ti_min;
      Time_Dig[0]=hour/10+48;
      Time_Dig[1]=hour%10+48;
      Time_Dig[2]=':';
      Time_Dig[3]=min/10+48;
      Time_Dig[4]=min%10+48;
      Time_Dig[5]=':';
      Time_Dig[6]=sec/10+48;
      Time_Dig[7]=sec%10+48;
      Time_Dig[8]='\0';
      outtextxy(270,250,"ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ");
      x1=150*cos(arg_sec*sec-M_PI_2)*0.98;
      y1=150*sin(arg_sec*sec-M_PI_2)*0.98;
      x2=150*cos(arg_sec*min-M_PI_2)*0.9;
      y2=150*sin(arg_sec*min-M_PI_2)*0.9;
      if(hour>12) hour-=12;
      x3=150*cos(arg_hour*hour-M_PI_2+arg_min*min)*0.6;
      y3=150*sin(arg_hour*hour-M_PI_2+arg_min*min)*0.6;
      setcolor(YELLOW);
      line(300,200,x1+300,y1+200);
      setcolor(CYAN);
      line(300,200,x2+300,y2+200);
      setcolor(WHITE);
      line(300,200,x3+300,y3+200);
      setcolor(YELLOW);
      outtextxy(270,250,Time_Dig);
      delay(50);

   }

  getch();
  closegraph();
  restorecrtmode();
}
 
ShareThis

Visitor

Website counter
Copyright 2009 Code's. Powered by Blogger
Blogger Templates created by Deluxe Templates
Wordpress by Wpthemescreator
Blogger Showcase