Friday, December 4, 2009

BARGRAPH

#include
#include
#include
#include
# define pi 3.142857
# define round(a)((int)(a+0.5))

//))))))))))))))))
void ddaline(int x1,int y1,int x2,int y2,int col)
{ int steps,dx,dy,i;float xinc,yinc,x,y;
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>abs(dy))
steps=abs(dx);
else
steps=abs(dy);
xinc=(float)dx/steps;
yinc=(float)dy/steps;
x=x1;y=y1;
putpixel(x,y,col);
for(i=0;i {
x=x+xinc;
y=y+yinc;
putpixel(round(x),round(y),col);
}
}
//00000000000
void bfill(int x,int y,int bclr,int fclr)
{ int curclr;
curclr=getpixel(x,y);
if(curclr!=fclr && curclr!=bclr)
{
putpixel(x,y,fclr);
bfill(x+1,y,bclr,fclr);
bfill(x,y+1,bclr,fclr);
bfill(x-1,y,bclr,fclr);
bfill(x,y-1,bclr,fclr);
}
}
//------------------
void main()
{ int gd,gm; int y[10],i,x,n,y1,sx,sy;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"..\\bgi");
printf("\n enter the no of data\n");
scanf("%d",&n);
printf("\n enter the data(<30)as stack overflows\n");
for(i=0;i {

scanf("%d",&y[i]);
y[i]=5*y[i];
}
cleardevice();
outtextxy(200,20,"SCALE: xaxis:1div=20 yaxis:1div=5");
ddaline(30,0,30,300,11);
ddaline(30,300,600,300,11);
y1=300;
while(y1>0)
{ y1-=5;
ddaline(30,y1,35,y1,11);
}
x=50;
for(i=0;i { ddaline(x,300,x,300-y[i],11);
ddaline(x,300-y[i],x+20,300-y[i],11);
ddaline(x+20,300-y[i],x+20,300,11);
sx=x+10;
sy=300-y[i]/2;
bfill(sx,sy,11,i+1);
x+=40;
}
getch();
}

1 comment:

  1. note-the common header files to be included are
    stdio.h
    conio.h
    graphics.h
    math.h

    the included header files did not show up in any post due to enclosure by"<" and ">"!

    ReplyDelete