Scanline

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include<stdio.

h>
#include<conio.h>
#include<math.h>
#include<dos.h>
#include<graphics.h>
#include<stdlib.h>
void scanfill(float x1,float y1,float x2,float y2,float x3,float y3,float x4,flo
at y4,int colr);
void edgedetect(float x1,float y1,float x2,float y2,int *le,int *re);
void main()
{
int colr=4;
float x1,x2,x3,x4,y1,y2,y3,y4;
int gd,gm,n,i,x,y,a[10][10];
gd=DETECT;
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
x1=100;
y1=150;
x2=150;
y2=250;
x3=250;
y3=300;
x4=300;
y4=150;
scanfill(x1,y1,x2,y2,x3,y3,x4,y4,colr);
getch();
// getch();
}
void scanfill(float x1,float y1,float x2,float y2,float x3,float y3,float x4,flo
at y4,int colr)
{
int le[480];
int re[480];
for(int i=0;i<480;i++)
{
le[i]=640;
re[i]=0;
}
edgedetect(x1,y1,x2,y2,le,re);
edgedetect(x2,y2,x3,y3,le,re);
edgedetect(x3,y3,x4,y4,le,re);
edgedetect(x4,y4,x1,y1,le,re);
int y;
for(y=0;y<480;y++)
{
if(le[y]<re[y])
{
for(i=le[y];i<=re[y];i++)
{
delay(1);
putpixel(i,y,colr);

}
}
}
}
void edgedetect(float x1,float y1,float x2,float y2,int *le,int *re)
{
float m,x;
int i,temp;
if((y2-y1)<0)
{
temp=x1;
x1=x2;
x2=temp;
temp=y1;
y1=y2;
y2=temp;
}
if((y2-y1)!=0)
m=(float)((x2-x1)/(y2-y1));
else
{
m=x2-x1;
}
x=x1;
for(i=y1;i<=y2;i++)
{
if(x<le[i])
{
le[i]=x;
}
if(x>re[i])
{
re[i]=x;
}
x+=m;
}
}

You might also like