SlideShare a Scribd company logo
1 of 22
[1]
Practical-01
Q1) Drawing star
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:tcbgi");
line(320,100,220,300);
line(220,300,420,300);
line(420,300,320,100); // straight triangle
line(320,350,220,150);
line(220,150,420,150);
line(420,150,320,350); // reverse triangle
setfillstyle(SOLID_FILL,1);
floodfill(320,102,15); //top triangle
setfillstyle(SOLID_FILL,2);
floodfill(225,152,15); //top left
setfillstyle(SOLID_FILL,3);
floodfill(225,298,15); //bottom left
setfillstyle(SOLID_FILL,4);
floodfill(320,348,15); //bottom
setfillstyle(SOLID_FILL,5);
floodfill(415,298,15); //bottom right
setfillstyle(SOLID_FILL,6);
floodfill(415,152,15); //top right
setfillstyle(SOLID_FILL,7);
floodfill(320,200,15); //middle
getch();
}
Q2)//House
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd, &gm, "C:TCBGI");
rectangle(100,200,400,400); //big wall
line(150,100,100,200); //left side of triangle
line(150,100,200,200); //right side of triangle
line(150,100,350,100); //top side of roof
line(200,200,400,200); //bottom side of roof
line(350,100,400,200); //right side of roof
line(200,200,200,400); //dividing wall into two parts
circle(150,160,20); //drawing circle within triangle
rectangle(120,250,180,400); //door
rectangle(225,225,375,300); //window
setfillstyle(SOLID_FILL,LIGHTRED);
floodfill(102,202,WHITE); //filling first wall
setfillstyle(SOLID_FILL,BLUE);
floodfill(202,202,WHITE); //filling second wall
setfillstyle(SOLID_FILL,CYAN);
floodfill(122,252,WHITE); //filling door
setfillstyle(XHATCH_FILL,GREEN);
[2]
floodfill(252,252,WHITE); //filling window
setfillstyle(SOLID_FILL,MAGENTA);
floodfill(150,102,WHITE); //filling triangle
setfillstyle(SOLID_FILL,RED);
floodfill(150,160,WHITE); //filling circle
setfillstyle(BKSLASH_FILL,BROWN);
floodfill(200,150,WHITE); //filling roof
getch();
closegraph();
}
Q3)//Flag
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd, &gm, "C:TCBGI");
rectangle(100,50,300,200); //outer rectangle
rectangle(100,100,300,150); //inner rectangle
setfillstyle(SOLID_FILL,LIGHTRED);
floodfill(102,52,WHITE); //top side filled
setfillstyle(SOLID_FILL,WHITE);
floodfill(102,102,WHITE); //middle side filled
setfillstyle(SOLID_FILL,GREEN);
floodfill(102,152,WHITE); //bottom side filled
setcolor(BLUE); //setting color for circle and lines
circle(200,125,25);
line(175,125,225,125);
line(200,100,200,150);
line(182,107,218,143);
line(218,107,182,143);
setcolor(BROWN);
line(100,200,100,400);
getch();
}
Q4) Ice cream cone
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:tcbgi");
line(320,450,270,200);
line(270,200,370,200);
line(370,200,320,450);
line(270,200,260,180);
line(260,180,380,180);
line(380,180,370,200);
ellipse(320,180,0,180,60,100); //ice-cream
circle(320,70,10); //cherry
setfillstyle(SLASH_FILL,BROWN);
floodfill(320,430,15); //filled bottom part of cone
setfillstyle(XHATCH_FILL,BROWN);
floodfill(320,198,15); //filled top part of cone
[3]
setfillstyle(SOLID_FILL,LIGHTMAGENTA);
floodfill(320,170,15); //filled ice-cream
setfillstyle(SOLID_FILL,RED);
floodfill(320,70,15); //filled cherry
getch();
}
Q5)//Smiley face
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd, &gm, "C:TCBGI");
ellipse(300,250,0,360,100,150); //drawing face
circle(250,200,20); //left eye
circle(350,200,20); //right eye
arc(200,200,60,275,20); //left ear
arc(400,200,265,480,20); //rigth ear
line(300,230,275,275);
line(300,230,325,275);
line(275,275,325,275); //drawing nose
setfillstyle(SOLID_FILL,BROWN);
floodfill(300,172,WHITE); //setting brown color for face
setfillstyle(SOLID_FILL,BLUE);
floodfill(350,200,WHITE);
setfillstyle(SOLID_FILL,BLUE);
floodfill(250,200,WHITE); //setting blue color for eyes
setfillstyle(SOLID_FILL,RED);
floodfill(300,235,WHITE); //setting red color for nose
setfillstyle(SOLID_FILL,GREEN);
floodfill(200,200,WHITE);
setfillstyle(SOLID_FILL,GREEN);
floodfill(400,200,WHITE); //setting green color for ears
setcolor(RED); //setting color for smile
arc(300,300,180,360,50); //drawing smile
setcolor(BLACK); //setting color for hair
line(300,100,300,170);
line(300,100,260,140);
line(300,100,340,140); //drawing hair
getch();
}
Q6)//Generation of sky
#include<graphics.h>
void main()
{
int gd=DETECT, gm;
int x, y, c;
initgraph(&gd, &gm, "C:TCBGI");
while(!kbhit()) //checks for currently available keystrokes
{
x=rand()%639;
y=rand()%479;
putpixel(x, y, rand()%14+1);
[4]
delay(15);
}
getch();
closegr,aph();
}
Q7)//Generation of Bubbles
#include<graphics.h>
void main()
{
int gd=DETECT, gm;
int x, y, c;
initgraph(&gd, &gm, "C:TCBGI");
while(!kbhit()) //checks for currently available keystrokes
{
x=rand()%639;
y=rand()%479;
c=rand()%14+1;
setcolor(c);
circle(x, y, rand()%10+10);
setfillstyle(SOLID_FILL, rand()%14+1);
floodfill(x, y, c);
delay(15);
}
getch();
closegr,aph();
}
Q8)//Concentric circles
#include<graphics.h>
void main()
{
//request auto detection
int gd=DETECT, gm;
int x, y, maxr;
//initializes the graphics system and put the system into graphics gm
initgraph(&gd, &gm, "C:TCBGI");
x=getmaxx()/2;
y=getmaxy()/2;
maxr= x<y ? x : y;
for(r=10; r<=maxr; r+=10)
{
setcolor(rand()%14+1);
circle(x, y, r);
delay(200); //suspends execution for interval (milliseconds)
}
//clean up
getch();
closegraph(); //shuts down the graphics system
}
Practical-02
[5]
Q1)//DDA line drawing algorithm
#include <graphics.h>
#include <math.h>
void main( )
{
float x1,y1,x2,y2;
float x,y,dx,dy,xinc,yinc,length;
int i;
int gd=DETECT,gm;
printf("Enter the value of x1 : ");
scanf("%f",&x1);
printf("Enter the value of y1 : ");
scanf("%f",&y1);
printf("Enter the value of x2 : ");
scanf("%f",&x2);
printf("Enter the value of y1 : ");
scanf("%f",&y2);
initgraph(&gd,&gm,"C:TCBGI");
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>=dy)
length=dx;
else
length=dy;
xinc=(x2-x1)/length;
yinc=(y2-y1)/length;
x=x1;
y=y1;
for(i=1;i<=length;i++)
{
putpixel((int)(x+0.5),(int)(y+0.5),15);
x=x+xinc;
y=y+yinc;
delay(100);
}
getch();
}
Q2)//Bresenham’s line drawing algorithm
#include <graphics.h>
#include <math.h>
int main( )
{
int x1,y1,x2,y2,gd=DETECT,gm;
int x,y,dx,dy,s1,s2;
int i,dp,temp,swap=0;
printf("Enter the value of x1 : ");
scanf("%d",&x1);
printf("Enter the value of y1 : ");
scanf("%d",&y1);
printf("Enter the value of x2 : ");
[6]
scanf("%d",&x2);
printf("Enter the value of y1 : ");
scanf("%d",&y2);
initgraph(&gd,&gm,"C:TCBGI");
x=x1;
y=y1;
putpixel(x,y,WHITE);
dx=abs(x2-x1);
dy=abs(y2-y1);
if(x2<x1)
s1=-1;
else if(x2>x1)
s1=1;
else
s1=0;
if(y2<y1)
s2=-1;
else if(y2>y1)
s2=1;
else
s2=0;
dp=2*dy-dx;
if(dy>dx)
{
temp=dx;
dx=dy;
dy=temp;
swap=1;
}
for(i=1;i<=dx;i++)
{
if(dp<0)
{
if(swap)
putpixel(x,y=y+s2,15);
else
putpixel(x=x+s1,y,15);
dp=dp+2*dy;
}
else
{
putpixel(x=x+s1,y=y+s2,15);
dp=dp+2*dy-2*dx;
}
delay(50);
}
getch();
}
[7]
Practical-03
Q1)//Midpoint Circle drawing algo
#include<graphics.h>
void main()
{
int gd=DETECT,gm,xc,yc,r,x,y,p;
clrscr();
printf("Enter the Xc=");
scanf("%d",&xc);
printf("Enter the Yc=");
scanf("%d",&yc);
printf("Enter the Radius=");
scanf("%d",&r);
initgraph(&gd,&gm,"C:TCBGI");
x=0;
y=r;
p=1-r;
do
{
putpixel(xc+x,yc+y,1);
putpixel(xc+x,yc-y,2);
putpixel(xc-x,yc+y,3);
putpixel(xc-x,yc-y,4);
putpixel(xc+y,yc+x,5);
putpixel(xc+y,yc-x,6);
putpixel(xc-y,yc+x,7);
putpixel(xc-y,yc-x,8);
delay(50);
if(p<0)
{
x=x+1;
p=p+(2*x)+1;
}
else
{
x=x+1;
y=y-1;
p=p+(2*x)-(2*y)+1;
}
}while(x<=y);
getch();
}
Q2)//Bresenham’x circle drawing algorithm
#include<graphics.h>
void main()
{
int gd=DETECT,gm,xc,yc,r,x,y,p;
clrscr();
printf("Enter the Xc=");
scanf("%d",&xc);
[8]
printf("Enter the Yc=");
scanf("%d",&yc);
printf("Enter the Radius=");
scanf("%d",&r);
initgraph(&gd,&gm,"C:TCBGI");
x=0;
y=r;
p=3-2*r;
do
{
putpixel(xc+x,yc+y,1);
putpixel(xc+x,yc-y,2);
putpixel(xc-x,yc+y,3);
putpixel(xc-x,yc-y,4);
putpixel(xc+y,yc+x,5);
putpixel(xc+y,yc-x,6);
putpixel(xc-y,yc+x,7);
putpixel(xc-y,yc-x,8);
delay(50);
if(p<0)
{
x=x+1;
p=p+(4*x)+6;
}
else
{
x=x+1;
y=y-1;
p=p+4*(x-y)+10;
}
}while(x<=y);
getch();
}
Practical -04
Q1)// To translate a polygon
#include<graphics.h>
#include<math.h>
void translate(int x1,int y1,int x2,int y2,int x3,int y3);
void main()
{
int gd=DETECT,gm;
int x1,y1,x2,y2,x3,y3;
printf("Enter first co-ordinates: ");
scanf("%d %d",&x1,&y1);
printf("Enter second co-ordinates: ");
scanf("%d %d",&x2,&y2);
printf("Enter third co-ordinates: ");
scanf("%d %d",&x3,&y3);
initgraph(&gd,&gm,"C:TCBGI");
translate(x1,y1,x2,y2,x3,y3);
getch();
}
[9]
void translate(int x1,int y1,int x2,int y2,int x3,int y3)
{
int tx,ty;
/*draw initial triangle*/
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
getch();
printf("Enter translation factorsn");
scanf("%d %d",&tx,&ty);
x1=x1+tx;
y1=y1+ty;
x2=x2+tx;
y2=y2+ty;
x3=x3+tx;
y3=y3+ty;
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
}
Q2//To scale a polygon
#include<graphics.h>
#include<math.h>
void scaling(int x1,int y1,int x2,int y2,int x3,int y3);
void main()
{
int gd=DETECT,gm;
int x1,y1,x2,y2,x3,y3;
printf("Enter first co-ordinates: ");
scanf("%d %d",&x1,&y1);
printf("Enter second co-ordinates: ");
scanf("%d %d",&x2,&y2);
printf("Enter third co-ordinates: ");
scanf("%d %d",&x3,&y3);
initgraph(&gd,&gm,"C:TCBGI");
scaling(x1,y1,x2,y2,x3,y3);
getch();
}
void scaling(int x1,int y1,int x2,int y2,int x3,int y3)
{
float sx,sy;
/*draw initial triangle*/
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
getch();
printf("Enter scaling factorsn");
scanf("%f %f",&sx,&sy);
x1=x1*sx;
y1=y1*sy;
x2=x2*sx;
y2=y2*sy;
x3=x3*sx;
[10]
y3=y3*sy;
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
}
Q3)// To reflect a polygon
#include<graphics.h>
#include<math.h>
void disp(int n,float c[][3])
{
float maxx,maxy;
int i;
maxx=getmaxx()/2;
maxy=getmaxy()/2;
i=0;
while(i<n-1)
{
line(maxx+c[i][0],maxy-c[i][1],maxx+c[i+1][0],maxy-c[i+1][1]);
i++;
}
i=n-1;
line(maxx+c[i][0],maxy-c[i][1],maxx+c[0][0],maxy-c[0][1]);
setcolor(GREEN);
line(0,maxy,maxx*2,maxy);
line(maxx,0,maxx,maxy*2);
setcolor(WHITE);
}
void mul(int n,float b[][3],float c[][3],float a[][3])
{
int i,j,k;
for(i=0;i<n;i++)
for(j=0;j<3;j++)
{
a[i][j]=0;
for(k=0;k<3;k++)
{
a[i][j] = a[i][j] + (c[i][k] * b[k][j]);
}
}
}
void reflection(int n,float c[][3])
{
float b[10][3],a[10][3];
int i=0,ch,j;
cleardevice();
do
{
printf("nt* * MENU * *");
printf("nt1) ABOUT X-AXIS");
printf("nt2) ABOUT Y-AXIS");
printf("nt3) ABOUT ORIGIN");
printf("nt4) EXIT");
printf("ntENTER YOUR CHOICE : ");
[11]
scanf("%d",&ch);
clrscr();
cleardevice();
disp(n,c);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
b[i][j]=0;
if(i==j)
b[i][j]=1;
}
switch(ch)
{
case 1:
b[1][1]=-1;
break;
case 2:
b[0][0]=-1;
break;
case 3:
b[0][0]=-1;
b[1][1]=-1;
break;
default:
printf("ntINVALID CHOICE ! ");
}
mul(n,b,c,a);
setcolor(RED);
disp(n,a);
}while(ch!=4);
}
void main()
{
int i,n,gd=DETECT,gm;
float c[10][3];
initgraph(&gd,&gm,"C:TCBGI");
printf("nEnter the number of vertices : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("nEnter the co-ordinates of the %d vertex :",i+1);
scanf("%f %f",&c[i][0],&c[i][1]);
c[i][2]=1;
}
setcolor(BLUE);
disp(n,c);
reflection(n,c);
getch();
closegraph();
}
[12]
Practical- 05
Q1)//To translate a circle
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
int tx,ty,color=0;
int x=100,y=100;
int key_code1=0,key_code2;
char key1,key2;
clrscr();
initgraph(&gd,&gm,"C:TCBGI");
setfillstyle(0,0);
outtextxy(50,469,"Use arrow keys translation");
bar3d(20,20,619,459,0,0);
circle(x,y,30);
do
{
key1=getch();
key_code1=(int)key1;
if(key_code1==27)//esc key
break;
if(key_code1==0)
{
setfillstyle(0,0);
setcolor(15);
outtextxy(50,469,"Press arrow keys for translation");
bar3d(20,20,619,459,0,0);
key2=getch();
key_code2=(int)key2;
if(key_code2==72) // up arrow
{
tx=0;
ty=-25;
x+=tx;
y+=ty;
color=2;
}
else if(key_code2==80) // down arrow
{
tx=0;
ty=25;
x+=tx;
y+=ty;
color=4;
}
if(key_code2==77) // right arrow
{
tx=25;
ty=0;
x+=tx;
y+=ty;
color=6;
[13]
}
if(key_code2==75) // left arrow
{
tx=-25;
ty=0;
x+=tx;
y+=ty;
color=8;
}
setfillstyle(0,0);
outtextxy(50,469,"Press arrow keys for translation, Esc
to exit");
bar3d(20,20,619,459,0,0);
setcolor(color);
circle(x,y,30);
}
} while(key_code1==0);
closegraph();
restorecrtgm();
}
Q2)// To scale a polygon about a reference point
#include<graphics.h>
typedef int matrix1[1][3];
typedef float matrix2[3][3];
void main()
{
int gd=DETECT,gm;
int tx,ty;
float sx,sy;
int res[10];
int array[10]={70,100,120,100,150,70,100,200,70,100};
void mul(matrix1,matrix2);
void multi(matrix2,matrix2);
matrix2 ttmat={{1,0,0}, {0,1,0}, {0,0,1} };
matrix2 t1={{1,0,0}, {0,1,0}, {0,0,1} };
matrix2 t2={{1,0,0}, {0,1,0}, {0,0,1} };
matrix2 t3,t4;
matrix1 a={{70,100,1}},b={{120,100,1}},c={{150,70,1}},d={{100,200,1}};
clrscr();
initgraph(&gd,&gm,"c:tcbgi");
outtextxy(30,30,"Scaling transformation function");
printf("Enter the scaling distance sx & sy:n");
scanf("%f %f",&sx,&sy);
outtextxy(20,50,"Before scaling:");
drawpoly(5,array);
getch();
ttmat[0][0]*=sx;
ttmat[1][1]*=sy;
tx=70;
ty=100;
t1[2][0]= -tx;
t1[2][1]= -ty;
t2[2][0]= tx;
[14]
t2[2][1]= ty;
multi(t1,ttmat);
multi(t1,t2);
mul(a,t1);
mul(b,t1);
mul(c,t1);
mul(d,t1);
res[0]=a[0][0];
res[1]=a[0][1];
res[2]=b[0][0];
res[3]=b[0][1];
res[4]=c[0][0];
res[5]=c[0][1];
res[6]=d[0][0];
res[7]=d[0][1];
res[8]=a[0][0];
res[9]=a[0][1];
outtextxy(200,200,"After scaling keeping Point A(70,100) fixed:");
drawpoly(5,res);
getch();
closegraph();
restorecrtgm();
}
void multi(matrix2 aa,matrix2 bb)
{
matrix2 cc;
int i,j,k;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cc[i][j]=0;
for(k=0;k<3;k++)
{
cc[i][j]=cc[i][j]+(aa[i][k]*bb[k][j]);
}
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
aa[i][j]=cc[i][j];
}
}
}
void mul(matrix1 aa,matrix2 bb)
{
matrix1 cc;
int i,j,k;
for(i=0;i<1;i++)
{
for(j=0;j<3;j++)
{
[15]
cc[i][j]=0;
for(k=0;k<3;k++)
{
cc[i][j]=cc[i][j]+(aa[i][k]*bb[k][j]);
}
}
}
for(i=0;i<1;i++)
{
for(j=0;j<3;j++)
{
aa[i][j]=cc[i][j];
}
}
}
Q3)//To rotate a polygon
#include<graphics.h>
#include<math.h>
typedef int matrix1[1][3];
typedef double matrix2[3][3];
void main()
{
int gd=DETECT,gm;
int tx,ty;
double A,theta;
int res[10];
int array[10]={350,180,400,80,450,80,500,180,350,180};
void mul(matrix1,matrix2);
void multi(matrix2,matrix2);
matrix2 ttmat={{1,0,0}, {0,1,0}, {0,0,1} };
matrix2 t1={{1,0,0}, {0,1,0}, {0,0,1} };
matrix2 t2={{1,0,0}, {0,1,0}, {0,0,1} };
matrix1 a={{350,180,1}},b={{400,80,1}},c={{450,80,1}},d={{500,180,1}};
initgraph(&gd,&gm,"C:TCBGI");
outtextxy(30,30,"Rotation transformation function");
printf("Enter the rotation angle:n");
scanf("%lf",&A);
outtextxy(20,50,"Before rotation:");
drawpoly(5,array);
getch();
theta=(3.14/180)*A;
ttmat[0][0]=cos(theta);
ttmat[0][1]=-sin(theta);
ttmat[1][0]=sin(theta);
ttmat[1][1]=cos(theta);
tx=350;
ty=180;
t1[2][0]=-tx;
t1[2][1]=-ty;
t2[2][0]=tx;
t2[2][1]=ty;
multi(t1,ttmat);
multi(t1,t2);
[16]
mul(a,t1);
mul(b,t1);
mul(c,t1);
mul(d,t1);
res[0]=a[0][0];
res[1]=a[0][1];
res[2]=b[0][0];
res[3]=b[0][1];
res[4]=c[0][0];
res[5]=c[0][1];
res[6]=d[0][0];
res[7]=d[0][1];
res[8]=a[0][0];
res[9]=a[0][1];
outtextxy(100,100,"After rotation:");
drawpoly(5,res);
getch();
closegraph();
restorecrtgm();
}
void multi(matrix2 aa,matrix2 bb)
{
matrix2 cc;
int i,j,k;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cc[i][j]=0;
for(k=0;k<3;k++)
{
cc[i][j]=cc[i][j]+(aa[i][k]*bb[k][j]);
}
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
aa[i][j]=cc[i][j];
}
}
}
void mul(matrix1 aa,matrix2 bb)
{
matrix1 cc;
int i,j,k;
for(i=0;i<1;i++)
{
for(j=0;j<3;j++)
{
cc[i][j]=0;
for(k=0;k<3;k++)
{
[17]
cc[i][j]=cc[i][j]+(aa[i][k]*bb[k][j]);
}
}
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
aa[i][j]=cc[i][j];
}
}
}
Practical -06
Q1)// Cohen sutherland line clipping algorithm
#include<graphics.h>
void main()
{
int gd=DETECT, gm;
float i,xmin,ymin, xmax,ymax,x1,y1,x2,y2,m;
float code1[4]={0,0,0,0},code2[4]={0,0,0,0};
clrscr();
initgraph(&gd,&gm,"c:tcbin");
printf("ntEnter the top-left coordinate of viewport: ");
scanf("%f %f",&xmin,&ymin);
printf("ntEnter the bottom-right coordinate of viewport: ");
scanf("%f %f",&xmax,&ymax);
printf("nEnter the coordinates for starting point of line: ");
scanf("%f %f",&x1,&y1);
printf("nEnter the coordinates for ending point of line: ");
scanf("%f %f",&x2,&y2);
rectangle(xmin,ymin,xmax,ymax);
line(x1,y1,x2,y2);
m=(y2-y1)/(x2-x1);
if(x1 <xmin)
start[0]=1;
if(x1 >xmax)
start[1]=1;
if(y1 >ymax)
start[2]=1;
if(y1 <ymin)
start[3]=1;
if(x2 <xmin)
end[0]=1;
if(x2 >xmax)
end[1]=1;
if(y2 >ymax)
end[2]=1;
if(y2 <ymin)
end[3]=1;
if((code1[0]==0)&&( code1[1]==0)&&( code1[2]==0)&&( code1[3]==0)&&(
code2[0]==0)&&( code2[1]==0)&&( code2[2]==0)&&( code2[3]==0))
{
[18]
cleardevice();
printf("nttThe line is totally visiblenttand not a clipping
candidate");
rectangle(xmin,ymin,xmax,ymax);
line(x1,y1,x2,y2);
getch();
}
else if(((code1[0] && code2[0])==0) && ((code1[1] && code2[1])==0) &&
((code1[2] && code2[2])==0) && ((code1[3] && code2[3])==0))
{
cleardevice();
printf("nttLine is partially visible");
rectangle(xmin,ymin,xmax,ymax);
if(x1<xmin)
{
y1=y1+m*(xmin-x1);
x1=xmin;
}
If(x2<xmin)
{
y2=y2+m*(xmin-x2);
x2=xmin;
}
If(x1>xmax)
{
y1=y1+m*(xmax-x1);
x1=xmax;
}
If(x2>xmax)
{
y2=y2+m*(xmax-x2);
x2=xmax;
}
if(y1<ymin)
{
x1=x1+(ymin-y1)/m;
y1=ymin;
}
If(y2<ymin)
{
x2=x2+(ymin-y2)/m;
y2=ymin;
}
If(y1>ymax)
{
x1=x1+(ymax-y1)/m;
y1=ymax;
}
If(y2>ymax)
{
x2=x2+(ymax-y2)/m;
y2=ymax;
}
line(x1,y1,x2,y2);
[19]
getch();
}
else
{
clrscr();
cleardevice();
printf("nLine is invisible");
rectangle(xmin,ymin,xmax,ymax);
}
getch();
}
Q2)Aim: Text Clipping
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
int xmin,ymin,xmax,ymax;
int x1,y1,x2,y2;
printf(“Enter coordinates of window: “);
scanf(“%d %d %d %d”,&xmin,&ymin,&xmax,&ymax);
printf(“Enter the location of first text: “);
scanf(“%d %d”,&x1,&y1);
printf(“Enter the location of second text: “);
scanf(“%d %d”,&x2,&y2);
initgraph(&gd,&gm,"C:TCBGI");
rectangle(xmin,ymin,xmax,ymax); //window
outtextxy(x1,y1,"INDIA");
rectangle(x1-1,y1-1,x1+50,y1+10);
outtextxy(x2,y2,"INDIA");
rectangle(x2-1,y2-1,x2+50,y2+10);
getch();
cleardevice();
outtextxy(20,20,"after clipping");
rectangle(xmin,ymin,xmax,ymax); //window
if((x1-1>xmin && x1-1<xmax) && (y1-1>ymin && y1-1<ymax) && (x1+50>xmin
&& x1+50<xmax) && (y1+10>ymin && y1+10<ymax))
{
outtextxy(x1,y1,"INDIA");
rectangle(x1-1,y1-1,x1+50,y1+10);
}
if((x2-1>xmin && x2-1<xmax) && (y2-1>ymin && y2-1<ymax) && (x2+50>xmin
&& x2+50<xmax) && (y2+10>ymin && y2+10<ymax))
{
outtextxy(x2,y2,"INDIA");
rectangle(x2-1,y2-1,x2+50,y2+10);
}
getch();
}
[20]
Practical -7
Q1) Aim: Character Generation
#include<graphics.h>
void main()
{
int gd=DETECT,gm,c,i,j;
int a[20][20]={{0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0},
{0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0},
{0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
{1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
{1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,0},
{1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0},
{0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0},
{0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0},
{0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0}};
initgraph(&gd,&gm,"C:TCBGI");
for(i=0;i<=19;i++)
{
for(j=0;j<=19;j++)
{
if(a[i][j]==1)
putpixel(100+j,200+i,15);
}
}
getch();
}
Practical -8
Q1) Aim: To draw a moving Car
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
int x=0;
int start=0,end=90;
int rad=30;
initgraph(&gd,&gm,"C:TCBGI");
while(!kbhit())
{
cleardevice();
start=start-4;
end=end-4;
if(x<640)
x=x+1 ;
else
x=0;
setfillstyle(SOLID_FILL,BLUE);
pieslice(x,240,start,end,rad);
pieslice(x,240,start-180,end-180,rad);
circle(x,240,rad);
[21]
setfillstyle(SOLID_FILL,BLUE);
pieslice(x+120,240,start,end,rad);
pieslice(x+120,240,start-180,end-180,rad);
circle(x+120,240,rad);
line(x+rad,240,x-rad+120,240);
line(x-rad,240,x-rad-45,240);
line(x+rad+120,240,x+rad+210,240);
line(x-rad-45,240,x-60,180);
line(x-60,180,x-10,180);
line(x-10,180,x+rad,150);
line(x+rad,150,x+130,150);
line(x+130,150,x+150+10,180);
line(x+160,180,x+210,180);
line(x+210,180,x+240,240);
delay(150);
}
getch();
}
Q2) Aim: To draw a moving fish
#include<graphics.h>
int main()
{
int gd=DETECT,gm;
int x=0;
initgraph(&gd,&gm,"C:TCBGI");
while(!kbhit())
{
cleardevice();
if(x<640)
x=x+10;
else
x=0;
setfillstyle(EMPTY_FILL,BLACK);
arc(x,180,30,150,50);
arc(x,130,210,330,50);
line(x-42,155,x-80,130);
line(x-42,155,x-80,180);
line(x-80,180,x-80,130);
circle(x+20,150,5);
circle(x+60,155,7);
circle(x+63,130,5);
circle(x+66,110,3);
arc(x,300,30,150,50);
arc(x,253,210,330,50);
delay(100);
}
getch();
}
Q3) Aim: To draw a flying kite
#include<graphics.h>
int main()
{
[22]
int gd=DETECT,gm;
int y=480,x=0;
initgraph(&gd,&gm,"C:TCBGI");
while(!kbhit())
{
cleardevice();
if(x<640)
x=x+4;
else
x=0;
if(y>0)
y=y-4;
else
y=480;
line(x,y,x-40,y-40);
line(x-40,y-40,x,y-80);
line(x,y-80,x+40,y-40);
line(x+40,y-40,x,y);
line(x,y,x-7,y+10);
line(x-7,y+10,x+8,y+10);
line(x,y,x+7,y+10);
line(x,y+10,x,y+50);
line(x-40,y-40,x+40,y-40);
line(x,y-80,x,y);
line(x,y-40,640,480);
delay(100); }
}
getch();
}

