CG Practical
CG Practical
COMPUTER GRAPHICS
(BCA0604)
CLASS: BCA 6TH
ROLL NO. : 21BCA016
UNIVERSITY ROLL NO: 6210250027
SUBMITTED BY: SAHIL BHARDWAJ
SUBMITTED TO: A.P. ANCHAL SHARMA
[Practical File Computer Graphics]
INDEX
[1]
[Practical File Computer Graphics]
#include <graphics.h>
void main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\TurboC++\Disk\TurboC3\BGI");
line(150, 150, 450, 150);
line(150, 250, 450, 250);
getch();
closegraph();
}
OUTPUT:
[2]
[Practical File Computer Graphics]
#include <graphics.h>
void main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\TurboC++\Disk\TurboC3\BGI");
circle(300, 200, 100);
getch();
closegraph();
}
OUTPUT:
[3]
[Practical File Computer Graphics]
[4]
[Practical File Computer Graphics]
Output:
[5]
[Practical File Computer Graphics]
x = getmaxx() / 2;
y = getmaxy() / 2;
Output:
[6]
[Practical File Computer Graphics]
[7]
[Practical File Computer Graphics]
Output:
[8]
[Practical File Computer Graphics]
[9]
[Practical File Computer Graphics]
[10]
[Practical File Computer Graphics]
Output:
[11]
[Practical File Computer Graphics]
closegraph();
return 0;
}
Output:
[12]
[Practical File Computer Graphics]
int main()
{
cout << "Enter no. of sides in polygon: ";
cin >> n;
cout << "Enter coordinates x, y for each vertex: ";
for (i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
cout << "Enter scale factors: sfx and sfy : ";
cin >> sfx >> sfy;
initgraph(&gd, &gm, (char*)"");
cleardevice();
setcolor(RED);
draw();
scale();
setcolor(YELLOW);
draw();
getch();
closegraph();
return 0;
}
void draw()
{
for (i = 0; i < n; i++) {
line(x[i], y[i], x[(i + 1) % n], y[(i + 1) % n]);
}
}
void scale()
{
[13]
[Practical File Computer Graphics]
Output:
[14]
[Practical File Computer Graphics]
Output:
[15]
[Practical File Computer Graphics]
void main( )
{
float x,y,x1,y1,x2,y2,dx,dy,step;
int i,gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>=dy)
step=dx;
else
step=dy;
dx=dx/step;
dy=dy/step;
x=x1;
y=y1;
i=1;
while(i<=step)
{
putpixel(x,y,5);
x=x+dx;
y=y+dy;
i=i+1;
delay(100);
}
[16]
[Practical File Computer Graphics]
closegraph();
}
Output:
[17]
[Practical File Computer Graphics]
#include<stdlib.h>
#include<graphics.h>
#include<dos.h>
#include<conio.h>
int main(){
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
CMP(300, 200, 100);
[18]
[Practical File Computer Graphics]
getch();
return 0;
}
Output:
[19]
[Practical File Computer Graphics]
[20]
[Practical File Computer Graphics]
Output:
[21]
[Practical File Computer Graphics]
[22]
[Practical File Computer Graphics]
putpixel(xc-x,yc+y,WHITE);
putpixel(xc-x,yc-y,WHITE);
if(p>0)
{
y=y-1;
p=p-2*a*a*y+a*a;
}
else
{
x=x+1;
y=y-1;
p=p-2*a*a*y+2*b*b*x+a*a;
}
}while(y!=0);
getch();
closegraph();
}
Output:
[23]