SlideShare una empresa de Scribd logo
1 de 16
1 Clipping/fill algorithms
//Graphics Point Clipping C Program
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int tlx,tly,brx,bry,px,py;
void point_clip()
{ int wxmin,wymin,wxmax,wymax;
wxmin=tlx;
wxmax=brx;
wymin=tly;
wymax=bry;
if(px>=wxmin&&px<=wxmax)
if(py>=wymin&&py<=wymax)
putpixel(px,py,RED);
getch();
closegraph();
}
void main(void)
{ int gd=DETECT,gm,xc,yc,r;
clrscr();
printf("Enter the top left coordinate");
scanf("%d%d",&tlx,&tly);
printf("Enter the bottom right coordinate");
scanf("%d%d",&brx,&bry);
printf("n Enter the point");
scanf("%d%d",&px,&py);
initgraph(&gd,&gm,"c:tcbgi"); /*Sometimes it may be
"C:TCBGI" , It depends machine to mac..*/
setbkcolor(YELLOW);
setcolor(RED);
rectangle(tlx,tly,brx,bry);
point_clip();
}
2 Clipping/fill algorithms
//Sutherland-Hodgeman Polygon clipping Algorithm
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void clip(float,float,float);
int i,j=0,n;
int rx1,rx2,ry1,ry2;
float x1[8],y1[8];
void main()
{
int gd=DETECT,gm;
int i,n;
float x[8],y[8],m;
clrscr();
initgraph(&gd,&gm,"");
printf("coordinates for rectangle : ");
scanf("%d%d%d%d",&rx1,&ry1,&rx2,&ry2);
printf("no. of sides for polygon : ");
scanf("%d",&n);
printf("coordinates : ");
for(i=0;i<n;i++)
{
scanf("%f%f",&x[i],&y[i]);
}
cleardevice();
outtextxy(10,10,"Before clipping");
outtextxy(10,470,"Press any key....");
rectangle(rx1,ry1,rx2,ry2);
for(i=0;i<n-1;i++)
line(x[i],y[i],x[i+1],y[i+1]);
line(x[i],y[i],x[0],y[0]);
getch();
cleardevice();
3 Clipping/fill algorithms
for(i=0;i<n-1;i++)
{
m=(y[i+1]-y[i])/(x[i+1]-x[i]);
clip(x[i],y[i],m);
}
clip(x[0],y[0],m);
outtextxy(10,10,"After clipping");
outtextxy(10,470,"Press any key....");
rectangle(rx1,ry1,rx2,ry2);
for(i=0;i<j-1;i++)
line(x1[i],y1[i],x1[i+1],y1[i+1]);
getch();
}
void clip(float e,float f,float m)
{
while(e<rx1 e>rx2 f<ry1 f>ry2)
{
if(e<rx1)
{
f+=m*(rx1-e);
e=rx1;
}
else if(e>rx2)
{
f+=m*(rx2-e);
e=rx1;
}
if(f<ry1)
{
e+=(ry1-f)/m;
f=ry1;
}
else if(f>ry2)
4 Clipping/fill algorithms
{
e+=(ry2-f)/m;
f=ry2;
}
x1[j]=e;
y1[j]=f;
j++;
}
}
OUTPUT
Enter the x1 & y1 coordinates:
X1 : 70
Y1 : 80
Enter the x2 & y2 coordinates:
X2 : 250
Y2 : 280
5 Clipping/fill algorithms
//polygon clipping
#include<graphics.h>
#include<dos.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int gd, gm ;
int x1 , y1 , x2 , y2 ;
int wxmin,wymin,wxmax, wymax ;
float u1 = 0.0,u2 = 1.0 ;
int p1 , q1 , p2 , q2 , p3 , q3 , p4 ,q4 ;
float r1 , r2 , r3 , r4 ;
int x11 , y11 , x22 , y22 ;
clrscr();
printf("Enter the windows left xmin , top boundry yminn");
scanf("%d%d",&wxmin,&wymin);
printf("Enter the windows right xmax ,bottom boundry
ymaxn");
scanf("%d%d",&wxmax,&wymax);
printf("Enter line x1 , y1 co-ordinaten");
scanf("%d%d",&x1,&y1);
printf("Enter line x2 , y2 co-ordinaten");
scanf("%d%d",&x2,&y2);
printf("liang barsky express these 4 inequalities using
lpk<=qpkn");
p1 = -(x2 - x1 ); q1 = x1 - wxmin ;
p2 = ( x2 - x1 ) ; q2 = wxmax - x1 ;
p3 = - ( y2 - y1 ) ; q3 = y1 - wymin ;
6 Clipping/fill algorithms
p4 = ( y2 - y1 ) ; q4 = wymax - y1 ;
printf("p1=0 line is parallel to left clippingn");
printf("p2=0 line is parallel to right clippingn");
printf("p3=0 line is parallel to bottom clippingn");
printf("p4=0 line is parallel to top clippingn");
if( ( ( p1 == 0.0 ) && ( q1 < 0.0 ) ) ||
( ( p2 == 0.0 ) && ( q2 < 0.0 ) ) ||
( ( p3 == 0.0 ) && ( q3 < 0.0 ) ) ||
( ( p4 == 0.0 ) && ( q4 < 0.0 ) ) )
{
printf("Line is rejectedn");
getch();
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:tcbgi");
setcolor(RED);
rectangle(wxmin,wymax,wxmax,wymin);
setcolor(BLUE);
line(x1,y1,x2,y2);
getch();
setcolor(WHITE);
line(x1,y1,x2,y2);
getch();
}
else
{
if( p1 != 0.0 )
{
r1 =(float) q1 /p1 ;
if( p1 < 0 )
u1 = max(r1 , u1 );
7 Clipping/fill algorithms
else
u2 = min(r1 , u2 );
}
if( p2 != 0.0 )
{
r2 = (float ) q2 /p2 ;
if( p2 < 0 )
u1 = max(r2 , u1 );
else
u2 = min(r2 , u2 );
}
if( p3 != 0.0 )
{
r3 = (float )q3 /p3 ;
if( p3 < 0 )
u1 = max(r3 , u1 );
else
u2 = min(r3 , u2 );
}
if( p4 != 0.0 )
{
r4 = (float )q4 /p4 ;
if( p4 < 0 )
u1 = max(r4 , u1 );
else
u2 = min(r4 , u2 );
}
if( u1 > u2 )
printf("line rejectedn");
else
8 Clipping/fill algorithms
{
x11 = x1 + u1 * ( x2 - x1 ) ;
y11 = y1 + u1 * ( y2 - y1 ) ;
x22 = x1 + u2 * ( x2 - x1 );
y22 = y1 + u2 * ( y2 - y1 );
printf("Original line cordinatesn");
printf("x1 = %d , y1 = %d, x2 = %d, y2 = %dn",x1,y1,x2,y2);
printf("Windows coordinate are n");
printf("wxmin = %d, wymin = %d,wxmax = %d , wymax = %d
",wxmin,wymin,wxmax,wymax);
printf("New coordinates are n");
printf("x1 = %d, y1 = %d,x2 = %d , y2 =
%dn",x11,y11,x22,y22);
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:TCBGI");
setcolor(2);
rectangle(wxmin,wymax,wxmax,wymin);
setcolor(1);
line(x1,y1,x2,y2);
getch();
setcolor(0);
line(x1,y1,x2,y2);
setcolor(3);
line(x11,y11,x22,y22);
getch();
}
}
}
9 Clipping/fill algorithms
//C Program For Oblique projection of a 3D object
#include<stdio.h>
#include<math.h>
#include<graphics.h>
main()
{
int x1,y1,x2,y2,gd,gm;
int ymax,a[4][8];
float par[4][4],b[4][8];
int i,j,k,m,n,p;
double L1,phi;
a[0][0] = 100; a[1][0] = 100; a[2][0] = 100;
a[0][1] = 200; a[1][1] = 100; a[2][1] = 100;
a[0][2] = 200; a[1][2] = 200; a[2][2] = 100;
a[0][3] = 100; a[1][3] = 200; a[2][3] = 100;
a[0][4] = 100; a[1][4] = 100; a[2][4] = 200;
a[0][5] = 200; a[1][5] = 100; a[2][5] = 200;
a[0][6] = 200; a[1][6] = 200; a[2][6] = 200;
a[0][7] = 100; a[1][7] = 200; a[2][7] = 200;
phi = (double) (3.14*45.0)/180 ;
L1 = 0.5;
par[0][0] = 1; par[0][1] = 0;
par[0][2] = L1*cos(phi); par[0][3] = 0;
10 Clipping/fill algorithms
par[1][0] = 0; par[1][1] = 1;
par[1][2] = L1*sin(phi); par[1][3] = 0;
par[2][0] = 0; par[2][1] = 0;
par[2][2] = 0; par[2][3] = 0;
par[3][0] = 0; par[3][1] = 0;
par[3][2] = 0; par[3][3] = 1;
m=4; n=4; p=8;
for(i=0; i<m; i++)
for(k=0; k<p; k++)
b[i][k] = 0;
for(i=0; i<m; i++)
for(k=0; k<p; k++)
for(j=0; j<n; j++)
b[i][k] += (float)par[i][j] * a[j][k];
detectgraph(&gd,&gm);
initgraph(&gd,&gm, "c:tcbgi");
ymax = getmaxy();
/*- front plane display -*/
for(j=0;j<3;j++)
{
x1=(int) b[0][j]; y1=(int) b[1][j];
x2=(int) b[0][j+1]; y2=(int) b[1][j+1];
line( x1,ymax-y1,x2,ymax-y2);
11 Clipping/fill algorithms
}
x1=(int) b[0][3]; y1=(int) b[1][3];
x2=(int) b[0][0]; y2=(int) b[1][0];
line( x1,ymax-y1,x2,ymax-y2);
/*- back plane display -*/
setcolor(11);
for(j=4;j<7;j++)
{
x1=(int) b[0][j]; y1=(int) b[1][j];
x2=(int) b[0][j+1]; y2=(int) b[1][j+1];
line( x1,ymax-y1,x2,ymax-y2);
}
x1=(int) b[0][7]; y1=(int) b[1][7];
x2=(int) b[0][4]; y2=(int) b[1][4];
line( x1,ymax-y1,x2,ymax-y2);
setcolor(13);
for(i=0;i<4;i++)
{
x1=(int) b[0][i]; y1=(int) b[1][i];
x2=(int) b[0][4+i]; y2=(int) b[1][4+i];
line( x1,ymax-y1,x2,ymax-y2);
}
getch(); getch();
}
12 Clipping/fill algorithms
C Program to implement Boundary Fill Algorithm
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void fill_right(x,y)
int x , y ;
{
if((getpixel(x,y) != WHITE)&&(getpixel(x,y) != RED))
{
putpixel(x,y,RED);
fill_right(++x,y);
x = x - 1 ;
fill_right(x,y-1);
fill_right(x,y+1);
}
delay(1);
}
void fill_left(x,y)
int x , y ;
{
if((getpixel(x,y) != WHITE)&&(getpixel(x,y) != RED))
{
putpixel(x,y,RED);
fill_left(--x,y);
x = x + 1 ;
fill_left(x,y-1);
13 Clipping/fill algorithms
fill_left(x,y+1);
}
delay(1);
}
void main()
{
int x,y,n,i;
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"c:tcbgi");
/*- draw object -*/
line (50,50,200,50);
line (200,50,200,300);
line (200,300,50,300);
line (50,300,50,50);
/*- set seed point -*/
x = 100; y = 100;
fill_right(x,y);
fill_left(x-1,y);
getch();
}
14 Clipping/fill algorithms
//C Program to Implement Flood Fill Algorithm
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
void fill_right(x,y)
int x , y ;
{
if(getpixel(x,y) == 0)
{
putpixel(x,y,RED);
fill_right(++x,y);
x = x - 1 ;
fill_right(x,y-1);
fill_right(x,y+1);
}
}
void fill_left(x,y)
int x , y ;
{
if(getpixel(x,y) == 0)
{
putpixel(x,y,RED);
fill_left(--x,y);
x = x + 1 ;
fill_left(x,y-1);
fill_left(x,y+1);
15 Clipping/fill algorithms
}
}
void main()
{
int x , y ,a[10][10];
int gd, gm ,n,i;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:tcbgi");
printf("nntEnter the no. of edges of polygon : ");
scanf("%d",&n);
printf("nntEnter the cordinates of polygon :nnn ");
for(i=0;i<n;i++)
{
printf("tX%d Y%d : ",i,i);
scanf("%d %d",&a[i][0],&a[i][1]);
}
a[n][0]=a[0][0];
a[n][1]=a[0][1];
printf("nntEnter the seed pt. : ");
scanf("%d%d",&x,&y);
cleardevice();
setcolor(WHITE);
for(i=0;i<n;i++) /*- draw poly -*/
{
16 Clipping/fill algorithms
line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]);
}
fill_right(x,y);
fill_left(x-1,y);
getch();
}
/*SAMPLE INPUT*/
/*Enter the number of edges of polygon 4
X0 Y0 = 50 50
X1 Y1 = 200 50
X2 Y2 = 200 300
X3 Y3 = 50 300
Enter the seed point 100 100*/

