Skip to content

Instantly share code, notes, and snippets.

@vertrigo
Created May 15, 2013 19:20
Show Gist options
  • Save vertrigo/5586577 to your computer and use it in GitHub Desktop.
Save vertrigo/5586577 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <graphics.h>
#include <dos.h>
class gr_init
{
public:
gr_init(int driver=0)
{
*gd=driver;
initgraph(gd,gm,"c:\\TurboC3\\BGI");
if (graphresult() !=0 ) {printf("Error!'");abort();}
}
~gr_init()
{
closegraph();
}
private:
int *gd,*gm;
};
class gr_obj
{
public:
gr_obj(int col=7) { _color=col; }
virtual void draw()=0;
int color() { return _color; }
void show() { setcolor(color()); draw(); }
void hide()
{
cback=getcolor();
setcolor(getbkcolor());
draw();
setcolor(color());
}
private:
int _color,cback;
};
class krug: public gr_obj
{
public:
krug(int xc=0, int yc=0, int rad=0, int col=7): gr_obj(col)
{
r=rad;
show();
setpx(xc);
setpy(yc);
}
~krug() { hide(); }
int getpx() { return x; }
int getpy() { return y; }
int getrad() { return r; }
void setpx(int px) { x=px; }
void setpy(int py) { y=py; }
void setrad(int rad) { r=rad; }
void draw(){ circle(getpx(),getpy(),getrad()); }
private:
int r,x,y;
};
void main()
{
gr_init gr(0);
krug kr(180,230,70);
krug kr2(420,230,70);
for (int i = 1; i < 30; i++)
{
if (i%2 == 0)
{
kr.hide();
}
else
{
kr.show();
}
if (i%2 != 0 && i != 29)
{
kr2.hide();
}
else
{
kr2.show();
}
delay(70);
}
getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment