Friday, June 21, 2013

Tennis game using graphics in C

//tennis game by fensa
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void main()
{
 float x=1,y=0.0,j=0.5,count=0.1,i,k,r=10;
 int gd=DETECT,gm;
 initgraph(&gd,&gm,"c:\\tc\\bgi");
 circle(20,230,20);//bat1
 line(20,250,20,300);
 circle(450,230,20);//bat2
 line(450,250,450,300);
// line(0,400,650,400);

 sleep(1);
 for(k=0;k<1;k++)
 {
  for(i=90;i<=270;i=i+2)
  {
   y=cos((i*22/7)/180)/j;
   if(y>0)
    y=-y;
    x=x+5;
    setcolor(14);
    setfillstyle(1,14);
    circle(x,y*75+200,r);
    floodfill(x,y*75+200,14);
    delay(40);
   setcolor(0);
   setfillstyle(1,0);
   circle(x,y*75+200,r);
   floodfill(x,y*75+200,0);
  }
   j=j+count;
   count=count+0.1;
 }
 for(k=0;k<1;k++)
 {
  for(i=270;i>=90;i=i-2)
  {
   y=cos((i*22/7)/180)/j;
   if(y>0)
    y=-y;
    x=x-5;
    setcolor(14);
    setfillstyle(1,14);
    circle(x,y*75+200,r);
    floodfill(x,y*75+200,14);
    delay(40);
   setcolor(0);
   setfillstyle(1,0);
   circle(x,y*75+200,r);
   floodfill(x,y*75+200,0);
  }
   j=j+count;
   count=count+0.1;
 }
 for(k=0;k<1;k++)
 {
  for(i=90;i<=270;i=i+2)
  {
   y=cos((i*22/7)/180)/j;
   if(y>0)
    y=-y;
    x=x+5;
    setcolor(14);
    setfillstyle(1,14);
    circle(x,y*75+200,r);
    floodfill(x,y*75+200,14);
    delay(40);
   setcolor(0);
   setfillstyle(1,0);
   circle(x,y*75+200,r);
   floodfill(x,y*75+200,0);
  }
   j=j+count;
   count=count+0.1;
 }
 getch();
 closegraph();
}

ball hitting wicket using graphics in C

//cricket by fensa
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void main()
{
 float x=1,y=0.0,j=0.5,count=0.1,i,k,r=10;
 int gd=DETECT,gm;
 initgraph(&gd,&gm,"c:\\tc\\bgi");
 line(0,210,650,210);
 line(470,150,470,210);//stump
 line(490,150,490,210);
 line(510,150,510,210);
 line(471,149,489,149);//wicket
 line(491,149,509,149);

 sleep(1);

 for(k=0;k<3;k++)
 {
  for(i=90;i<=250;i=i+5)
  {
    y=cos((i*22/7)/180)/j;
    if(y>0)
    y=-y;
    x=x+5;
    setcolor(14);
    setfillstyle(1,14);
    circle(x,y*100+200,r);
    floodfill(x,y*100+200,14);
    delay(40);
    setcolor(0);
    setfillstyle(1,0);
    circle(x,y*100+200,r);
    floodfill(x,y*100+200,0);
  }
    j=j+count;
    count=count+0.1;
 }
 cleardevice();
 setcolor(15);
 line(0,210,650,210);
 line(450,150,470,210);//stump
 line(490,150,490,210);
 line(530,150,510,210);
 line(471,149,489,139);//wicket
 line(493,139,512,149);
 getch();
}

Thursday, May 2, 2013

simple traffic system


//traffic system
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int i;
 int gd=DETECT,gm;
 initgraph(&gd,&gm,"c:\\tc\\bgi");

 for(i=0;i<600;i++)
 {
  outtextxy(30,50,"traffic system by Fensa Saj");
  rectangle(50+i,300,100+i,400);

  //traffic post
 line(10,200,600,200);
 line(500,180,500,200);
 rectangle(475,80,525,180);
 circle(500,100,10);
 circle(500,130,10);
 circle(500,160,10);
 setfillstyle(1,2);
 floodfill(500,160,15);
 if(i==350)
 {
 setfillstyle(1,0);
 floodfill(500,160,15);
 setfillstyle(1,14);
 floodfill(500,130,15);
 delay(600);
 setfillstyle(1,0);
 floodfill(500,130,15);
 setfillstyle(1,4);
 floodfill(500,100,15);
 delay(3000);
 }
 setfillstyle(1,2);
 floodfill(500,160,15);
 delay(40);
 cleardevice();
 }
 getch();
}