Más contenido relacionado

La actualidad más candente

Regular expression in javascript
Regular expression in javascriptRegular expression in javascript
Regular expression in javascriptToan Nguyen
 
Introduction to Computer theory Daniel Cohen Chapter 4 & 5 Solutions
Introduction to Computer theory Daniel Cohen Chapter 4 & 5 SolutionsIntroduction to Computer theory Daniel Cohen Chapter 4 & 5 Solutions
Introduction to Computer theory Daniel Cohen Chapter 4 & 5 SolutionsAshu
 
Program security
Program securityProgram security
Program securityG Prachi
 
Process improvement & service oriented software engineering
Process improvement & service oriented software engineeringProcess improvement & service oriented software engineering
Process improvement & service oriented software engineeringSweta Kumari Barnwal
 
Software Engineering ppt
Software Engineering pptSoftware Engineering ppt
Software Engineering pptshruths2890
 
Formal Specification in Software Engineering SE9
Formal Specification in Software Engineering SE9Formal Specification in Software Engineering SE9
Formal Specification in Software Engineering SE9koolkampus
 
Web Technology Lab files with practical
Web Technology Lab  files with practicalWeb Technology Lab  files with practical
Web Technology Lab files with practicalNitesh Dubey
 
Object oriented testing
Object oriented testingObject oriented testing
Object oriented testingHaris Jamil
 
