Graphics Project : Bar Diagram [A Project work in Computer Graphics]

This was a Computer Graphics Project named Bar Diagram required in the coursework. [A Project work in Computer Graphics]

#include
#include
#include
#include
#include
#include

/*FUNCTION FOR READING DATA FROM USER*/

void input(float ,float,float,float,float,float);

/*FUNCTION FOR DRAWING BAR DIAGRAM*/

void bar1 (float);
void bar2 (float);
void bar3 (float);
void bar4 (float);
void bar5 (float);
void bar6 (float);

/* MAIN PROGRAM */

void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,”c:\\tc\\bgi”);

float sub1,sub2,sub3,sub4,sub5,sub6;
setbkcolor(9);
setcolor(BLUE);
settextstyle(3,0,2);
outtextxy(getmaxx()/2-130,0,”TRIBHUWAN UNIVERSITY”);
settextstyle(3,0,2);
outtextxy(getmaxx()/2-145,30,”INSTITUTE OF ENGINEERING”);
settextstyle(3,0,3);
outtextxy(getmaxx()/2-155,60,”WESTERN REGION CAMPUS”);
settextstyle(3,0,1);
outtextxy(getmaxx()/2-135,92,”LAMACHAUR-16,POKHARA”);
settextstyle(3,0,2);
outtextxy(getmaxy()/2+50,getmaxy()/2,”A”);
settextstyle(3,0,2);
outtextxy(getmaxy()/2+15,260,”PROJECT”);
settextstyle(3,0,2);
outtextxy(getmaxy()/2+40,getmaxy()/2+40,”ON”);
settextstyle(3,0,1);
outtextxy(getmaxy()/2-50,300,”COMPUTER GRAPHICS”);
outtextxy(getmaxx()-600,getmaxy()-140,”BY”);
outtextxy(getmaxx()-600,getmaxy()-110,”Archana Shrestha”);
outtextxy(getmaxx()-600,getmaxy()-80,”402/BEX/062″);

delay(2500);
cleardevice();
settextstyle(7,0,3);
outtextxy(getmaxx()/2-250,getmaxy()/2,”PROGRAM TO DRAW A BAR DIAGRAM”);
delay(1500);
input(sub1,sub2,sub3,sub4,sub5,sub6);
getch();
}
/*END OF MAIN PROGRAM*/

/*FUNCTION FOR READING DATA FROM USER */

void input(float sub1,float sub2 ,float sub3,float sub4,float sub5,float sub6)
{
cleardevice();
cout<“);

setcolor(12);
line(50,50,50,400);
line(50,400,600,400) ;
settextstyle(11,0,1);
outtextxy(70,430,”SUBJECT——->”);
setcolor(YELLOW);
settextstyle(2,0,2);
outtextxy(40,400,”00″);
outtextxy(40,380,”10″);
outtextxy(40,360,”20″);
outtextxy(40,340,”30″);
outtextxy(40,320,”40″);
outtextxy(40,300,”50″);
outtextxy(40,280,”60″);
outtextxy(40,260,”70″);
outtextxy(40,240,”80″);
outtextxy(40,220,”90″);
outtextxy(40,200,”100″);
setcolor(BLUE);
/* FUNCTION CALL TO DRAW BARDIAGRAM */
bar1(sub1);
bar2(sub2);
bar3(sub3);
bar4(sub4);
bar5(sub5);
bar6(sub6);
delay(3000);

cleardevice();
setbkcolor(1);
setcolor(5);

for (int j=0;j{
settextstyle(4,0,6);
setcolor(j);
delay(200);
outtextxy(getmaxx()/2-200,getmaxy()/2,” THANK-YOU “) ;
cout<

for(float i=0;i{
line(485,400-i,555,400-i);
delay(60);
}
}

Related articles suggested by Google

Hardware Concept in Computer Graphics- Mouse and Pointing Devices

Mouse play a very important role in development of Computer Graphics and to implement graphics in the computer system. Mouse is a pointing input device that points out item(s) by cursor. The cursor can be move from one position to another, this movement of cursor is due to the movement of mouse in the plane surface. The movement of mouse occurs only in two directions- vertical and horizontal. Mouse always measures its relative movement from its last position. Continue reading

Write a program (WAP) to draw a circle using Mid-point Algorithm

Although Bresenham’s algorithm is based upon integral operations only and is much faster than other algorithms, yet there is one drawback of this algorithm. This method is not uniformly applicable to all sorts of conics. For eg, for the ellipse drawing procedure, we need to treat two different regions in the first quadrant differently. This complication can be avoided by the midpoint method.

Mid-Point Circle Algorithm:

The following program written in C++ programming language uses circular symmetry of eight octants of the circle. Also delay in corresponding functions are used. Note the use of header file dos.h for delay.

// WAP to draw a circle using mid-point circle algorithm.

#include

#include

#include

#include

#include //used for delay function

void plot (float, float, float, float);

void main()

{

int gd=DETECT, gm;

initgraph(&gd, &gm, “c:\\tc\\bgi”);

float xc, yc, x, y, r, p;

cout<>xc>>yc;

x=0;y=r;

p=(1-r);

while(x

{

if(p

{

x++;

plot(xc, yc, x,y);

p=p+2*x+1;

}

else

{

x++;

y–;

plot(xc, yc, x, y);

p=p+2*x-2*y+1;

}

}

getch();

closegraph();

}

void plot(float xc, float yc, float x, float y)

{

// cleardevice();

putpixel(xc+x, yc+y, RED);

putpixel(xc-x, yc+y, RED);

putpixel(xc+x, yc-y, RED);

putpixel(xc-x, yc-y, RED);

putpixel(xc+y, yc+x, RED);

putpixel(xc-y, yc+x, RED);

putpixel(xc+y, yc-x, RED);

putpixel(xc-y, yc-x, RED);

delay(20);

}

To draw a line by using Bresenham’s line drawing algorithm

to draw a line by using Bresenham’s line drawing algorithm

// modified version checks slope sign and function realization

#include

#include

#include

#include

#include

void func(int, int, int, int);

void main()

{

int gd=DETECT, gm;

initgraph(&gd, &gm, “c:\\tc\\bgi”);

int x1, y1, x2, y2, dx, dy, p;

cout<

cin>>x2>>y2;

dx= abs(x2-x1);

dy= abs(y2-y1);

int slope= dy/dx;

p=(2*dy-dx);

int x=x1;

int y=y1;

if (slope<1)

func(x1,y1, x2, y2);

else

{

int tempx1=y1;

int tempy1=x1;

int tempx2=y2;

int tempy2=x2;

func(tempx1, tempy1, tempx2, tempy2);

}

getch();

closegraph();

}

void func(tempx1, tempy1, tempx2, tempy2)

{

int p, i, dx, dy, x, y, x1, y1;

putpixel(x1, y1,RED);

for(i=0; i

{

if(p<0)

{

p=(p+2*dy);

x=x+1;

putpixel(x,y,RED);

}

else

{

p=(p+2*dy-2*dx);

x=x++;

y=y++;

putpixel(x,y,RED);

}

}

closegraph();

}