Monday, April 22, 2013

Analog clock using graphics in c


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
#define arg_sec M_PI/30
#define arg_hour M_PI/6
#define arg_min M_PI/360
void main()
{
  int a,b,i;
  int gd=DETECT,gm,sec=0,hour,min,x1=0,y1=0,x2=0,y2=0,x3=0,y3=0;
  char *k[12]={"1","2","3","4","5","6","7","8","9","10","11","12"};
  struct time t;
  initgraph(&gd,&gm,"c:\\tc\\bgi");
  setcolor(YELLOW);
  circle(300,200,200);
  circle(300,200,180);
  setfillstyle(1,RED);
  floodfill(300,390,YELLOW);
  settextstyle(DEFAULT_FONT,0,2);

  for(i=1;i<13;i++)
    {
a=160*cos(arg_hour*i-M_PI_2);
b=160*sin(arg_hour*i-M_PI_2);
outtextxy(a+300,b+200,k[i-1]);
    }

  while(!kbhit())
   {
      settextstyle(7,0,1);
      outtextxy(278,280,"Quartz");
      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;

      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);
      delay(50);
   }

  getch();
  closegraph();
}

Digital clock using graphics in c


//digital_clock

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

void main()
{
   int gd = DETECT, gm;
   int i=0, a[5];
   struct time t;
   initgraph(&gd, &gm, "c:\\tc\\bgi"); //Initializing Graphics mode
 
   while(!kbhit()) // if key hit is not received, display the clock
   {
    setcolor(YELLOW);
    gettime(&t);
    if(t.ti_hour>12)
    {
     t.ti_hour = t.ti_hour-12;
     settextstyle(DEFAULT_FONT,0,4);
     outtextxy(550,150,"PM");
    }
    else
    {
     outtextxy(550,150,"AM");
    }
    a[0]=t.ti_hour/10;
    a[1]=t.ti_hour%10;
    a[2]=t.ti_min/10;
    a[3]=t.ti_min%10;
    a[4]=t.ti_sec/10;
    a[5]=t.ti_sec%10;
    circle(240,150,2);
    circle(240,160,2);
    circle(390,150,2);
    circle(390,160,2);
    for(i=0;i<6;i++)
    {
     switch(a[i]) //Out the particular digit according to the input//
     {
      case 0:
    {
line(105+i*75,100,145+i*75,100);
line(100+i*75,105,100+i*75,145);
line(100+i*75,155,100+i*75,195);
line(105+i*75,200,145+i*75,200);
line(150+i*75,155,150+i*75,195);
line(150+i*75,105,150+i*75,145);
break;
    }
      case 1:
      {
       line(150+i*75,155,150+i*75,195);
       line(150+i*75,105,150+i*75,145);
       break;
      }
      case 2:
      {
       line(105+i*75,100,145+i*75,100);
       line(100+i*75,155,100+i*75,195);
       line(105+i*75,200,145+i*75,200);
       line(150+i*75,105,150+i*75,145);
       line(105+i*75,150,145+i*75,150);
       break;
      }
      case 3:
      {
       line(105+i*75,100,145+i*75,100);
       line(105+i*75,200,145+i*75,200);
       line(150+i*75,155,150+i*75,195);
       line(150+i*75,105,150+i*75,145);
       line(105+i*75,150,145+i*75,150);
       break;
      }
      case 4:
      {
       line(100+i*75,105,100+i*75,145);
       line(150+i*75,155,150+i*75,195);
       line(150+i*75,105,150+i*75,145);
       line(105+i*75,150,145+i*75,150);
       break;
      }
    case 5:
    {
    line(105+i*75,100,145+i*75,100);
    line(100+i*75,105,100+i*75,145);
    line(105+i*75,200,145+i*75,200);
    line(150+i*75,155,150+i*75,195);
    line(105+i*75,150,145+i*75,150);
    break;
    }
    case 6:
    {
    line(105+i*75,100,145+i*75,100);
    line(100+i*75,105,100+i*75,145);
    line(100+i*75,155,100+i*75,195);
    line(105+i*75,200,145+i*75,200);
    line(150+i*75,155,150+i*75,195);
    line(105+i*75,150,145+i*75,150);
    break;
    }
    case 7:
    {
    line(105+i*75,100,145+i*75,100);
    line(150+i*75,155,150+i*75,195);
    line(150+i*75,105,150+i*75,145);
    break;
    }
    case 8:
    {
    line(105+i*75,100,145+i*75,100);
    line(100+i*75,105,100+i*75,145);
    line(100+i*75,155,100+i*75,195);
    line(105+i*75,200,145+i*75,200);
    line(150+i*75,155,150+i*75,195);
    line(150+i*75,105,150+i*75,145);
    line(105+i*75,150,145+i*75,150);
    break;
    }
    case 9:
    {
    line(105+i*75,100,145+i*75,100);
    line(100+i*75,105,100+i*75,145);
    line(105+i*75,200,145+i*75,200);
    line(150+i*75,155,150+i*75,195);
    line(150+i*75,105,150+i*75,145);
    line(105+i*75,150,145+i*75,150);
    break;
    }
    }
    }
   delay(700);
   cleardevice();
   }
   closegraph();
}