More Related Content

What's hot

Playing with camera preview buffers on BlackBerry 10
Playing with camera preview buffers on BlackBerry 10Playing with camera preview buffers on BlackBerry 10
Playing with camera preview buffers on BlackBerry 10Raimon Ràfols
 
Computer graphics File for Engineers
Computer graphics File for EngineersComputer graphics File for Engineers
Computer graphics File for Engineersvarun arora
 
Hypercritical C++ Code Review
Hypercritical C++ Code ReviewHypercritical C++ Code Review
Hypercritical C++ Code ReviewAndrey Karpov
 
Junaid program assignment
Junaid program assignmentJunaid program assignment
Junaid program assignmentJunaid Ahmed
 
C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscationguest9006ab
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202Mahmoud Samir Fayed
 
Program Language - Fall 2013
Program Language - Fall 2013 Program Language - Fall 2013
Program Language - Fall 2013 Yun-Yan Chi
 
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -Wataru Kani
 
Let’s talk about microbenchmarking
Let’s talk about microbenchmarkingLet’s talk about microbenchmarking
Let’s talk about microbenchmarkingAndrey Akinshin
 
Tabela completa de derivadas e integrais
Tabela completa de derivadas e integraisTabela completa de derivadas e integrais
Tabela completa de derivadas e integraisDiego Rodrigues Vaz
 