Estimating Software Maintenance Costs
Estimating Software Maintenance CostsEstimating Software Maintenance Costs
Estimating Software Maintenance Costslalithambiga kamaraj
 
Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1Vai Jayanthi
 
Client server s/w Engineering
Client server s/w EngineeringClient server s/w Engineering
Client server s/w EngineeringRajan Shah
 
Unit4 Proof of Correctness, Statistical Tools, Clean Room Process and Quality...
Unit4 Proof of Correctness, Statistical Tools, Clean Room Process and Quality...Unit4 Proof of Correctness, Statistical Tools, Clean Room Process and Quality...
Unit4 Proof of Correctness, Statistical Tools, Clean Room Process and Quality...Reetesh Gupta
 
WT(WEB TECHNOLOGY) previous year question papers
WT(WEB TECHNOLOGY) previous year question papersWT(WEB TECHNOLOGY) previous year question papers
WT(WEB TECHNOLOGY) previous year question papersHemaArora2
 
Library Management System - V1.0
Library Management System - V1.0Library Management System - V1.0
Library Management System - V1.0JamesMuturi
 
Spiral model explanation
Spiral model  explanationSpiral model  explanation
Spiral model explanationUmar Farooq
 
Counting valleys from Hackerrank solution explained
Counting valleys from Hackerrank solution explainedCounting valleys from Hackerrank solution explained
Counting valleys from Hackerrank solution explainedLuis Martín Espino Rivera
 