Friday, April 5, 2013

Man opening umbrella program using Graphics in C


#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<math.h>
#include<graphics.h>
#include<stdlib.h>
void raindrops();
void far *man1,*man2;
unsigned size1,size2;
int cx=15,cy=360,r=22;
int x=0,y,p,i;
void drawgrass()
   {
    setfillstyle(3,GREEN);
    bar(0,385,getmaxx(),getmaxy());
   }
void drawmanbody()
 {
  fillellipse(15,350,7,7);
  moveto(15,350);
  lineto(15,370);
  lineto(25,360);
  lineto(25,369);
  lineto(15,370);
  lineto(15,390);
  lineto(15,390);
  lineto(15,390);
 }

 void drawman1()
  {
   drawmanbody();
   rectangle(23,369,28,400);
   setfillstyle(SOLID_FILL,RED);
   floodfill(24,370,WHITE);
   size1=imagesize(0,299,30,416);
   man1=malloc(size1);
   getimage(0,299,30,416,man1);
   setfillstyle(SOLID_FILL,WHITE);
   cleardevice();
  }

void drawman2()
 {
  drawmanbody();
  moveto(25,369);
  lineto(25,340);
  line(5,340,41,340);
  arc(23,340,0,180,18);
  setfillstyle(SOLID_FILL,RED);
  floodfill(24,339,WHITE);
  size2=imagesize(0,249,42,416);
  man2=malloc(size2);
  getimage(0,299,42,410,man2);
  cleardevice();
 }

 void raindrops()
   {
    int x,x1,y1;
    setcolor(15);
    x=getmaxx();
    x1=random(x);
    y1=random(480);
    line(x1,y1,x1+5,y1+5);
   }
int path1(int dtn)
{
    int x1,y1;
    setcolor(15);
    if(x>=y)
    {
return 0;
    }
    cleardevice();

    if(dtn==1)
    {

putimage(++i,270,man2,COPY_PUT);
raindrops();
drawgrass();
line(cx+i,cy,cx+x+i,cy+y);
line(cx+i,cy,cx-x+i,cy+y);
    }
    else
    {
putimage(++i,270,man2,COPY_PUT);
raindrops();
drawgrass();
line(cx+i,cy,cx-x+i,cy+y);
line(cx+i,cy,cx+x+i,cy+y);
    }
    delay(50);
    if(kbhit())
exit(0);
    x++;
    if(p<0)
p+=2*x+1;
    else
    {
y--;
p+=2*(x-y)+1;
    }
    x1=x;
    y1=y;
    path1(dtn);

    cleardevice();
    if(dtn==1)
    {
putimage(++i,270,man2,COPY_PUT);
raindrops();
  drawgrass();
line(cx+i,cy,cx+x1+i,cy+y1);
line(cx+i,cy,cx-x1+i,cy+y1);
    }
    else
    {

putimage(++i,270,man2,COPY_PUT);
raindrops();
drawgrass();
line(cx+i,cy,cx-x1+i,cy+y1);
line(cx+i,cy,cx+x1+i,cy+y1);
    }
    delay(50);
    if(kbhit())
exit(0);
    return(0);
}


