Professional Documents
Culture Documents
Avi 86
Avi 86
INDEX
Practical: - 1(A)
Rushi Pate l
Avi Patel
IU2141220086
IU2141220108
Practical: - 1(B)
Aim: - TO STUDY BASICS OF COMPUTER GRAPHICS BY CREATING
A PICTURE FRAME IN C/C++.
Program:
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm,xmax,ymax;
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
xmax=getmaxx();
ymax=getmaxy();
printf("%d %d",xmax,ymax);
setfillstyle(SOLID_FILL,2);
line(0,ymax/2,xmax,ymax/2);
line(0,ymax/2,xmax/8,0);
line(xmax/8,0,xmax/4,ymax/2);
line(xmax/4,ymax/2,xmax/3,0);
line(xmax/3,0,xmax/2,ymax/2);
floodfill(xmax/8,(ymax/2)-10,getmaxcolor());
setfillstyle(SOLID_FILL,6);
circle(xmax/2,100,40);
floodfill(xmax/2,100,getmaxcolor());
getch();
}
OUTPUT:
Program:
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<math.h>
void main(){
int gd= DETECT ,gm ;
int x1 , y1, x2, y2, i = 0 ,dx
,dy,x,y; int s1,s2,swap=0 ,temp,e;
printf("Enter x1:");
scanf("%d",&x1);
printf("Enter x2:");
scanf("%d",&x2);
printf("Enter Y1:");
scanf("%d",&y1);
printf("Enter Y2:");
scanf("%d",&y2);
initgraph(&gd,&gm , "C:\\TURBOC3\\BGI");
x = x1;
y =y1;
dx =abs (x2 -
x1); dy =abs (y2
-y1);
if(x2>x1)
{ s1=
1;
OUTPUT: -
Rushi Patel
IU2141220108
Practical: - 2(B)
Aim: - IMPLEMENT A ROTATING WHEEL USING C GRAPHICS.
Program: -
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <dos.h>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode,
th=0; float rad1, rad2,rad3, rad4;
int x, y,i=0;
int r = 100;
OUTPUT:
Practical: - 3(A)
Aim: - Implement mid point circle algorithm.
Program: -
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
int main()
{
int gd=DETECT,gm;
int xc=300,yc=200,x=0,y=0,r=70;
float p;
/*printf("Enter center and radius");
scanf("%d%d%d",&xc,&yc,&r); */
initgraph(&gd,&gm,"..\\BGI\\");
x=0;
y=r;
p=(5/4)-r;
while(x<=y)
{
if(p<0)
{
x=x+1;
p=p+(2*x)+1;
}
else
{
x=x+1;
OUTPUT:
IU2141220108
Rushi Patel
IU2141220086
Avi Patel
Practical: - 3(B)
Aim: - Draw an Analog Clock using computer graphics programming in C.
Program: -
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <dos.h>
int main(void)
{
float rad1,rad2,rad3,rad4,rad5,rad6,rad7;
int t1=0;
int th=0;
int gdriver = DETECT,
gmode; int midx, midy;
int radius = 100;
initgraph(&gdriver, &gmode,
"C://TURBOC3//BGI"); while(!kbhit())
{
cleardevice();
midx = getmaxx()/2;
midy = getmaxy()/2;
setfillstyle(SOLID_FILL,9);
circle(midx,midy,radius);
floodfill(midx,midy+85,getmaxcolor());
setfillstyle(SOLID_FILL,1);
circle(midx,midy,90);
floodfill(midx,midy+95,getmaxcolor());
setfillstyle(SOLID_FILL,8);
OUTPUT:
Program: -
#include <stdio.h>
#include <math.h>
#include <graphics.h>
#include <conio.h>
typedef struct {
int x;
int y;
} Point;
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm,"C:\\turboc3\\bgi");
Point vertices[] = {
{100, 100},
{200, 100},
{200, 200},
{100, 200}
};
drawSquare(vertices);
int choice;
printf("Select transformation:\n");
printf("1. Translation\n");
printf("2. Scaling\n");
printf("3. Rotation\n");
printf("Enter your choice:
"); scanf("%d", &choice);
switch (choice) {
case 1: {
int dx, dy;
printf("Enter translation values (dx dy):
"); scanf("%d %d", &dx, &dy);
translate(vertices, dx, dy);
break;
}
case 2: {
float sx, sy;
printf("Enter scaling factors (sx sy):
"); scanf("%f %f", &sx, &sy);
scale(vertices, sx, sy);
break;
}
case 3: {
float angle;
printf("Enter rotation angle (degrees):
"); scanf("%f", &angle);
rotate(vertices, angle);
break;
}
default:
printf("Invalid choice\n");
IU2141220086 Avi Patel 18
Computer Graphics (IT0501)
closegraph();
return 1;
}
drawSquare(vertices);
outtextxy(400,380,"IU2141220086");
outtextxy(400,400,"Avi Patel");
getch();
closegraph();
return 0;
}
OUTPUT:
IU2141220108
IU2141220086
Practical: - 4(B)
Aim: - Create inverse animation keeping car static and moving the road.
Program: -
#include <stdio.h>
#include <graphics.h>
#include <dos.h>
int main()
{
int gd = DETECT, gm; int i, maxx, midy;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
maxx = getmaxx();
midy = getmaxy()/2;
setcolor(WHITE);
line(0, midy + 37, maxx, midy +
37); setcolor(YELLOW);
setfillstyle(SOLID_FILL, RED);
line(i, midy + 23, i, midy);
line(i, midy, 40 + i, midy - 20);
line(40 + i, midy - 20, 80 + i, midy - 20);
line(80 + i, midy - 20, 100 + i, midy);
line(100 + i, midy, 120 + i, midy);
line(120 + i, midy, 120 + i, midy + 23);
line(0 + i, midy + 23, 18 + i, midy + 23);
arc(30 + i, midy + 23, 0, 180, 12);
line(42 + i, midy + 23, 78 + i, midy +
23); arc(90 + i, midy + 23, 0, 180, 12);
line(102 + i, midy + 23, 120 + i, midy +
23); line(28 + i, midy, 43 + i, midy - 15);
line(43 + i, midy - 15, 57 + i, midy -
15); line(57 + i, midy - 15, 57 + i,
midy); line(57 + i, midy, 28 + i, midy);
line(62 + i, midy - 15, 77 + i, midy -
15); line(77 + i, midy - 15, 92 + i,
midy); line(92 + i, midy, 62 + i, midy);
line(62 + i, midy, 62 + i, midy - 15);
floodfill(5 + i, midy + 22, YELLOW);
setcolor(BLUE);
setfillstyle(SOLID_FILL, DARKGRAY);
IU2141220086 Avi Patel 20
Computer Graphics (IT0501)
circle(30 + i, midy + 25, 9);
circle(90 + i, midy + 25, 9);
floodfill(30 + i, midy + 25, BLUE);
floodfill(90 + i, midy + 25, BLUE);
delay(100);
outtextxy(300,380,"IU2141220086");
outtextxy(300,400,"Avi Patel");
}
closegraph();
return 0;
}
OUTPUT: -
IU2141220108
Rushi Patel
IU2141220086
Avi Patel
Practical: - 5(A)
Aim: - W.A.P. To write a Program in C to implement the basic 2-Dimensional
transformations such as Shear and Reflection.
Program: -
#include <conio.h>
#include <graphics.h>
#include <stdio.h>
void main()
{
int gm, gd = DETECT, ax, x1 = 100;
int x2 = 100, x3 = 200, y1 = 100;
int y2 = 200, y3 = 100;
OUTPUT: -
Practical: - 6(A)
Program: -
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
int maxx,maxy,midx,midy;
void axis()
{
getch(); cleardevice();
line(midx,0,midx,maxy);
line(0,midy,maxx,midy);
}
void main()
{
int gd = DETECT, gm;
int x,y,z,ang,x1,x2,y1,y2;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
setfillstyle(3,25);
maxx=getmaxx();
maxy=getmaxy();
midx=maxx/2;
midy=maxy/2;
outtextxy(100,100,"ORIGINAL OBJECT");
line(midx,0,midx,maxy);
line(0,midy,maxx,midy);
bar3d(midx+100,midy-20,midx+60,midy-90,20,5);
axis();
outtextxy(100,20,"TRANSLATION");
printf("\n\n Enter the Translation vector:
"); scanf("%d%d",&x,&y);
bar3d(midx+100,midy-20,midx+60,midy-90,20,5); bar3d(midx+
(x*100),midy-(y+20),midx+(x+60),midy-(y+90),20,5); axis();
outtextxy(100,20,"SCALING");
printf("\n Enter the Scaling Factor: ");
scanf("%d%d%d",&x,&y,&z);
outtextxy(100,20,"ROTATION");
printf("\n Enter the Rotation angle:
"); scanf("%d",&ang);
x1=100*cos(ang*3.14/180)-20*sin(ang*3.14/180);
y1=100*sin(ang*3.14/180)+20*sin(ang*3.14/180);
x2=60*cos(ang*3.14/180)-90*sin(ang*3.14/180);
y2=60*sin(ang*3.14/180)+90*sin(ang*3.14/180);
axis();