La actualidad más candente (20)

Regular expression in javascript
Regular expression in javascriptRegular expression in javascript
Regular expression in javascript
 
Web technology lab manual
Web technology lab manualWeb technology lab manual
Web technology lab manual
 
Introduction to Computer theory Daniel Cohen Chapter 4 & 5 Solutions
Introduction to Computer theory Daniel Cohen Chapter 4 & 5 SolutionsIntroduction to Computer theory Daniel Cohen Chapter 4 & 5 Solutions
Introduction to Computer theory Daniel Cohen Chapter 4 & 5 Solutions
 
Program security
Program securityProgram security
Program security
 
Process improvement & service oriented software engineering
Process improvement & service oriented software engineeringProcess improvement & service oriented software engineering
Process improvement & service oriented software engineering
 
Software Engineering ppt
Software Engineering pptSoftware Engineering ppt
Software Engineering ppt
 
Formal Specification in Software Engineering SE9
Formal Specification in Software Engineering SE9Formal Specification in Software Engineering SE9
Formal Specification in Software Engineering SE9
 
Web Technology Lab files with practical
Web Technology Lab  files with practicalWeb Technology Lab  files with practical
Web Technology Lab files with practical
 
Object oriented testing
Object oriented testingObject oriented testing
Object oriented testing
 
Estimating Software Maintenance Costs
Estimating Software Maintenance CostsEstimating Software Maintenance Costs
Estimating Software Maintenance Costs
 
Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1Cs6402 daa-2 marks set 1
Cs6402 daa-2 marks set 1
 
Client server s/w Engineering
Client server s/w EngineeringClient server s/w Engineering
Client server s/w Engineering
 
Unit4 Proof of Correctness, Statistical Tools, Clean Room Process and Quality...
Unit4 Proof of Correctness, Statistical Tools, Clean Room Process and Quality...Unit4 Proof of Correctness, Statistical Tools, Clean Room Process and Quality...
Unit4 Proof of Correctness, Statistical Tools, Clean Room Process and Quality...
 
WT(WEB TECHNOLOGY) previous year question papers
WT(WEB TECHNOLOGY) previous year question papersWT(WEB TECHNOLOGY) previous year question papers
WT(WEB TECHNOLOGY) previous year question papers
 
Css box-model
Css box-modelCss box-model
Css box-model
 
Library Management System - V1.0
Library Management System - V1.0Library Management System - V1.0
Library Management System - V1.0
 
Web Terminology
Web TerminologyWeb Terminology
Web Terminology
 
Taxonomy for bugs
Taxonomy for bugsTaxonomy for bugs
Taxonomy for bugs
 
Spiral model explanation
Spiral model  explanationSpiral model  explanation
Spiral model explanation
 
Counting valleys from Hackerrank solution explained
Counting valleys from Hackerrank solution explainedCounting valleys from Hackerrank solution explained
Counting valleys from Hackerrank solution explained
 

Destacado

Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics ProgramesAbhishek Sharma
 