int path(int dtn)
{
    int x1,y1;
    setcolor(15);
    if(x>=y)
    {
return 0;
    }
 

    if(dtn==1)
    {

putimage(++i,270,man1,COPY_PUT);
  drawgrass();
line(cx+i,cy,cx+x+i,cy+y);
line(cx+i,cy,cx-x+i,cy+y);
    }
    else
    {

putimage(++i,270,man1,COPY_PUT);
  drawgrass();
line(cx+i,cy,cx-x+i,cy+y);
line(cx+i,cy,cx+x+i,cy+y);
    }
    delay(50);
    if(kbhit())
exit(0);
    x++;
    if(p<0)
p+=2*x+1;
    else
    {
y--;
p+=2*(x-y)+1;
    }
    x1=x;
    y1=y;
    path(dtn);

    cleardevice();
    if(dtn==1)
    {

putimage(++i,270,man1,COPY_PUT);
  drawgrass();
line(cx+i,cy,cx+x1+i,cy+y1);
line(cx+i,cy,cx-x1+i,cy+y1);
    }
    else
   {
putimage(++i,270,man1,COPY_PUT);
   drawgrass();
line(cx+i,cy,cx-x1+i,cy+y1);
line(cx+i,cy,cx+x1+i,cy+y1);
    }
    delay(100);
    if(kbhit())
exit(0);
    return(0);
}

 void startwalk()
  {
   double theta;
   for(i=0;i<600;)
    {

if(i<=100)
{
        x=0;
        y=r;
        p=1-r;
path(1);
        x=0;
        y=r;
p=1-r;
path(0);
}
else if(i>100 && i<600)
{
x=0;
y=r;
p=1-r;
path1(1);
x=0;
y=r;
p=1-r;
path1(0);
}
}
}
//umbrella program by Fensa Merry Saj
 void main()
 {
   int i,j;
   int gd=DETECT,gm;
   initgraph(&gd,&gm,"c:\\tc\\bgi");
   drawman1();
   drawman2();
   startwalk();
   raindrops();
   getch();
 }






Sutherland-Hodgeman Polygon Clipping Program in C


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#define round(a) ((int)(a+0.5))
int k;
float xmin,ymin,xmax,ymax,arr[20],m;

void clipl(float x1,float y1,float x2,float y2)
{
if(x2-x1)
m=(y2-y1)/(x2-x1);
if(x1>=xmin && x2>=xmin)
{
arr[k]=x2;
arr[k+1]=y2;
k+=2;
}
if(x1<xmin && x2>=xmin)
{
arr[k]=xmin;
arr[k+1]=y1+m*(xmin-x1);
arr[k+2]=x2;
arr[k+3]=y2;
k+=4;
}
if(x1>=xmin  && x2<xmin)
{
arr[k]=xmin;
arr[k+1]=y1+m*(xmin-x1);
k+=2;
}
}

void clipt(float x1,float y1,float x2,float y2)
{
if(y2-y1)
m=(x2-x1)/(y2-y1);
if(y1<=ymax && y2<=ymax)
{
arr[k]=x2;
arr[k+1]=y2;
k+=2;
}
if(y1>ymax && y2<=ymax)
{
arr[k]=x1+m*(ymax-y1);
arr[k+1]=ymax;
arr[k+2]=x2;
arr[k+3]=y2;
k+=4;
}
if(y1<=ymax  && y2>ymax)
{
arr[k]=x1+m*(ymax-y1);
arr[k+1]=ymax;
k+=2;
}
}

void clipr(float x1,float y1,float x2,float y2)
{
if(x2-x1)
m=(y2-y1)/(x2-x1);
if(x1<=xmax && x2<=xmax)
{
arr[k]=x2;
arr[k+1]=y2;
k+=2;
}
if(x1>xmax && x2<=xmax)
{
arr[k]=xmax;
arr[k+1]=y1+m*(xmax-x1);
arr[k+2]=x2;
arr[k+3]=y2;
k+=4;
}
if(x1<=xmax  && x2>xmax)
{
arr[k]=xmax;
arr[k+1]=y1+m*(xmax-x1);
k+=2;
}
}

