Complete C Program to demonstrate rectangles using putpixel and filling them with different fill effects
# Include <graphics.h>
# Include <conio.h>
# include <stdlib.h>
# include <dos.h>
void main()
{
int gm,gd= DETECT;
int x1,x2,y1,y2,c,I;
initgraph(&gd,&gm,’’’’);
while(!kbhit()) /* until pressing any key this loop continues */
{
/* To draw rectangle co-ordinatinates are taken randomly */
x1=rand()%getmaxx();
x2=rand()%getmaxx();
y1=rand()%getmaxy();
y2=rand()%getmaxy();
if (x1>x2)
{
c=x1; /* exchange of x1 and x2 when x1 is >x2 */
x1=x2;
x2=c;
}
if(y1>y2)
{
c=y1; /* exchange of y1 and y2 when y1 is > y2 */
y1=y2;
y2=c;
}
c=rand()%16;
/* for rectangle using putpixel */
for(I=x1 ;i<=x2;++i)
{
putpixel(I,y1,c);
delay (1);
}
for(i=y1;I<=y2;++i)
{
putpixel(x2,I,c);
delay(1);
}
for(i=x2;i>=x1; i)
{
putpixel(i,y2,c);
delay(1);
}
for(i=y2;I>=y1; i)
{
putpixel(x1,i,c);
delay(1);
}
setfillsytyle(rand()%12, rand()%8); /* setting the random fill styles and colors
*
floodfill(x1+1,y1+1,c);
delay(200); /* to draw the pixels slowly */
}
getch();
closegraph(); /* closes the graph mode */
}