SE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneSE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneBhavesh Shah
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics labPriya Goyal
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics PracticalNeha Sharma
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clippingavelraj
 
Developing a research Library position statement on Text and Data Mining in t...
Developing a research Library position statement on Text and Data Mining in t...Developing a research Library position statement on Text and Data Mining in t...
Developing a research Library position statement on Text and Data Mining in t...Danny Kingsley
 
Writing thesis chapters 1-3 guidelines
Writing thesis chapters 1-3 guidelinesWriting thesis chapters 1-3 guidelines
Writing thesis chapters 1-3 guidelinespoleyseugenio
 

Destacado (10)

Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics Programes
 
SE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneSE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of Pune
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
 
Graphics Programming in C
Graphics Programming in CGraphics Programming in C
Graphics Programming in C
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics Practical
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clipping
 
Developing a research Library position statement on Text and Data Mining in t...
Developing a research Library position statement on Text and Data Mining in t...Developing a research Library position statement on Text and Data Mining in t...
Developing a research Library position statement on Text and Data Mining in t...
 
Writing thesis chapters 1-3 guidelines
Writing thesis chapters 1-3 guidelinesWriting thesis chapters 1-3 guidelines
Writing thesis chapters 1-3 guidelines
 

Similar a Graphics point clipping c program

Computer graphics File for Engineers
Computer graphics File for EngineersComputer graphics File for Engineers
Computer graphics File for Engineersvarun arora
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignmentAbdullah Al Shiam
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++Ankit Kumar
 
Numerical Methods in C
Numerical Methods in CNumerical Methods in C
Numerical Methods in CAmbili Baby
 
1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdfsutharbharat59
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C CodeSyed Ahmed Zaki
 
Program to reflecta triangle
Program to reflecta triangleProgram to reflecta triangle
Program to reflecta triangleTanya Makkar
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graphkinan keshkeh
 
Runge kutta C programme
Runge kutta C programmeRunge kutta C programme
Runge kutta C programmeShah Keval
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignmentashikul akash
 
C tech questions
C tech questionsC tech questions
C tech questionsvijay00791
 
Program for pyramid
Program for pyramidProgram for pyramid
Program for pyramidnayakq
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicalsManoj Chauhan
 

Similar a Graphics point clipping c program (20)

Computer graphics File for Engineers
Computer graphics File for EngineersComputer graphics File for Engineers
Computer graphics File for Engineers
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
 
Numerical Methods in C
Numerical Methods in CNumerical Methods in C
Numerical Methods in C
 
1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
Program to reflecta triangle
Program to reflecta triangleProgram to reflecta triangle
Program to reflecta triangle
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
Runge kutta C programme
Runge kutta C programmeRunge kutta C programme
Runge kutta C programme
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignment
 
C tech questions
C tech questionsC tech questions
C tech questions
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
Program for pyramid
Program for pyramidProgram for pyramid
Program for pyramid
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicals
 

Más de Dr.M.Karthika parthasarathy

IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...Dr.M.Karthika parthasarathy
 
Unit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptxUnit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptxDr.M.Karthika parthasarathy
 

Más de Dr.M.Karthika parthasarathy (20)

IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
 
Linux Lab Manual.doc
Linux Lab Manual.docLinux Lab Manual.doc
Linux Lab Manual.doc
 
Unit 2 IoT.pdf
Unit 2 IoT.pdfUnit 2 IoT.pdf
Unit 2 IoT.pdf
 
Unit 3 IOT.docx
Unit 3 IOT.docxUnit 3 IOT.docx
Unit 3 IOT.docx
 
Unit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptxUnit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptx
 
Unit I What is Artificial Intelligence.docx
Unit I What is Artificial Intelligence.docxUnit I What is Artificial Intelligence.docx
Unit I What is Artificial Intelligence.docx
 
Introduction to IoT - Unit II.pptx
Introduction to IoT - Unit II.pptxIntroduction to IoT - Unit II.pptx
Introduction to IoT - Unit II.pptx
 
IoT Unit 2.pdf
IoT Unit 2.pdfIoT Unit 2.pdf
IoT Unit 2.pdf
 
Chapter 3 heuristic search techniques
Chapter 3 heuristic search techniquesChapter 3 heuristic search techniques
Chapter 3 heuristic search techniques
 
Ai mcq chapter 2
Ai mcq chapter 2Ai mcq chapter 2
Ai mcq chapter 2
 
Introduction to IoT unit II
Introduction to IoT  unit IIIntroduction to IoT  unit II
Introduction to IoT unit II
 
Introduction to IoT - Unit I
Introduction to IoT - Unit IIntroduction to IoT - Unit I
Introduction to IoT - Unit I
 
Internet of things Unit 1 one word
Internet of things Unit 1 one wordInternet of things Unit 1 one word
Internet of things Unit 1 one word
 