void clipb(float x1,float y1,float x2,float y2)
{
if(y2-y1)
m=(x2-x1)/(y2-y1);
if(y1>=ymin && y2>=ymin)
{
arr[k]=x2;
arr[k+1]=y2;
k+=2;
}
if(y1<ymin && y2>=ymin)
{
arr[k]=x1+m*(ymin-y1);
arr[k+1]=ymin;
arr[k+2]=x2;
arr[k+3]=y2;
k+=4;
}
if(y1>=ymin  && y2<ymin)
{
arr[k]=x1+m*(ymin-y1);
arr[k+1]=ymin;
k+=2;
}
}

void main()
{
int gdriver=DETECT,gmode,n,poly[20],i;
float xi,yi,xf,yf,polyy[20];
clrscr();
printf("Coordinates of rectangular clip window :\nxmin,ymin:");
scanf("%f%f",&xmin,&ymin);
printf("Coordinates of rectangular clip window :\nxmax,ymax:");
scanf("%f%f",&xmax,&ymax);
printf("\n\nPolygon to be clipped :\nNumber of sides       :");
scanf("%d",&n);
printf("Enter the coordinates :");
for (i=0;i<2*n;i++)
scanf("%f",&polyy[i]);
polyy[i]=polyy[0];
polyy[i+1]=polyy[1];
for(i=0;i<2*n+2;i++)
poly[i]=round(polyy[i]);
initgraph(&gdriver,&gmode,"C:\\TC\\BGI");
rectangle(xmin,ymax,xmax,ymin);
printf("\tUNCLIPPED POLYGON");
printf("hi");
fillpoly(n,poly);
getch();
cleardevice();
k=0;
for(i=0;i<2*n;i+=2)
clipl(polyy[i],polyy[i+1],polyy[i+2],polyy[i+3]);
n=k/2;
for(i=0;i<k;i++)
polyy[i]=arr[i];
polyy[i]=polyy[0];
polyy[i+1]=polyy[1];
k=0;
for(i=0;i<2*n;i+=2)
clipt(polyy[i],polyy[i+1],polyy[i+2],polyy[i+3]);
n=k/2;
for(i=0;i<k;i++)
polyy[i]=arr[i];
polyy[i]=polyy[0];
polyy[i+1]=polyy[1];
k=0;
for(i=0;i<2*n;i+=2)
clipr(polyy[i],polyy[i+1],polyy[i+2],polyy[i+3]);
n=k/2;
for(i=0;i<k;i++)
polyy[i]=arr[i];
polyy[i]=polyy[0];
polyy[i+1]=polyy[1];
k=0;
for(i=0;i<2*n;i+=2)
clipb(polyy[i],polyy[i+1],polyy[i+2],polyy[i+3]);
for(i=0;i<k;i++)
poly[i]=round(arr[i]);
if(k)
fillpoly(k/2,poly);
rectangle(xmin,ymax,xmax,ymin);
printf("\tCLIPPED POLYGON");
getch();
closegraph();
}

Wednesday, March 20, 2013

Cohen-Sutherland's Line clipping in C


//line clipping
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<dos.h>
#define MAX 20
void cohen_sutherlands(double,double,double,double,double,double,double,double);
enum{TOP=0x1,BOTTOM=0x2,RIGHT=0x4,LEFT=0x8};
enum{FALSE,TRUE};
typedef unsigned int outcode;
outcode compute_outcode(int x,int y,int xmin,int ymin,int xmax,int ymax)
{
 outcode oc=0;
 if(y>ymax)
 oc|=TOP;
 else if(y<ymin)
 oc|=BOTTOM;
 if(x>xmax)
 oc|=RIGHT;
 else if(x<xmin)
 oc|=LEFT;
 return oc;
}