What's hot (16)

Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Playing with camera preview buffers on BlackBerry 10
Playing with camera preview buffers on BlackBerry 10Playing with camera preview buffers on BlackBerry 10
Playing with camera preview buffers on BlackBerry 10
 
Computer graphics File for Engineers
Computer graphics File for EngineersComputer graphics File for Engineers
Computer graphics File for Engineers
 
Vcs9
Vcs9Vcs9
Vcs9
 
Hypercritical C++ Code Review
Hypercritical C++ Code ReviewHypercritical C++ Code Review
Hypercritical C++ Code Review
 
Myraytracer
MyraytracerMyraytracer
Myraytracer
 
Junaid program assignment
Junaid program assignmentJunaid program assignment
Junaid program assignment
 
C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscation
 
Css grid-layout
Css grid-layoutCss grid-layout
Css grid-layout
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202
 
Program Language - Fall 2013
Program Language - Fall 2013 Program Language - Fall 2013
Program Language - Fall 2013
 
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
 
Dpsm simu.cpp
Dpsm simu.cppDpsm simu.cpp
Dpsm simu.cpp
 
Let’s talk about microbenchmarking
Let’s talk about microbenchmarkingLet’s talk about microbenchmarking
Let’s talk about microbenchmarking
 
Tabela completa de derivadas e integrais
Tabela completa de derivadas e integraisTabela completa de derivadas e integrais
Tabela completa de derivadas e integrais
 
