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 ...
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.
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++ ...
DDA Algorithm
The Digital Differential Analyzer DDA is a scan conversion line algorithm based on calculating either the difference of y or x ie ?y or ?x. The pixel positions are calculated initially- uses raster characteristics so that appropriate increments are applied in the x or y direction to step to pixel positions along the line path.
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();
}