void cohen_sutherlands(double x1,double y1,double x2,double y2,double xmin,double ymin,double xmax,double ymax)
{
 int accept;
 int done;
 outcode outcode1,outcode2;
 accept=FALSE;
 done=FALSE;
 outcode1=compute_outcode(x1,y1,xmin,ymin,xmax,ymax);
 outcode2=compute_outcode(x2,y2,xmin,ymin,xmax,ymax);
 do
 {
  if(outcode1==0&&outcode2==0)
  {
   accept=TRUE;
   done=TRUE;
  }
  else if(outcode1&outcode2)
  {
   done=TRUE;
  }
  else
  {
   double x,y;
   int outcode_ex=outcode1?outcode1:outcode2;
   if(outcode_ex&TOP)
   {
    x=x1+(x2-x1)*(ymax-y1)/(y2-y1);
    y=ymax;
   }
   if(outcode_ex&BOTTOM)
   {
    x=x1+(x2-x1)*(ymin-y1)/(y2-y1);
    y=ymin;
   }
   else if(outcode_ex&RIGHT)
   {
    y=y1+(y2-y1)*(xmax-x1)/(x2-x1);
    x=xmax;
   }
   else if(outcode_ex&LEFT)
   {
    y=y1+(y2-y1)*(xmin-x1)/(x2-x1);
    x=xmin;
   }
   if(outcode_ex==outcode1)
   {
    x1=x;
    y1=y;
    outcode1=compute_outcode(x1,y1,xmin,ymin,xmax,ymax);
   }
   else
   {
    x2=x;
    y2=y;
    outcode2=compute_outcode(x2,y2,xmin,ymin,xmax,ymax);
   }
  }
 }
 while(done==FALSE);
 if(accept==TRUE)
 line(x1,y1,x2,y2);
}
//fms
void main()
{
 int n,i,j;
 int ln[MAX][4];
 int clip[4];
 int gd=DETECT,gm;
 printf("\nenter the no. of lines to be clipped");
 scanf("%d",&n);
 printf("\nEnter the x & y coordinates of line end points");
 for(i=0;i<n;i++)
 for(j=0;j<4;j++)
 scanf("%d",&ln[i][j]);
 printf("\nEnter the x & y coordinates of left top & right bottom");
 for(i=0;i<4;j++)
 scanf("%d",&clip[i]);
 initgraph(&gd,&gm,"c:\\tc\\bgi");
 rectangle(clip[0],clip[1],clip[2],clip[3]);
 for(i=0;i<n;i++)
 line(ln[i][0],ln[i][1],ln[i][2],ln[i][3]);
 getch();
 cleardevice();
 rectangle(clip[0],clip[1],clip[2],clip[3]);
 for(i=0;i<n;i++)
 {
  cohen_sutherlands(ln[i][0],ln[i][1],ln[i][2],ln[i][3],clip[0],clip[1],clip[2],clip[3]);
  getch();
 }
 closegraph();
}

Saturday, March 2, 2013

Traffic System using GRAPHICS in C


//Traffic System
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>

void traf(int,int,int);
void car(int);

void main()
{
 int gd=DETECT,gm,i;
 initgraph(&gd,&gm,"c:\\tc\\bgi");
 for(i=0;i<650;i++)
 {
  if(i!=150)
  {
   traf(0,0,2);
   setcolor(6);
   car(i);
   delay(15);
   cleardevice();
  }
  else
  {
   traf(4,0,0);
   setcolor(6);
   car(i);
   delay(3500);
   traf(0,0,2);
  }
 }
 getch();
}

void traf(int r,int y,int g)
{
 cleardevice();
 setcolor(6);
 rectangle(490,50,530,110);
 setfillstyle(1,r);
 fillellipse(510,60,10,10);
 setfillstyle(1,y);
 fillellipse(510,80,10,10);
 setfillstyle(1,g);
 fillellipse(510,100,10,10);
 setcolor(4);
 line(505,110,505,200);
 line(515,110,515,200);
 setcolor(15);
 line(0,200,getmaxx(),200);
 line(0,416,getmaxx(),416);
}

void car(int i)
{
 ellipse(125+i,320,0,180,50,25);
 line(41+i,320,75+i,320);
 line(175+i,320,208+i,320);
 arc(75+i,328,165,216,36);
 line(45+i,350,205+i,350);
 arc(175+i,328,320,373,36);
 circle(80+i,360,10);
 circle(160+i,360,10);
}

Monday, February 11, 2013

JavaScript program to display todays date


<!--fms-->
<html>
<head>
<script>
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
}
</script>
</head>
<body>

<h1>JavaScript to display date</h1>
<p id="demo">This is a paragraph.</p>

