/*_|_| CLASS13H.CPP PUBLIC DOMAIN Kurt Kuzba (6/11/1997)
_|_|_| Basic mode 13h class for C++. DOS. Not portable.
_|_|*/
#include
class GraphicsScreen {
public:
GraphicsScreen();
~GraphicsScreen();
void PutPixel(int, int, int);
int GetPixel(int, int);
void Box(int, int, int, int, int);
void Line(int, int, int, int, int);
void Circle(int, int, int, int);
private:
int abs(int a) {return (a < 0) ? -a : a;}
};
GraphicsScreen::GraphicsScreen()
{
_asm {
mov ax, 13h
int 10h
}
}
GraphicsScreen::~GraphicsScreen()
{
asm {
mov ax, 3h
int 10h
}
}
void GraphicsScreen::PutPixel(int x, int y, int c)
{
if(x 319 || y 199) return;
*((char*)0xA0000000L + x + (y << 8) + (y << 6)) = (char)c;
}
int GraphicsScreen::GetPixel(int x, int y)
{
if(x 319 || y 199) return 0;
return *((char*)0xA0000000L + x + (y << 8) + (y << 6));
}
void GraphicsScreen::Box(int x1,int y1,int x2,int y2, int c)
{
for(; x1 <= x2; x1++) Line(x1, y1, x1, y2, c);
}
void GraphicsScreen::Circle(int xc, int yc, int r, int c)
{ /*_|_| based on code in SNIPPETS -- BRESNHAM.C */
int x = 0, d = 2 * (1 - r), w = 2 * 320 / 200;
while(r >= 0)
{
PutPixel(xc + x, yc + r, c); PutPixel(xc + x, yc - r, c);
PutPixel(xc - x, yc + r, c); PutPixel(xc - x, yc - r, c);
if(d + r > 0) d -= (w * --r) - 1;
if(x > d) d += (2 * ++x) + 1;
}
}
void GraphicsScreen::Line(int x, int y, int x2, int y2, int c)
{ /*_|_| based on code in SNIPPETS -- BRESNHAM.C */
int i, steep = 0, sx, sy, dx, dy, e;
dx = abs(x2 - x); sx = ((x2 - x) > 0) ? 1 : -1;
dy = abs(y2 - y); sy = ((y2 - y) > 0) ? 1 : -1;
if(dy > dx)
{
steep = x; x = y; y = steep; /* swap x and y */
steep = dx; dx = dy; dy = steep; /* swap dx and dy */
steep = sx; sx = sy; sy = steep; /* swap sx and sy */
steep = 1;
}
e = 2 * dy - dx;
for(i = 0;i < dx;i++)
{
if(steep) PutPixel(y, x, c);
else PutPixel(x, y, c);
while(e >= 0) { y += sy; e -= 2 * dx; }
x += sx; e += 2 * dy;
}
PutPixel(x2, y2, c);
}
int main(void)
{
GraphicsScreen *gs = new GraphicsScreen;
int circumference;
gs->Box(100,100,200,200,0x13);
gs->PutPixel(150,150,0x2F);
for(circumference = 4; circumference < 50; circumference += 5)
gs->Circle(150, 150, circumference, 33);
getch();
delete gs;
return 0;
}
> ] Let's try randomly accessing YOUR memory once...............
---
---------------
* Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750)
|