Prelude to halide_public
Prelude to halide_publicPrelude to halide_public
Prelude to halide_public
 

Similar to Graphics programs

bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfbfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfshehabhamad_90
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignmentAbdullah Al Shiam
 
All VLSI programs
All VLSI programsAll VLSI programs
All VLSI programsGouthaman V
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfcontact32
 
Computer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportComputer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportBijoy679
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2Koshy Geoji
 
C prpgram code of design google web page
C prpgram code of design google web pageC prpgram code of design google web page
C prpgram code of design google web pageKapil Pandit
 
square.cpp Open
 square.cpp Open square.cpp Open
square.cpp OpenMikeEly930
 
11103500 61599 sagar (1)
11103500 61599 sagar (1)11103500 61599 sagar (1)
11103500 61599 sagar (1)Rounit Roy
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graphkinan keshkeh
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8alish sha
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8alish sha
 

Similar to Graphics programs (20)

bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfbfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
 
All VLSI programs
All VLSI programsAll VLSI programs
All VLSI programs
 
Clock For My
Clock For MyClock For My
Clock For My
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdf
 
662305 LAB13
662305 LAB13662305 LAB13
662305 LAB13
 
Computer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportComputer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab report
 
Rkf
RkfRkf
Rkf
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Drawing Figures
Drawing FiguresDrawing Figures
Drawing Figures
 