<button type="button" onclick="displayDate()">Display Date</button>

</body>
</html>

jsp to display todays day of the week


<!--fms-->
<html>
<body>

<p id="demo">Click the button to display todays day of the week.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction()
{
var d = new Date();
var weekday=new Array(7);
weekday[0]="Today is Sunday";
weekday[1]="Today is Monday";
weekday[2]="Today is Tuesday";
weekday[3]="Today is Wednesday";
weekday[4]="Today is Thursday";
weekday[5]="Today is Friday";
weekday[6]="Today is Saturday";

var x = document.getElementById("demo");
x.innerHTML=weekday[d.getDay()];
}
</script>

</body>
</html>

Sunday, February 10, 2013

jsp program to display clock


<!jsp program to display clock!>
<!DOCTYPE html>
<html>
<head>
<script>
function startTime()
{
  var today=new Date();
  var h=today.getHours();
  var m=today.getMinutes();
  var s=today.getSeconds();
  // add a zero in front of numbers<10
  m=checkTime(m);
  s=checkTime(s);
  document.getElementById('txt').innerHTML=h+":"+m+":"+s;
  t=setTimeout(function(){startTime()},500);
}

function checkTime(i)
{
   if (i<10)
   {
      i="0" + i;
   }
   return i;
}
</script>
</head>

<body onload="startTime()">
<div id="txt"></div>
</body>
</html>

Wednesday, January 30, 2013

Code for Program to rotate about reference point in C++ Programming


Code for Program to rotate about reference point in C++ Programming
# include <iostream.h>
# include <conio.h>
# include <graphics.h>
# include <math.h>

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();

Friday, January 25, 2013

Cascading Style Sheet inline & internal example


<!--Example of Cascading Style Sheet with inline & internal....fensasaj@blogspot.com-->
<html>
<head>
<style>
body
{
background-color:lightblue;
}
h1
{
color:red;
text-align:center;
}
h4
{
text-align:left;
background-color:pink;
color:green;
}
p
{
font-family:"Palace Script MT";
font-size:70px;
color:blue;
}
</style>
</head>
<body>
<h1>WELCOME</h1>
<h4>Log onto e-mail</h4>
<p>This is first page...........................
Welcome to first page...........................
Keep trying.....................................
</p>
</body>
</html>

Validation of Username and Password


<!--Validation of Username and Password........fensasaj@blogspot.com-->
<html>
<head>
</head>
<body bgcolor="cyan">

<form>

<h3 align="center">username<input type="text" name="userid"/>
</h3>
<br>
<h3 align="center">password<input type="password" name="password"/>
</h3>
<br>
<input type ="button" onclick="check(this.form)" value="submit"/>

<input type="reset" value="reset"/>

</form>

<script language="javascript">

function check(form)
{
 if(form.userid.value=="lbs"&&form.password.value=="it")
 {
  document.write("Welcome lbs!!");
 }
 else
 {
  alert("you are a wrong user");
 }
}

</script>

</body>

</html>

Calculator using Javascript


<!--Creating Calculator using Javascript....fensasaj@blogspot.com-->
<html>
<head>
<script type="text/javascript">

function pushButton(buttonValue) {
     if (buttonValue == 'C') {
          document.getElementById('screen').value = '';
     }
     else {
          document.getElementById('screen').value += buttonValue;
     }
}
function calculate(equation) {
     var answer = eval(equation);
     document.getElementById('screen').value = answer;

}
</script>
</head>
<body>
<style type="text/css">
table.calc {
     border: 2px solid #0034D1;
     background-color: #809FFF;
}
input.calc {
     width: 100%;
     margin: 5px;
}
</style>
<fieldset>
<legend>Calculator</legend>
<table class="calc" cellpadding=4>
<tr><td colspan=3><input class="calc" id="screen" type="text"></td></tr>
<tr>
<td><input class="calc" type="button" value=1 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=2 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=3 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value='/' onclick="pushButton(this.value);"></td>
</tr>
<tr>
<td><input class="calc" type="button" value=4 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=5 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=6 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value='*' onclick="pushButton(this.value);"></td>
</tr>
<tr>
<td><input class="calc" type="button" value=7 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=8 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=9 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value='-' onclick="pushButton(this.value);"></td>
</tr>
<tr>
<td><input class="calc" type="button" value=0 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value='.' onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value='C' onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value='+' onclick="pushButton(this.value);"></td>
</tr>
<tr><td colspan=3><input class="calc" type="button" value='=' onclick="calculate(document.getElementById('screen').value);"></td></tr>
</table>
</body>
</html>