Unit 1 q&amp;a
Unit  1 q&amp;aUnit  1 q&amp;a
Unit 1 q&amp;a
 
Overview of Deadlock unit 3 part 1
Overview of Deadlock unit 3 part 1Overview of Deadlock unit 3 part 1
Overview of Deadlock unit 3 part 1
 
Examples in OS synchronization for UG
Examples in OS synchronization for UG Examples in OS synchronization for UG
Examples in OS synchronization for UG
 
Process Synchronization - Monitors
Process Synchronization - MonitorsProcess Synchronization - Monitors
Process Synchronization - Monitors
 
.net progrmming part4
.net progrmming part4.net progrmming part4
.net progrmming part4
 
.net progrmming part3
.net progrmming part3.net progrmming part3
.net progrmming part3
 
.net progrmming part1
.net progrmming part1.net progrmming part1
.net progrmming part1
 

Último

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Último (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

Graphics point clipping c program

  • 1. 1 Clipping/fill algorithms //Graphics Point Clipping C Program #include<stdio.h> #include<conio.h> #include<graphics.h> int tlx,tly,brx,bry,px,py; void point_clip() { int wxmin,wymin,wxmax,wymax; wxmin=tlx; wxmax=brx; wymin=tly; wymax=bry; if(px>=wxmin&&px<=wxmax) if(py>=wymin&&py<=wymax) putpixel(px,py,RED); getch(); closegraph(); } void main(void) { int gd=DETECT,gm,xc,yc,r; clrscr(); printf("Enter the top left coordinate"); scanf("%d%d",&tlx,&tly); printf("Enter the bottom right coordinate"); scanf("%d%d",&brx,&bry); printf("n Enter the point"); scanf("%d%d",&px,&py); initgraph(&gd,&gm,"c:tcbgi"); /*Sometimes it may be "C:TCBGI" , It depends machine to mac..*/ setbkcolor(YELLOW); setcolor(RED); rectangle(tlx,tly,brx,bry); point_clip(); }
  • 2. 2 Clipping/fill algorithms //Sutherland-Hodgeman Polygon clipping Algorithm #include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h> void clip(float,float,float); int i,j=0,n; int rx1,rx2,ry1,ry2; float x1[8],y1[8]; void main() { int gd=DETECT,gm; int i,n; float x[8],y[8],m; clrscr(); initgraph(&gd,&gm,""); printf("coordinates for rectangle : "); scanf("%d%d%d%d",&rx1,&ry1,&rx2,&ry2); printf("no. of sides for polygon : "); scanf("%d",&n); printf("coordinates : "); for(i=0;i<n;i++) { scanf("%f%f",&x[i],&y[i]); } cleardevice(); outtextxy(10,10,"Before clipping"); outtextxy(10,470,"Press any key...."); rectangle(rx1,ry1,rx2,ry2); for(i=0;i<n-1;i++) line(x[i],y[i],x[i+1],y[i+1]); line(x[i],y[i],x[0],y[0]); getch(); cleardevice();
  • 3. 3 Clipping/fill algorithms for(i=0;i<n-1;i++) { m=(y[i+1]-y[i])/(x[i+1]-x[i]); clip(x[i],y[i],m); } clip(x[0],y[0],m); outtextxy(10,10,"After clipping"); outtextxy(10,470,"Press any key...."); rectangle(rx1,ry1,rx2,ry2); for(i=0;i<j-1;i++) line(x1[i],y1[i],x1[i+1],y1[i+1]); getch(); } void clip(float e,float f,float m) { while(e<rx1 e>rx2 f<ry1 f>ry2) { if(e<rx1) { f+=m*(rx1-e); e=rx1; } else if(e>rx2) { f+=m*(rx2-e); e=rx1; } if(f<ry1) { e+=(ry1-f)/m; f=ry1; } else if(f>ry2)
  • 4. 4 Clipping/fill algorithms { e+=(ry2-f)/m; f=ry2; } x1[j]=e; y1[j]=f; j++; } } OUTPUT Enter the x1 & y1 coordinates: X1 : 70 Y1 : 80 Enter the x2 & y2 coordinates: X2 : 250 Y2 : 280
  • 5. 5 Clipping/fill algorithms //polygon clipping #include<graphics.h> #include<dos.h> #include<conio.h> #include<stdlib.h> void main() { int gd, gm ; int x1 , y1 , x2 , y2 ; int wxmin,wymin,wxmax, wymax ; float u1 = 0.0,u2 = 1.0 ; int p1 , q1 , p2 , q2 , p3 , q3 , p4 ,q4 ; float r1 , r2 , r3 , r4 ; int x11 , y11 , x22 , y22 ; clrscr(); printf("Enter the windows left xmin , top boundry yminn"); scanf("%d%d",&wxmin,&wymin); printf("Enter the windows right xmax ,bottom boundry ymaxn"); scanf("%d%d",&wxmax,&wymax); printf("Enter line x1 , y1 co-ordinaten"); scanf("%d%d",&x1,&y1); printf("Enter line x2 , y2 co-ordinaten"); scanf("%d%d",&x2,&y2); printf("liang barsky express these 4 inequalities using lpk<=qpkn"); p1 = -(x2 - x1 ); q1 = x1 - wxmin ; p2 = ( x2 - x1 ) ; q2 = wxmax - x1 ; p3 = - ( y2 - y1 ) ; q3 = y1 - wymin ;
  • 6. 6 Clipping/fill algorithms p4 = ( y2 - y1 ) ; q4 = wymax - y1 ; printf("p1=0 line is parallel to left clippingn"); printf("p2=0 line is parallel to right clippingn"); printf("p3=0 line is parallel to bottom clippingn"); printf("p4=0 line is parallel to top clippingn"); if( ( ( p1 == 0.0 ) && ( q1 < 0.0 ) ) || ( ( p2 == 0.0 ) && ( q2 < 0.0 ) ) || ( ( p3 == 0.0 ) && ( q3 < 0.0 ) ) || ( ( p4 == 0.0 ) && ( q4 < 0.0 ) ) ) { printf("Line is rejectedn"); getch(); detectgraph(&gd,&gm); initgraph(&gd,&gm,"c:tcbgi"); setcolor(RED); rectangle(wxmin,wymax,wxmax,wymin); setcolor(BLUE); line(x1,y1,x2,y2); getch(); setcolor(WHITE); line(x1,y1,x2,y2); getch(); } else { if( p1 != 0.0 ) { r1 =(float) q1 /p1 ; if( p1 < 0 ) u1 = max(r1 , u1 );
  • 7. 7 Clipping/fill algorithms else u2 = min(r1 , u2 ); } if( p2 != 0.0 ) { r2 = (float ) q2 /p2 ; if( p2 < 0 ) u1 = max(r2 , u1 ); else u2 = min(r2 , u2 ); } if( p3 != 0.0 ) { r3 = (float )q3 /p3 ; if( p3 < 0 ) u1 = max(r3 , u1 ); else u2 = min(r3 , u2 ); } if( p4 != 0.0 ) { r4 = (float )q4 /p4 ; if( p4 < 0 ) u1 = max(r4 , u1 ); else u2 = min(r4 , u2 ); } if( u1 > u2 ) printf("line rejectedn"); else
  • 8. 8 Clipping/fill algorithms { x11 = x1 + u1 * ( x2 - x1 ) ; y11 = y1 + u1 * ( y2 - y1 ) ; x22 = x1 + u2 * ( x2 - x1 ); y22 = y1 + u2 * ( y2 - y1 ); printf("Original line cordinatesn"); printf("x1 = %d , y1 = %d, x2 = %d, y2 = %dn",x1,y1,x2,y2); printf("Windows coordinate are n"); printf("wxmin = %d, wymin = %d,wxmax = %d , wymax = %d ",wxmin,wymin,wxmax,wymax); printf("New coordinates are n"); printf("x1 = %d, y1 = %d,x2 = %d , y2 = %dn",x11,y11,x22,y22); detectgraph(&gd,&gm); initgraph(&gd,&gm,"C:TCBGI"); setcolor(2); rectangle(wxmin,wymax,wxmax,wymin); setcolor(1); line(x1,y1,x2,y2); getch(); setcolor(0); line(x1,y1,x2,y2); setcolor(3); line(x11,y11,x22,y22); getch(); } } }
  • 9. 9 Clipping/fill algorithms //C Program For Oblique projection of a 3D object #include<stdio.h> #include<math.h> #include<graphics.h> main() { int x1,y1,x2,y2,gd,gm; int ymax,a[4][8]; float par[4][4],b[4][8]; int i,j,k,m,n,p; double L1,phi; a[0][0] = 100; a[1][0] = 100; a[2][0] = 100; a[0][1] = 200; a[1][1] = 100; a[2][1] = 100; a[0][2] = 200; a[1][2] = 200; a[2][2] = 100; a[0][3] = 100; a[1][3] = 200; a[2][3] = 100; a[0][4] = 100; a[1][4] = 100; a[2][4] = 200; a[0][5] = 200; a[1][5] = 100; a[2][5] = 200; a[0][6] = 200; a[1][6] = 200; a[2][6] = 200; a[0][7] = 100; a[1][7] = 200; a[2][7] = 200; phi = (double) (3.14*45.0)/180 ; L1 = 0.5; par[0][0] = 1; par[0][1] = 0; par[0][2] = L1*cos(phi); par[0][3] = 0;
  • 10. 10 Clipping/fill algorithms par[1][0] = 0; par[1][1] = 1; par[1][2] = L1*sin(phi); par[1][3] = 0; par[2][0] = 0; par[2][1] = 0; par[2][2] = 0; par[2][3] = 0; par[3][0] = 0; par[3][1] = 0; par[3][2] = 0; par[3][3] = 1; m=4; n=4; p=8; for(i=0; i<m; i++) for(k=0; k<p; k++) b[i][k] = 0; for(i=0; i<m; i++) for(k=0; k<p; k++) for(j=0; j<n; j++) b[i][k] += (float)par[i][j] * a[j][k]; detectgraph(&gd,&gm); initgraph(&gd,&gm, "c:tcbgi"); ymax = getmaxy(); /*- front plane display -*/ for(j=0;j<3;j++) { x1=(int) b[0][j]; y1=(int) b[1][j]; x2=(int) b[0][j+1]; y2=(int) b[1][j+1]; line( x1,ymax-y1,x2,ymax-y2);
  • 11. 11 Clipping/fill algorithms } x1=(int) b[0][3]; y1=(int) b[1][3]; x2=(int) b[0][0]; y2=(int) b[1][0]; line( x1,ymax-y1,x2,ymax-y2); /*- back plane display -*/ setcolor(11); for(j=4;j<7;j++) { x1=(int) b[0][j]; y1=(int) b[1][j]; x2=(int) b[0][j+1]; y2=(int) b[1][j+1]; line( x1,ymax-y1,x2,ymax-y2); } x1=(int) b[0][7]; y1=(int) b[1][7]; x2=(int) b[0][4]; y2=(int) b[1][4]; line( x1,ymax-y1,x2,ymax-y2); setcolor(13); for(i=0;i<4;i++) { x1=(int) b[0][i]; y1=(int) b[1][i]; x2=(int) b[0][4+i]; y2=(int) b[1][4+i]; line( x1,ymax-y1,x2,ymax-y2); } getch(); getch(); }
  • 12. 12 Clipping/fill algorithms C Program to implement Boundary Fill Algorithm #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> void fill_right(x,y) int x , y ; { if((getpixel(x,y) != WHITE)&&(getpixel(x,y) != RED)) { putpixel(x,y,RED); fill_right(++x,y); x = x - 1 ; fill_right(x,y-1); fill_right(x,y+1); } delay(1); } void fill_left(x,y) int x , y ; { if((getpixel(x,y) != WHITE)&&(getpixel(x,y) != RED)) { putpixel(x,y,RED); fill_left(--x,y); x = x + 1 ; fill_left(x,y-1);
  • 13. 13 Clipping/fill algorithms fill_left(x,y+1); } delay(1); } void main() { int x,y,n,i; int gd=DETECT,gm; clrscr(); initgraph(&gd,&gm,"c:tcbgi"); /*- draw object -*/ line (50,50,200,50); line (200,50,200,300); line (200,300,50,300); line (50,300,50,50); /*- set seed point -*/ x = 100; y = 100; fill_right(x,y); fill_left(x-1,y); getch(); }
  • 14. 14 Clipping/fill algorithms //C Program to Implement Flood Fill Algorithm #include<conio.h> #include<stdio.h> #include<graphics.h> #include<dos.h> void fill_right(x,y) int x , y ; { if(getpixel(x,y) == 0) { putpixel(x,y,RED); fill_right(++x,y); x = x - 1 ; fill_right(x,y-1); fill_right(x,y+1); } } void fill_left(x,y) int x , y ; { if(getpixel(x,y) == 0) { putpixel(x,y,RED); fill_left(--x,y); x = x + 1 ; fill_left(x,y-1); fill_left(x,y+1);
  • 15. 15 Clipping/fill algorithms } } void main() { int x , y ,a[10][10]; int gd, gm ,n,i; detectgraph(&gd,&gm); initgraph(&gd,&gm,"c:tcbgi"); printf("nntEnter the no. of edges of polygon : "); scanf("%d",&n); printf("nntEnter the cordinates of polygon :nnn "); for(i=0;i<n;i++) { printf("tX%d Y%d : ",i,i); scanf("%d %d",&a[i][0],&a[i][1]); } a[n][0]=a[0][0]; a[n][1]=a[0][1]; printf("nntEnter the seed pt. : "); scanf("%d%d",&x,&y); cleardevice(); setcolor(WHITE); for(i=0;i<n;i++) /*- draw poly -*/ {
  • 16. 16 Clipping/fill algorithms line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]); } fill_right(x,y); fill_left(x-1,y); getch(); } /*SAMPLE INPUT*/ /*Enter the number of edges of polygon 4 X0 Y0 = 50 50 X1 Y1 = 200 50 X2 Y2 = 200 300 X3 Y3 = 50 300 Enter the seed point 100 100*/