Vcs23
Vcs23Vcs23
Vcs23
 
Vcs16
Vcs16Vcs16
Vcs16
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
C prpgram code of design google web page
C prpgram code of design google web pageC prpgram code of design google web page
C prpgram code of design google web page
 
square.cpp Open
 square.cpp Open square.cpp Open
square.cpp Open
 
20DCE096_dlp_prac4.pdf
20DCE096_dlp_prac4.pdf20DCE096_dlp_prac4.pdf
20DCE096_dlp_prac4.pdf
 
11103500 61599 sagar (1)
11103500 61599 sagar (1)11103500 61599 sagar (1)
11103500 61599 sagar (1)
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
 

Recently uploaded

(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?Watsoo Telematics
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutionsmonugehlot87
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 

Recently uploaded (20)

(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutions
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 

Graphics programs

  • 1. [1] Practical-01 Q1) Drawing star #include<graphics.h> void main() { int gd=DETECT,gm; initgraph(&gd,&gm,"c:tcbgi"); line(320,100,220,300); line(220,300,420,300); line(420,300,320,100); // straight triangle line(320,350,220,150); line(220,150,420,150); line(420,150,320,350); // reverse triangle setfillstyle(SOLID_FILL,1); floodfill(320,102,15); //top triangle setfillstyle(SOLID_FILL,2); floodfill(225,152,15); //top left setfillstyle(SOLID_FILL,3); floodfill(225,298,15); //bottom left setfillstyle(SOLID_FILL,4); floodfill(320,348,15); //bottom setfillstyle(SOLID_FILL,5); floodfill(415,298,15); //bottom right setfillstyle(SOLID_FILL,6); floodfill(415,152,15); //top right setfillstyle(SOLID_FILL,7); floodfill(320,200,15); //middle getch(); } Q2)//House #include<graphics.h> void main() { int gd=DETECT,gm; initgraph(&gd, &gm, "C:TCBGI"); rectangle(100,200,400,400); //big wall line(150,100,100,200); //left side of triangle line(150,100,200,200); //right side of triangle line(150,100,350,100); //top side of roof line(200,200,400,200); //bottom side of roof line(350,100,400,200); //right side of roof line(200,200,200,400); //dividing wall into two parts circle(150,160,20); //drawing circle within triangle rectangle(120,250,180,400); //door rectangle(225,225,375,300); //window setfillstyle(SOLID_FILL,LIGHTRED); floodfill(102,202,WHITE); //filling first wall setfillstyle(SOLID_FILL,BLUE); floodfill(202,202,WHITE); //filling second wall setfillstyle(SOLID_FILL,CYAN); floodfill(122,252,WHITE); //filling door setfillstyle(XHATCH_FILL,GREEN);
  • 2. [2] floodfill(252,252,WHITE); //filling window setfillstyle(SOLID_FILL,MAGENTA); floodfill(150,102,WHITE); //filling triangle setfillstyle(SOLID_FILL,RED); floodfill(150,160,WHITE); //filling circle setfillstyle(BKSLASH_FILL,BROWN); floodfill(200,150,WHITE); //filling roof getch(); closegraph(); } Q3)//Flag #include<graphics.h> void main() { int gd=DETECT,gm; initgraph(&gd, &gm, "C:TCBGI"); rectangle(100,50,300,200); //outer rectangle rectangle(100,100,300,150); //inner rectangle setfillstyle(SOLID_FILL,LIGHTRED); floodfill(102,52,WHITE); //top side filled setfillstyle(SOLID_FILL,WHITE); floodfill(102,102,WHITE); //middle side filled setfillstyle(SOLID_FILL,GREEN); floodfill(102,152,WHITE); //bottom side filled setcolor(BLUE); //setting color for circle and lines circle(200,125,25); line(175,125,225,125); line(200,100,200,150); line(182,107,218,143); line(218,107,182,143); setcolor(BROWN); line(100,200,100,400); getch(); } Q4) Ice cream cone #include<graphics.h> void main() { int gd=DETECT,gm; initgraph(&gd,&gm,"c:tcbgi"); line(320,450,270,200); line(270,200,370,200); line(370,200,320,450); line(270,200,260,180); line(260,180,380,180); line(380,180,370,200); ellipse(320,180,0,180,60,100); //ice-cream circle(320,70,10); //cherry setfillstyle(SLASH_FILL,BROWN); floodfill(320,430,15); //filled bottom part of cone setfillstyle(XHATCH_FILL,BROWN); floodfill(320,198,15); //filled top part of cone
  • 3. [3] setfillstyle(SOLID_FILL,LIGHTMAGENTA); floodfill(320,170,15); //filled ice-cream setfillstyle(SOLID_FILL,RED); floodfill(320,70,15); //filled cherry getch(); } Q5)//Smiley face #include<graphics.h> void main() { int gd=DETECT,gm; initgraph(&gd, &gm, "C:TCBGI"); ellipse(300,250,0,360,100,150); //drawing face circle(250,200,20); //left eye circle(350,200,20); //right eye arc(200,200,60,275,20); //left ear arc(400,200,265,480,20); //rigth ear line(300,230,275,275); line(300,230,325,275); line(275,275,325,275); //drawing nose setfillstyle(SOLID_FILL,BROWN); floodfill(300,172,WHITE); //setting brown color for face setfillstyle(SOLID_FILL,BLUE); floodfill(350,200,WHITE); setfillstyle(SOLID_FILL,BLUE); floodfill(250,200,WHITE); //setting blue color for eyes setfillstyle(SOLID_FILL,RED); floodfill(300,235,WHITE); //setting red color for nose setfillstyle(SOLID_FILL,GREEN); floodfill(200,200,WHITE); setfillstyle(SOLID_FILL,GREEN); floodfill(400,200,WHITE); //setting green color for ears setcolor(RED); //setting color for smile arc(300,300,180,360,50); //drawing smile setcolor(BLACK); //setting color for hair line(300,100,300,170); line(300,100,260,140); line(300,100,340,140); //drawing hair getch(); } Q6)//Generation of sky #include<graphics.h> void main() { int gd=DETECT, gm; int x, y, c; initgraph(&gd, &gm, "C:TCBGI"); while(!kbhit()) //checks for currently available keystrokes { x=rand()%639; y=rand()%479; putpixel(x, y, rand()%14+1);
  • 4. [4] delay(15); } getch(); closegr,aph(); } Q7)//Generation of Bubbles #include<graphics.h> void main() { int gd=DETECT, gm; int x, y, c; initgraph(&gd, &gm, "C:TCBGI"); while(!kbhit()) //checks for currently available keystrokes { x=rand()%639; y=rand()%479; c=rand()%14+1; setcolor(c); circle(x, y, rand()%10+10); setfillstyle(SOLID_FILL, rand()%14+1); floodfill(x, y, c); delay(15); } getch(); closegr,aph(); } Q8)//Concentric circles #include<graphics.h> void main() { //request auto detection int gd=DETECT, gm; int x, y, maxr; //initializes the graphics system and put the system into graphics gm initgraph(&gd, &gm, "C:TCBGI"); x=getmaxx()/2; y=getmaxy()/2; maxr= x<y ? x : y; for(r=10; r<=maxr; r+=10) { setcolor(rand()%14+1); circle(x, y, r); delay(200); //suspends execution for interval (milliseconds) } //clean up getch(); closegraph(); //shuts down the graphics system } Practical-02
  • 5. [5] Q1)//DDA line drawing algorithm #include <graphics.h> #include <math.h> void main( ) { float x1,y1,x2,y2; float x,y,dx,dy,xinc,yinc,length; int i; int gd=DETECT,gm; printf("Enter the value of x1 : "); scanf("%f",&x1); printf("Enter the value of y1 : "); scanf("%f",&y1); printf("Enter the value of x2 : "); scanf("%f",&x2); printf("Enter the value of y1 : "); scanf("%f",&y2); initgraph(&gd,&gm,"C:TCBGI"); dx=abs(x2-x1); dy=abs(y2-y1); if(dx>=dy) length=dx; else length=dy; xinc=(x2-x1)/length; yinc=(y2-y1)/length; x=x1; y=y1; for(i=1;i<=length;i++) { putpixel((int)(x+0.5),(int)(y+0.5),15); x=x+xinc; y=y+yinc; delay(100); } getch(); } Q2)//Bresenham’s line drawing algorithm #include <graphics.h> #include <math.h> int main( ) { int x1,y1,x2,y2,gd=DETECT,gm; int x,y,dx,dy,s1,s2; int i,dp,temp,swap=0; printf("Enter the value of x1 : "); scanf("%d",&x1); printf("Enter the value of y1 : "); scanf("%d",&y1); printf("Enter the value of x2 : ");
  • 6. [6] scanf("%d",&x2); printf("Enter the value of y1 : "); scanf("%d",&y2); initgraph(&gd,&gm,"C:TCBGI"); x=x1; y=y1; putpixel(x,y,WHITE); dx=abs(x2-x1); dy=abs(y2-y1); if(x2<x1) s1=-1; else if(x2>x1) s1=1; else s1=0; if(y2<y1) s2=-1; else if(y2>y1) s2=1; else s2=0; dp=2*dy-dx; if(dy>dx) { temp=dx; dx=dy; dy=temp; swap=1; } for(i=1;i<=dx;i++) { if(dp<0) { if(swap) putpixel(x,y=y+s2,15); else putpixel(x=x+s1,y,15); dp=dp+2*dy; } else { putpixel(x=x+s1,y=y+s2,15); dp=dp+2*dy-2*dx; } delay(50); } getch(); }
  • 7. [7] Practical-03 Q1)//Midpoint Circle drawing algo #include<graphics.h> void main() { int gd=DETECT,gm,xc,yc,r,x,y,p; clrscr(); printf("Enter the Xc="); scanf("%d",&xc); printf("Enter the Yc="); scanf("%d",&yc); printf("Enter the Radius="); scanf("%d",&r); initgraph(&gd,&gm,"C:TCBGI"); x=0; y=r; p=1-r; do { putpixel(xc+x,yc+y,1); putpixel(xc+x,yc-y,2); putpixel(xc-x,yc+y,3); putpixel(xc-x,yc-y,4); putpixel(xc+y,yc+x,5); putpixel(xc+y,yc-x,6); putpixel(xc-y,yc+x,7); putpixel(xc-y,yc-x,8); delay(50); if(p<0) { x=x+1; p=p+(2*x)+1; } else { x=x+1; y=y-1; p=p+(2*x)-(2*y)+1; } }while(x<=y); getch(); } Q2)//Bresenham’x circle drawing algorithm #include<graphics.h> void main() { int gd=DETECT,gm,xc,yc,r,x,y,p; clrscr(); printf("Enter the Xc="); scanf("%d",&xc);
  • 8. [8] printf("Enter the Yc="); scanf("%d",&yc); printf("Enter the Radius="); scanf("%d",&r); initgraph(&gd,&gm,"C:TCBGI"); x=0; y=r; p=3-2*r; do { putpixel(xc+x,yc+y,1); putpixel(xc+x,yc-y,2); putpixel(xc-x,yc+y,3); putpixel(xc-x,yc-y,4); putpixel(xc+y,yc+x,5); putpixel(xc+y,yc-x,6); putpixel(xc-y,yc+x,7); putpixel(xc-y,yc-x,8); delay(50); if(p<0) { x=x+1; p=p+(4*x)+6; } else { x=x+1; y=y-1; p=p+4*(x-y)+10; } }while(x<=y); getch(); } Practical -04 Q1)// To translate a polygon #include<graphics.h> #include<math.h> void translate(int x1,int y1,int x2,int y2,int x3,int y3); void main() { int gd=DETECT,gm; int x1,y1,x2,y2,x3,y3; printf("Enter first co-ordinates: "); scanf("%d %d",&x1,&y1); printf("Enter second co-ordinates: "); scanf("%d %d",&x2,&y2); printf("Enter third co-ordinates: "); scanf("%d %d",&x3,&y3); initgraph(&gd,&gm,"C:TCBGI"); translate(x1,y1,x2,y2,x3,y3); getch(); }
  • 9. [9] void translate(int x1,int y1,int x2,int y2,int x3,int y3) { int tx,ty; /*draw initial triangle*/ line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); getch(); printf("Enter translation factorsn"); scanf("%d %d",&tx,&ty); x1=x1+tx; y1=y1+ty; x2=x2+tx; y2=y2+ty; x3=x3+tx; y3=y3+ty; line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); } Q2//To scale a polygon #include<graphics.h> #include<math.h> void scaling(int x1,int y1,int x2,int y2,int x3,int y3); void main() { int gd=DETECT,gm; int x1,y1,x2,y2,x3,y3; printf("Enter first co-ordinates: "); scanf("%d %d",&x1,&y1); printf("Enter second co-ordinates: "); scanf("%d %d",&x2,&y2); printf("Enter third co-ordinates: "); scanf("%d %d",&x3,&y3); initgraph(&gd,&gm,"C:TCBGI"); scaling(x1,y1,x2,y2,x3,y3); getch(); } void scaling(int x1,int y1,int x2,int y2,int x3,int y3) { float sx,sy; /*draw initial triangle*/ line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); getch(); printf("Enter scaling factorsn"); scanf("%f %f",&sx,&sy); x1=x1*sx; y1=y1*sy; x2=x2*sx; y2=y2*sy; x3=x3*sx;
  • 10. [10] y3=y3*sy; line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); } Q3)// To reflect a polygon #include<graphics.h> #include<math.h> void disp(int n,float c[][3]) { float maxx,maxy; int i; maxx=getmaxx()/2; maxy=getmaxy()/2; i=0; while(i<n-1) { line(maxx+c[i][0],maxy-c[i][1],maxx+c[i+1][0],maxy-c[i+1][1]); i++; } i=n-1; line(maxx+c[i][0],maxy-c[i][1],maxx+c[0][0],maxy-c[0][1]); setcolor(GREEN); line(0,maxy,maxx*2,maxy); line(maxx,0,maxx,maxy*2); setcolor(WHITE); } void mul(int n,float b[][3],float c[][3],float a[][3]) { int i,j,k; for(i=0;i<n;i++) for(j=0;j<3;j++) { a[i][j]=0; for(k=0;k<3;k++) { a[i][j] = a[i][j] + (c[i][k] * b[k][j]); } } } void reflection(int n,float c[][3]) { float b[10][3],a[10][3]; int i=0,ch,j; cleardevice(); do { printf("nt* * MENU * *"); printf("nt1) ABOUT X-AXIS"); printf("nt2) ABOUT Y-AXIS"); printf("nt3) ABOUT ORIGIN"); printf("nt4) EXIT"); printf("ntENTER YOUR CHOICE : ");
  • 11. [11] scanf("%d",&ch); clrscr(); cleardevice(); disp(n,c); for(i=0;i<3;i++) for(j=0;j<3;j++) { b[i][j]=0; if(i==j) b[i][j]=1; } switch(ch) { case 1: b[1][1]=-1; break; case 2: b[0][0]=-1; break; case 3: b[0][0]=-1; b[1][1]=-1; break; default: printf("ntINVALID CHOICE ! "); } mul(n,b,c,a); setcolor(RED); disp(n,a); }while(ch!=4); } void main() { int i,n,gd=DETECT,gm; float c[10][3]; initgraph(&gd,&gm,"C:TCBGI"); printf("nEnter the number of vertices : "); scanf("%d",&n); for(i=0;i<n;i++) { printf("nEnter the co-ordinates of the %d vertex :",i+1); scanf("%f %f",&c[i][0],&c[i][1]); c[i][2]=1; } setcolor(BLUE); disp(n,c); reflection(n,c); getch(); closegraph(); }
  • 12. [12] Practical- 05 Q1)//To translate a circle #include<graphics.h> void main() { int gd=DETECT,gm; int tx,ty,color=0; int x=100,y=100; int key_code1=0,key_code2; char key1,key2; clrscr(); initgraph(&gd,&gm,"C:TCBGI"); setfillstyle(0,0); outtextxy(50,469,"Use arrow keys translation"); bar3d(20,20,619,459,0,0); circle(x,y,30); do { key1=getch(); key_code1=(int)key1; if(key_code1==27)//esc key break; if(key_code1==0) { setfillstyle(0,0); setcolor(15); outtextxy(50,469,"Press arrow keys for translation"); bar3d(20,20,619,459,0,0); key2=getch(); key_code2=(int)key2; if(key_code2==72) // up arrow { tx=0; ty=-25; x+=tx; y+=ty; color=2; } else if(key_code2==80) // down arrow { tx=0; ty=25; x+=tx; y+=ty; color=4; } if(key_code2==77) // right arrow { tx=25; ty=0; x+=tx; y+=ty; color=6;
  • 13. [13] } if(key_code2==75) // left arrow { tx=-25; ty=0; x+=tx; y+=ty; color=8; } setfillstyle(0,0); outtextxy(50,469,"Press arrow keys for translation, Esc to exit"); bar3d(20,20,619,459,0,0); setcolor(color); circle(x,y,30); } } while(key_code1==0); closegraph(); restorecrtgm(); } Q2)// To scale a polygon about a reference point #include<graphics.h> typedef int matrix1[1][3]; typedef float matrix2[3][3]; void main() { int gd=DETECT,gm; int tx,ty; float sx,sy; int res[10]; int array[10]={70,100,120,100,150,70,100,200,70,100}; void mul(matrix1,matrix2); void multi(matrix2,matrix2); matrix2 ttmat={{1,0,0}, {0,1,0}, {0,0,1} }; matrix2 t1={{1,0,0}, {0,1,0}, {0,0,1} }; matrix2 t2={{1,0,0}, {0,1,0}, {0,0,1} }; matrix2 t3,t4; matrix1 a={{70,100,1}},b={{120,100,1}},c={{150,70,1}},d={{100,200,1}}; clrscr(); initgraph(&gd,&gm,"c:tcbgi"); outtextxy(30,30,"Scaling transformation function"); printf("Enter the scaling distance sx & sy:n"); scanf("%f %f",&sx,&sy); outtextxy(20,50,"Before scaling:"); drawpoly(5,array); getch(); ttmat[0][0]*=sx; ttmat[1][1]*=sy; tx=70; ty=100; t1[2][0]= -tx; t1[2][1]= -ty; t2[2][0]= tx;
  • 14. [14] t2[2][1]= ty; multi(t1,ttmat); multi(t1,t2); mul(a,t1); mul(b,t1); mul(c,t1); mul(d,t1); res[0]=a[0][0]; res[1]=a[0][1]; res[2]=b[0][0]; res[3]=b[0][1]; res[4]=c[0][0]; res[5]=c[0][1]; res[6]=d[0][0]; res[7]=d[0][1]; res[8]=a[0][0]; res[9]=a[0][1]; outtextxy(200,200,"After scaling keeping Point A(70,100) fixed:"); drawpoly(5,res); getch(); closegraph(); restorecrtgm(); } void multi(matrix2 aa,matrix2 bb) { matrix2 cc; int i,j,k; for(i=0;i<3;i++) { for(j=0;j<3;j++) { cc[i][j]=0; for(k=0;k<3;k++) { cc[i][j]=cc[i][j]+(aa[i][k]*bb[k][j]); } } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { aa[i][j]=cc[i][j]; } } } void mul(matrix1 aa,matrix2 bb) { matrix1 cc; int i,j,k; for(i=0;i<1;i++) { for(j=0;j<3;j++) {
  • 15. [15] cc[i][j]=0; for(k=0;k<3;k++) { cc[i][j]=cc[i][j]+(aa[i][k]*bb[k][j]); } } } for(i=0;i<1;i++) { for(j=0;j<3;j++) { aa[i][j]=cc[i][j]; } } } Q3)//To rotate a polygon #include<graphics.h> #include<math.h> typedef int matrix1[1][3]; typedef double matrix2[3][3]; void main() { int gd=DETECT,gm; int tx,ty; double A,theta; int res[10]; int array[10]={350,180,400,80,450,80,500,180,350,180}; void mul(matrix1,matrix2); void multi(matrix2,matrix2); matrix2 ttmat={{1,0,0}, {0,1,0}, {0,0,1} }; matrix2 t1={{1,0,0}, {0,1,0}, {0,0,1} }; matrix2 t2={{1,0,0}, {0,1,0}, {0,0,1} }; matrix1 a={{350,180,1}},b={{400,80,1}},c={{450,80,1}},d={{500,180,1}}; initgraph(&gd,&gm,"C:TCBGI"); outtextxy(30,30,"Rotation transformation function"); printf("Enter the rotation angle:n"); scanf("%lf",&A); outtextxy(20,50,"Before rotation:"); drawpoly(5,array); getch(); theta=(3.14/180)*A; ttmat[0][0]=cos(theta); ttmat[0][1]=-sin(theta); ttmat[1][0]=sin(theta); ttmat[1][1]=cos(theta); tx=350; ty=180; t1[2][0]=-tx; t1[2][1]=-ty; t2[2][0]=tx; t2[2][1]=ty; multi(t1,ttmat); multi(t1,t2);
  • 16. [16] mul(a,t1); mul(b,t1); mul(c,t1); mul(d,t1); res[0]=a[0][0]; res[1]=a[0][1]; res[2]=b[0][0]; res[3]=b[0][1]; res[4]=c[0][0]; res[5]=c[0][1]; res[6]=d[0][0]; res[7]=d[0][1]; res[8]=a[0][0]; res[9]=a[0][1]; outtextxy(100,100,"After rotation:"); drawpoly(5,res); getch(); closegraph(); restorecrtgm(); } void multi(matrix2 aa,matrix2 bb) { matrix2 cc; int i,j,k; for(i=0;i<3;i++) { for(j=0;j<3;j++) { cc[i][j]=0; for(k=0;k<3;k++) { cc[i][j]=cc[i][j]+(aa[i][k]*bb[k][j]); } } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { aa[i][j]=cc[i][j]; } } } void mul(matrix1 aa,matrix2 bb) { matrix1 cc; int i,j,k; for(i=0;i<1;i++) { for(j=0;j<3;j++) { cc[i][j]=0; for(k=0;k<3;k++) {
  • 17. [17] cc[i][j]=cc[i][j]+(aa[i][k]*bb[k][j]); } } } for(i=0;i<m;i++) { for(j=0;j<q;j++) { aa[i][j]=cc[i][j]; } } } Practical -06 Q1)// Cohen sutherland line clipping algorithm #include<graphics.h> void main() { int gd=DETECT, gm; float i,xmin,ymin, xmax,ymax,x1,y1,x2,y2,m; float code1[4]={0,0,0,0},code2[4]={0,0,0,0}; clrscr(); initgraph(&gd,&gm,"c:tcbin"); printf("ntEnter the top-left coordinate of viewport: "); scanf("%f %f",&xmin,&ymin); printf("ntEnter the bottom-right coordinate of viewport: "); scanf("%f %f",&xmax,&ymax); printf("nEnter the coordinates for starting point of line: "); scanf("%f %f",&x1,&y1); printf("nEnter the coordinates for ending point of line: "); scanf("%f %f",&x2,&y2); rectangle(xmin,ymin,xmax,ymax); line(x1,y1,x2,y2); m=(y2-y1)/(x2-x1); if(x1 <xmin) start[0]=1; if(x1 >xmax) start[1]=1; if(y1 >ymax) start[2]=1; if(y1 <ymin) start[3]=1; if(x2 <xmin) end[0]=1; if(x2 >xmax) end[1]=1; if(y2 >ymax) end[2]=1; if(y2 <ymin) end[3]=1; if((code1[0]==0)&&( code1[1]==0)&&( code1[2]==0)&&( code1[3]==0)&&( code2[0]==0)&&( code2[1]==0)&&( code2[2]==0)&&( code2[3]==0)) {
  • 18. [18] cleardevice(); printf("nttThe line is totally visiblenttand not a clipping candidate"); rectangle(xmin,ymin,xmax,ymax); line(x1,y1,x2,y2); getch(); } else if(((code1[0] && code2[0])==0) && ((code1[1] && code2[1])==0) && ((code1[2] && code2[2])==0) && ((code1[3] && code2[3])==0)) { cleardevice(); printf("nttLine is partially visible"); rectangle(xmin,ymin,xmax,ymax); if(x1<xmin) { y1=y1+m*(xmin-x1); x1=xmin; } If(x2<xmin) { y2=y2+m*(xmin-x2); x2=xmin; } If(x1>xmax) { y1=y1+m*(xmax-x1); x1=xmax; } If(x2>xmax) { y2=y2+m*(xmax-x2); x2=xmax; } if(y1<ymin) { x1=x1+(ymin-y1)/m; y1=ymin; } If(y2<ymin) { x2=x2+(ymin-y2)/m; y2=ymin; } If(y1>ymax) { x1=x1+(ymax-y1)/m; y1=ymax; } If(y2>ymax) { x2=x2+(ymax-y2)/m; y2=ymax; } line(x1,y1,x2,y2);
  • 19. [19] getch(); } else { clrscr(); cleardevice(); printf("nLine is invisible"); rectangle(xmin,ymin,xmax,ymax); } getch(); } Q2)Aim: Text Clipping #include<graphics.h> void main() { int gd=DETECT,gm; int xmin,ymin,xmax,ymax; int x1,y1,x2,y2; printf(“Enter coordinates of window: “); scanf(“%d %d %d %d”,&xmin,&ymin,&xmax,&ymax); printf(“Enter the location of first text: “); scanf(“%d %d”,&x1,&y1); printf(“Enter the location of second text: “); scanf(“%d %d”,&x2,&y2); initgraph(&gd,&gm,"C:TCBGI"); rectangle(xmin,ymin,xmax,ymax); //window outtextxy(x1,y1,"INDIA"); rectangle(x1-1,y1-1,x1+50,y1+10); outtextxy(x2,y2,"INDIA"); rectangle(x2-1,y2-1,x2+50,y2+10); getch(); cleardevice(); outtextxy(20,20,"after clipping"); rectangle(xmin,ymin,xmax,ymax); //window if((x1-1>xmin && x1-1<xmax) && (y1-1>ymin && y1-1<ymax) && (x1+50>xmin && x1+50<xmax) && (y1+10>ymin && y1+10<ymax)) { outtextxy(x1,y1,"INDIA"); rectangle(x1-1,y1-1,x1+50,y1+10); } if((x2-1>xmin && x2-1<xmax) && (y2-1>ymin && y2-1<ymax) && (x2+50>xmin && x2+50<xmax) && (y2+10>ymin && y2+10<ymax)) { outtextxy(x2,y2,"INDIA"); rectangle(x2-1,y2-1,x2+50,y2+10); } getch(); }
  • 20. [20] Practical -7 Q1) Aim: Character Generation #include<graphics.h> void main() { int gd=DETECT,gm,c,i,j; int a[20][20]={{0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0}, {0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0}, {0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0}, {1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0}, {1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,0}, {1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0}, {0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0}, {0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0}, {0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0}}; initgraph(&gd,&gm,"C:TCBGI"); for(i=0;i<=19;i++) { for(j=0;j<=19;j++) { if(a[i][j]==1) putpixel(100+j,200+i,15); } } getch(); } Practical -8 Q1) Aim: To draw a moving Car #include<graphics.h> void main() { int gd=DETECT,gm; int x=0; int start=0,end=90; int rad=30; initgraph(&gd,&gm,"C:TCBGI"); while(!kbhit()) { cleardevice(); start=start-4; end=end-4; if(x<640) x=x+1 ; else x=0; setfillstyle(SOLID_FILL,BLUE); pieslice(x,240,start,end,rad); pieslice(x,240,start-180,end-180,rad); circle(x,240,rad);
  • 21. [21] setfillstyle(SOLID_FILL,BLUE); pieslice(x+120,240,start,end,rad); pieslice(x+120,240,start-180,end-180,rad); circle(x+120,240,rad); line(x+rad,240,x-rad+120,240); line(x-rad,240,x-rad-45,240); line(x+rad+120,240,x+rad+210,240); line(x-rad-45,240,x-60,180); line(x-60,180,x-10,180); line(x-10,180,x+rad,150); line(x+rad,150,x+130,150); line(x+130,150,x+150+10,180); line(x+160,180,x+210,180); line(x+210,180,x+240,240); delay(150); } getch(); } Q2) Aim: To draw a moving fish #include<graphics.h> int main() { int gd=DETECT,gm; int x=0; initgraph(&gd,&gm,"C:TCBGI"); while(!kbhit()) { cleardevice(); if(x<640) x=x+10; else x=0; setfillstyle(EMPTY_FILL,BLACK); arc(x,180,30,150,50); arc(x,130,210,330,50); line(x-42,155,x-80,130); line(x-42,155,x-80,180); line(x-80,180,x-80,130); circle(x+20,150,5); circle(x+60,155,7); circle(x+63,130,5); circle(x+66,110,3); arc(x,300,30,150,50); arc(x,253,210,330,50); delay(100); } getch(); } Q3) Aim: To draw a flying kite #include<graphics.h> int main() {