Online QUIZ using Javascript


<!--ONLINE QUIZ example ......fensasaj@blogspot.com.-->
<HEAD>
     
    <SCRIPT LANGUAGE="JavaScript">
   
     
    var ans = new Array;
    var done = new Array;
    var score = 0;
    ans[1] = "c";
    ans[2] = "a";
    ans[3] = "b";
    ans[4] = "b";
    ans[5] = "d";
 
    function Pop(question, answer) {
    if (answer != ans[question]) {
    if (!done[question]) {
    done[question] = -1;
    alert("Wrong! and Your score is now: " + score);
    }
    else {
    alert("You have already answered that!");
       }
    }
    else {
    if (!done[question]) {
    done[question] = -1;
    score++;
    alert("Correct!and Your score is now: " + score);
    }
    else {      
    alert("You have already answered that!");
          }
       }
    }
         
    function NextLevel () {
    if (score > 5) {
    alert("Cheater!");
    }
    if (score >= 3 && score <= 6) {
    alert("Access permitted!  But there are no more levels if you don't make any ...")
     
    //change previous line to: self.location="js_misc_userquiz2.html" if you make more
     
    }
    else {
    alert("Access denied!  You need 3 points to enter the next level.")
       }
    }
   
    </SCRIPT>
     
 
     
    <BODY>
     
    <font size=7 face=Arial>Online Quiz</font><br><p>
    <b>Objective: answer 3 questions correctly.  JavaScript required!</b><p>
    <noscript>JavaScript is <b><i>disabled</b></i>.  Get Netscape 3.0 or turn it on!</noscript>
    <hr noshade>
    <FORM>
    <b>1. Which is the capital of  <i>Canada</i>?</b><p>
    <input type=radio value="a" onClick="Pop(1, this.value)">Doha<br>
    <input type=radio value="b" onClick="Pop(1, this.value)">Canbera<br>
    <input type=radio value="c" onClick="Pop(1, this.value)">Ottawa<br>
    <input type=radio value="d" onClick="Pop(1, this.value)">Vienna<p>
    <b>2. Where is the head quarters of <i>UNESCO</i>?</b><p>
    <input type=radio value="a" onClick="Pop(2, this.value)">Paris<br>
    <input type=radio value="b" onClick="Pop(2, this.value)">Switzerland<br>
    <input type=radio value="c" onClick="Pop(2, this.value)">Brazil<br>
    <input type=radio value="d" onClick="Pop(2, this.value)">Delhi<p>
    <b>3. Which is the first country to introduce currency notes ?</b><p>
    <input type=radio value="a" onClick="Pop(3, this.value)">India<br>
    <input type=radio value="b" onClick="Pop(3, this.value)">China<br>
    <input type=radio value="c" onClick="Pop(3, this.value)">Pakisthan<br>
    <input type=radio value="d" onClick="Pop(3, this.value)">Sri Lanka<p>
    <b>4. Who is the first Indian Nobel Laurette?</b><p>
    <input type=radio value="a" onClick="Pop(4, this.value)">Amartya Sen<br>
    <input type=radio value="b" onClick="Pop(4, this.value)">Rabindra Nath Tagore<br>
    <input type=radio value="c" onClick="Pop(4, this.value)">Indira Gandhi<br>
    <input type=radio value="d" onClick="Pop(4, this.value)">Mother Theresa<p>
    <b>5. Who invented Radio? </b><p>
    <input type=radio value="a" onClick="Pop(5, this.value)">Edison<br>
    <input type=radio value="b" onClick="Pop(5, this.value)">Bell<br>
    <input type=radio value="c" onClick="Pop(5, this.value)">Newton<br>
    <input type=radio value="d" onClick="Pop(5, this.value)">Marcony<p>
   
    <CENTER>
    <input type=button onClick="NextLevel()" value="Advance to next level">
    </CENTER>
    </FORM>