CGR Code 123
CGR Code 123
CGR Code 123
// in computer-graphics
#include <stdio.h>
#include <dos.h>
#include <graphics.h>
// at subsequence points
int x = 0, y = r;
int d = 3 - 2 * r;
// and correspondingly
// update d, y
if (d > 0) {
y--;
d = d + 4 * (x - y) + 10;
else
d = d + 4 * x + 6;
x++;
delay(50);
int main()
return 0;
}
Practical no 5
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void flood(int,int,int,int);
void main()
intgd=DETECT,gm;
initgraph(&gd,&gm,"C:/TURBOC3/bgi");
rectangle(50,50,250,250);
flood(55,55,10,0);
getch();
if(getpixel(x,y)==defaultColor)
delay(1);
putpixel(x,y,fillColor);
flood(x+1,y,fillColor,defaultColor);
flood(x-1,y,fillColor,defaultColor);
flood(x,y+1,fillColor,defaultColor);
flood(x,y-1,fillColor,defaultColor);
}
Praactical no 6
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
getpixel(x, y) != fill_color)
putpixel(x, y, fill_color);
//driver code
int main()
int x , y , radius;
scanf("%d%d%d",&x,&y,&radius);
// circle fuction
circle(x, y, radius);
// Function calling
boundaryFill4(x, y, 6, 15);
delay(10000);
getch();
// graphics system .
closegraph();
return 0;
}
Practical no 7,8,9
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
int x=330,y=250;
int a[4][2]={{50,50},{100,50},{100,100},{50,100}};
setcolor(WHITE);
line(x,y-250,x,y+250);
line(x-330,y,x+330,y);
line(x+a[0][0],y-a[0][1],x+a[1][0],y-a[1][1]);
line(x+a[1][0],y-a[1][1],x+a[2][0],y-a[2][1]);
line(x+a[2][0],y-a[2][1],x+a[3][0],y-a[3][1]);
line(x+a[3][0],y-a[3][1],x+a[0][0],y-a[0][1]);
int tx,ty,xt,yt;
cleardevice();
scanf("%d%d",&tx,&ty);
cleardevice();
draw(x,y);
setcolor(WHITE);
stat(x,y);
xt=x+tx;
yt=y+ty;
getch();
setcolor(GREEN);
stat(xt,yt);
double d,x2r,y2r,x3r,y3r,x4r,y4r;
cleardevice();
scanf("%lf",&d);
cleardevice();
draw(x,y);
setcolor(WHITE);
stat(x,y);
d=(d*3.14)/180;
x2r=a[0][0]+(((a[1][0]-a[0][0])*cos(d))-((a[1][1]-a[0][1])*sin(d)));
y2r=a[0][1]+(((a[1][0]-a[0][0])*sin(d))+((a[1][1]-a[0][1])*cos(d)));
x3r=a[0][0]+(((a[2][0]-a[0][0])*cos(d))-((a[2][1]-a[0][1])*sin(d)));
y3r=a[0][1]+(((a[2][0]-a[0][0])*sin(d))+((a[2][1]-a[0][1])*cos(d)));
x4r=a[0][0]+(((a[3][0]-a[0][0])*cos(d))-((a[3][1]-a[0][1])*sin(d)));
y4r=a[0][1]+(((a[3][0]-a[0][0])*sin(d))+((a[3][1]-a[0][1])*cos(d)));
getch();
setcolor(GREEN);
line(x+a[0][0],y-a[0][1],x+x2r,y-y2r);
line(x+x2r,y-y2r,x+x3r,y-y3r);
line(x+x3r,y-y3r,x+x4r,y-y4r);
line(x+x4r,y-y4r,x+a[0][0],y-a[0][1]);
{
int sx,sy;
cleardevice();
scanf("%d%d",&sx,&sy);
cleardevice();
draw(x,y);
setcolor(WHITE);
stat(x,y);
getch();
setcolor(GREEN);
line(x+a[0][0]*sx,y-a[0][1]*sy,x+a[1][0]*sx,y-a[1][1]*sy);
line(x+a[1][0]*sx,y-a[1][1]*sy,x+a[2][0]*sx,y-a[2][1]*sy);
line(x+a[2][0]*sx,y-a[2][1]*sy,x+a[3][0]*sx,y-a[3][1]*sy);
line(x+a[3][0]*sx,y-a[3][1]*sy,x+a[0][0]*sx,y-a[0][1]*sy);
int x1,y1,ch;
scanf("%d",&ch);
cleardevice();
draw(x,y);
setcolor(WHITE);
stat(x,y);
getch();
x1=-1;
y1=1;
setcolor(GREEN);
if(ch==2)
line(x+a[0][0]*x1,y-a[0][1]*y1,x+a[1][0]*x1,y-a[1][1]*y1);
line(x+a[1][0]*x1,y-a[1][1]*y1,x+a[2][0]*x1,y-a[2][1]*y1);
line(x+a[2][0]*x1,y-a[2][1]*y1,x+a[3][0]*x1,y-a[3][1]*y1);
line(x+a[3][0]*x1,y-a[3][1]*y1,x+a[0][0]*x1,y-a[0][1]*y1);
else
line(x-a[0][0]*x1,y+a[0][1]*y1,x-a[1][0]*x1,y+a[1][1]*y1);
line(x-a[1][0]*x1,y+a[1][1]*y1,x-a[2][0]*x1,y+a[2][1]*y1);
line(x-a[2][0]*x1,y+a[2][1]*y1,x-a[3][0]*x1,y+a[3][1]*y1);
line(x-a[3][0]*x1,y+a[3][1]*y1,x-a[0][0]*x1,y+a[0][1]*y1);
int shr,sh1,sh2,shear;
cleardevice();
scanf("%d",&shear);
scanf("%d",&shr);
cleardevice();
draw(x,y);
setcolor(WHITE);
stat(x,y);
getch();
setcolor(GREEN);
switch(shear)
case 1:
{
sh1=shr*a[2][1];
sh2=shr*a[3][1];
line(x+a[0][0],y-a[0][1],x+a[1][0],y-a[1][1]);
line(x+a[1][0],y-a[1][1],x+a[2][0]+sh1,y-a[2][1]);
line(x+a[2][0]+sh1,y-a[2][1],x+a[3][0]+sh2,y-a[3][1]);
line(x+a[3][0]+sh2,y-a[3][1],x+a[0][0],y-a[0][1]);
break;
case 2:
sh1=shr*a[1][0];
sh2=shr*a[2][0];
line(x+a[0][0],y-a[0][1],x+a[1][0],y-a[1][1]-sh2);
line(x+a[1][0],y-a[1][1]-sh2,x+a[2][0],y-a[2][1]-sh2);
line(x+a[2][0],y-a[2][1]-sh2,x+a[3][0],y-a[3][1]);
line(x+a[3][0],y-a[3][1],x+a[0][0],y-a[0][1]);
break;
void main()
int ch;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
cleardevice();
printf("\n1: TRANSLATION \n2: ROTATION \n3: SCALING \n4: REFLECTION \n5: SHEAR");
scanf("%d",&ch);
switch(ch)
{
case 1: translate(x,y);
break;
case 2: rotate(x,y);
break;
case 3: scale(x,y);
break;
case 4: reflect(x,y);
break;
case 5: shear(x,y);
break;
default:printf("Wrong choice");
break;
getch();
closegraph();
restorecrtmode();
}
Translation
Rotation
Scaling
Reflection
Shear
Practical no 10,11
#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,gm,x,y,z,ang,x1,x2,y1,y2;
detectgraph(&gd,&gm);
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");
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");
scanf("%d%d%d",&x,&y,&z);
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*z,5);
axis();
outtextxy(100,20,"ROTATION");
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();
bar3d(midx+100,midy-20,midx+60,midy-90,20,5);
bar3d(midx+x1,midy-y1,midx+x2,midy-y2,20,5);
axis();
bar3d(midx+100,midy-20,midx+60,midy-90,20,5);
bar3d(midx+100,midy-x1,midx+60,midy-x2,20,5);
axis();
bar3d(midx+100,midy-20,midx+60,midy-90,20,5);
bar3d(midx+x1,midy-20,midx+x2,midy-90,20,5);
axis();
closegraph(); }
3d Translation
Rotation
3D Scaling
Practical no 12
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int xwmax=300,xwmin=200,ywmax=100,ywmin=200,ax,ay,bx,by;
void input()
scanf("%d%d%d%d",&ax,&ay,&bx,&by);
void draw()
rectangle(xwmin,ywmin,xwmax,ywmax);
if(y<ywmax)
p[0]=1;
if(y>ywmin)
p[1]=1;
if(x>xwmax)
p[2]=1;
if(x<xwmin)
p[3]=1;
else
p[3]=0;
void main()
int gd=DETECT,gm,y,x,c,p1[4],p2[4],p3[4],i;
float m;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
cleardevice();
input();
cleardevice();
clip(ax,ay,p1);
clip(bx,by,p2);
for(i=0;i<4;i++)
p3[3]=p1[i]&&p2[i];
for(i=0;i<4;i++)
if(p3[i]==1)
break;
draw();
line(ax,ay,bx,by);
getch();
cleardevice();
if(i!=4)
draw();
else
m=(float)(by-ay)/(bx-ax);
if(p1[0]==1)
y=ywmax;
if(p1[1]==1)
y=ywmin;
if(p1[0]==1||p1[1]==1)
ax=ax+(y-ay)/m;
ay=y;
if(p2[0]==1)
y=ywmax;
if(p2[1]==1)
y=ywmin;
if(p2[0]==1||p2[1]==1)
bx=bx+(y-by)/m;
by=y;
if(p1[2]==1)
x=xwmax;
if(p1[3]==1)
x=xwmin;
if(p1[2]==1||p1[3]==1)
ay=ay+m*(x-ax);
ax=x;
if(p2[2]==1)
x=xwmax;
if(p2[3]==1)
x=xwmin;
if(p2[2]==1||p2[3]==1)
by=by+m*(x-bx);
bx=x;
draw();
line(ax,ay,bx,by);
getch();
closegraph();
restorecrtmode();}
Practical no 13
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
#include <math.h>
#include <graphics.h>
int x,y;
char code[4];
}PT;
void drawwindow();
PT setcode(PT p);
main()
PT p1,p2,ptemp;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
cleardevice();
scanf("%d%d",&p1.x,&p1.y);
scanf("%d%d",&p2.x,&p2.y);
cleardevice();
drawwindow();
getch();
drawline(p1,p2);
getch();
cleardevice();
drawwindow();
midsub(p1,p2);
getch();
closegraph();
return(0);
PT mid;
int v;
p1=setcode(p1);
p2=setcode(p2);
v=visibility(p1,p2);
switch(v)
case 0:
drawline(p1,p2);
break;
case 1:break;
case 2:
midsub(p1,mid);
mid.x = mid.x+1;
mid.y = mid.y+1;
midsub(mid,p2);
break;
void drawwindow()
{
setcolor(RED);
line(150,100,450,100);
line(450,100,450,400);
line(450,400,150,400);
line(150,400,150,100);
setcolor(15);
line(p1.x,p1.y,p2.x,p2.y);
PT setcode(PT p)
PT ptemp;
ptemp.code[1]=1;
else
ptemp.code[1]=0;
if (p.x>=450)
ptemp.code[2]=1;
else
ptemp.code[2]=0;
if (p.x<=150)
ptemp.code[3]=1;
else
ptemp.code[3]=0;
ptemp.x=p.x;
ptemp.y=p.y;
return(ptemp);
int i,flag=0;
for(i=0;i<4;i++)
if((p1.code[i]!=0)||(p2.code[i]!=0))
flag=1;
if(flag==0)
return(0);
for(i=0;i<4;i++)
if((p1.code[i]==p2.code[i]) &&(p1.code[i]==1))
flag=0;
if(flag==0)
return(1);
return(2);
}
Pracical no 14
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
int main()
int gd,gm,n,*x,i,k=0;
detectgraph(&gd,&gm);
printf("Window:-");
scanf("%d",&n);
x = malloc(n*2+1);
k=0;
printf("(x%d,y%d): ",k,k);
scanf("%d,%d",&x[i],&x[i+1]);
k++;
x[n*2]=x[0]; //assigning the coordinates of first vertex to last additional vertex for drawpoly
method.
x[n*2+1]=x[1];
setcolor(WHITE);
drawpoly(n+1,x);
printf("\nPress a button to clip a polygon..");
getch();
setcolor(RED);
drawpoly(5,w);
setfillstyle(SOLID_FILL,BLACK);
floodfill(2,2,RED);
getch();
cleardevice();
closegraph();
return 0;
}
Practical no 15
#include<graphics.h>
#include<math.h>
#include<conio.h>
#include<stdio.h>
void main()
int x[4],y[4],i;
double put_x,put_y,t;
int gr=DETECT,gm;
initgraph(&gr,&gm,"C:\\TURBOC3\\BGI");
for(i=0;i<4;i++)
scanf("%d%d",&x[i],&y[i]);
getch();
closegraph();
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: