#include <stdio.h>
#include <conio.h>
#include <graphics.h>
main()
{
int n,i,j,k,gd,gm,dy,dx;
int x,y,temp;
int a[20][2],xi[20];
float slope[20];
clrscr();
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];
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:tcbgi");
/*- draw polygon -*/
for(i=0;i<n;i++)
{
line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]);
}
getch();
for(i=0;i<n;i++)
{
dy=a[i+1][1]-a[i][1];
dx=a[i+1][0]-a[i][0];
if(dy==0) slope[i]=1.0;
if(dx==0) slope[i]=0.0;
if((dy!=0)&&(dx!=0)) /*- calculate inverse slope -*/
{
slope[i]=(float) dx/dy;
}
}
for(y=0;y< 480;y++)
{
k=0;
for(i=0;i<n;i++)
{
if( ((a[i][1]<=y)&&(a[i+1][1]>y))||
((a[i][1]>y)&&(a[i+1][1]<=y)))
{
xi[k]=(int)(a[i][0]+slope[i]*(y-a[i][1]));
k++;
}
}
for(j=0;j<k-1;j++) /*- Arrange x-intersections in order -*/
for(i=0;i<k-1;i++)
{
if(xi[i]>xi[i+1])
{
temp=xi[i];
xi[i]=xi[i+1];
xi[i+1]=temp;
}
}
setcolor(35);
for(i=0;i<k;i+=2)
{
line(xi[i],y,xi[i+1]+1,y);
getch();
}
}
}

More Related Content

DOC
Doi xung mang mot chieu
TXT
Pruebabfs
PDF
Alocação Dinâmica em C
TXT
Bai lam chuong 3
DOCX
[程式設計]標準差
PDF
Bubble sort
PDF
Heep implementation in c
PDF
Doi xung mang mot chieu
Pruebabfs
Alocação Dinâmica em C
Bai lam chuong 3
[程式設計]標準差
Bubble sort
Heep implementation in c

What's hot (20)

PDF
Bcsl 033 data and file structures lab s1-2
DOCX
TXT
N primo clase programa
TXT
C Program : Sorting : Bubble,
DOCX
Fcfs Cpu Scheduling With Gantt Chart
PDF
Quick sort
DOC
Tugas4
DOCX
listing output program C
DOCX
Dado un vector imprimir cuantas vocales tiene
PDF
Bcsl 033 data and file structures lab s4-3
DOCX
Rafaeltorres
PDF
contoh Program C++ tentang fungsi for
DOCX
Info clasa
DOC
Ejercicios.
DOCX
Memoria dinámica ejercicio
DOC
Sources
PDF
07 5 반복문(break,contine).key
DOC
Cg lab cse-vii
Bcsl 033 data and file structures lab s1-2
N primo clase programa
C Program : Sorting : Bubble,
Fcfs Cpu Scheduling With Gantt Chart
Quick sort
Tugas4
listing output program C
Dado un vector imprimir cuantas vocales tiene
Bcsl 033 data and file structures lab s4-3
Rafaeltorres
contoh Program C++ tentang fungsi for
Info clasa
Ejercicios.
Memoria dinámica ejercicio
Sources
07 5 반복문(break,contine).key
Cg lab cse-vii
Ad

Viewers also liked (11)

PPTX
3Com 3C17260-NEW
PDF
Need for reliable statistics
PPTX
3Com 3CNJ225FX-SC
DOCX
정품남성발기제 『 W6.ow.to 』 톡 w2015 ♡ 남성발기제판매,남성발기제 효능,남성발기제 성분,남성발기제 종류, 남성발기제 치사량,...
PPT
ODP
Crise democracia fascismos
PDF
compassionate care car pool to school
PPTX
The Student Survival sMOOC - Designing and Piloting a course in partnership w...
PPTX
TEST 2013 INFORMATICA
PDF
¿Cómo atacan los patógenos a las plantas?
PPTX
New microsoft power point presentation
3Com 3C17260-NEW
Need for reliable statistics
3Com 3CNJ225FX-SC
정품남성발기제 『 W6.ow.to 』 톡 w2015 ♡ 남성발기제판매,남성발기제 효능,남성발기제 성분,남성발기제 종류, 남성발기제 치사량,...
Crise democracia fascismos
compassionate care car pool to school
The Student Survival sMOOC - Designing and Piloting a course in partnership w...
TEST 2013 INFORMATICA
¿Cómo atacan los patógenos a las plantas?
New microsoft power point presentation
Ad

More from Sonia Pahuja (14)

DOCX
numerical method solutions
DOCX
Bisection method solved questions
PPTX
raster and random scan
PPTX
Graphics exercise (b.tech)
PPT
graphics notes
PPTX
Graphics exercise (b.tech)
PPT
Surajkund Mella Faridabad
PPT
Business Ethics
TXT
Determinant Matlab Code
TXT
Gaussel Method
TXT
CODE Data Structures
DOCX
DATABASE MANAGEMENT SYSTEM
PPT
Introduction to sets
PPT
Data Link Control
numerical method solutions
Bisection method solved questions
raster and random scan
Graphics exercise (b.tech)
graphics notes
Graphics exercise (b.tech)
Surajkund Mella Faridabad
Business Ethics
Determinant Matlab Code
Gaussel Method
CODE Data Structures
DATABASE MANAGEMENT SYSTEM
Introduction to sets
Data Link Control

Scanfill polygon