#include<iostream.h>
#include<graphics.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
/*************************************************************************///------------------------------ rect ---------------------------------///*************************************************************************/class rect
{
public:
void draw_rect(int,int,int,int,int);
};
/*************************************************************************///---------------------------- fill_rect ------------------------------///*************************************************************************/class fill_rect:public rect
{
public:
void draw_rect(int,int,int,int,int,int,int);
};
/*************************************************************************///--------------------------- animate_rect ----------------------------///*************************************************************************/class animate_rect:public fill_rect
{
public:
void draw_rect(int,int,int,int,int,int,int);
};
/*************************************************************************///---------------- draw_rect(int,int,int,int,int) ---------------------///*************************************************************************/void rect::draw_rect(int x1,int y1,int x2,int y2,int boundry_color)
{
setcolor(boundry_color);
rectangle(x1,y1,x2,y2);
}
/*************************************************************************///------------ draw_rect(int,int,int,int,int,int,int) -----------------///*************************************************************************/void fill_rect::draw_rect(int x1,int y1,int x2,int y2,int boundry_color,
int pattern,int pattern_color)
{
rect::draw_rect(x1,y1,x2,y2,boundry_color);
struct fillsettingstype t;
getfillsettings(&t);
setfillstyle(pattern,pattern_color);
floodfill(x1+1,y1+1,boundry_color);
setfillstyle(t.pattern,t.color);
}
/*************************************************************************///------------- draw_rect(int,int,int,int,int,int,int) ----------------///*************************************************************************/void animate_rect::draw_rect(int x1,int y1,int x2,int y2,int boundry_color,
int pattern,int pattern_color)
{
fill_rect::draw_rect(x1,y1,x2,y2,boundry_color,pattern,pattern_color);
int size=imagesize(x1,y1,x2,y2);
char *p;
p=newchar[size];
getimage(x1,y1,x2,y2,p);
putimage(x1+100,y1+100,p,XOR_PUT);
int x;
int y;
while(!kbhit())
{
x=random(getmaxx());
y=y2+random(getmaxy());
putimage(x,y,p,OR_PUT);
delay(100);
putimage(x,y,p,XOR_PUT);
}
}
main()
{
clrscr();
int graphic_driver=DETECT;
int graphic_mode;
int errorcode;
initgraph(&graphic_driver,&graphic_mode,"..\\bgi");
errorcode=graphresult();
if(errorcode!=grOk)
{
restorecrtmode();
cout<<"Graphic Error";
exit(1);
}
rect x;
x.draw_rect(20,20,150,150,4);
fill_rect y;
y.draw_rect(210,20,350,100,14,1,13);
animate_rect z;
z.draw_rect(400,20,530,100,14,7,10);
getch();
closegraph();
return 0;
}