if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* return with error code */
}
display();
closegraph();
return 0;
}
void display()
{
int x1 = 0, x2 = x1 + 300;
int y1 = 0, y2 = y1 + 200;
int i = 0;
for (; i < 16; ++i)
{
setfillstyle(SOLID_FILL, i);
bar(x1, y1, x2, y2);
drawTable(x1, y1+20, x2, y2, 10, 10);
drawLeftUp(x1, y1, x2, y2);
drawRightDown(x1, y1, x2, y2);
drawCaption("Multiple Table", x1, 0, x2, 20);
delay(1500);
}
return ;
}
void drawCaption(const char* buf, int x1, int y1, int x2, int y2, int color)
{
int tempColor = color;
int len = strlen(buf) * 8;
setcolor(BKCOLOR);
bar(x1, y1, x2, y2);
drawLeftUp(x1, y1, x2, y2);
drawRightDown(x1, y1, x2, y2);
drawLeftUp(x1, y2, x2, y2);
setcolor(0);
outtextxy(x1+8, y1+8, buf);
setcolor(FOCUSCOLOR);
outtextxy(x1+5, y1+5, buf);
setcolor(0);
line (x1+len+10, y1+7, x2-1, y1+7);
line (x1+len+10, y1+14, x2-1, y1+14);
setcolor(FOCUSCOLOR);
line (x1+len+10, y1+6, x2-1, y1+6);
line (x1+len+10, y1+13, x2-1, y1+13);
setcolor(tempColor);
}
void drawLeftUp(int x1, int y1, int x2, int y2, int color)
{
int tempColor = color;
setcolor(UPCOLOR);
line (x1, y1, x2, y1);
line (x1, y1, x1, y2);
setcolor(tempColor);
}
void drawRightDown(int x1, int y1, int x2, int y2, int color)
{
int tempColor = color;
setcolor(DOWNCOLOR);
line (x2, y1, x2, y2);
line (x1, y2, x2, y2);
setcolor(tempColor);
}
void drawTable(int x1, int y1, int x2, int y2, int Col, int Line, int color)
{
int tempColor = color;
int cellX = (x2 - x1) / Col;
int cellY = (y2 - y1) / Line;
int i = 1, j = 1;
int temp = 0;
setcolor(DOWNCOLOR);
for (i = 1; i < Col; ++i)
{
temp = i * cellX + x1;
line (temp, y1, temp, y2);
}
for (j = 1; j < Line; ++j)
{
temp = j * cellY + y1;
line (x1, temp, x2, temp);
}
setcolor (TEXTCOLOR);
fillTable (cellX, cellY);
setcolor (tempColor);
}
void fillTable(int cX, int cY)
{
int i = 1, j = 1;
int y = 0;
char buf[8];
for (j = 1; j < 10; ++j)
{
y = 20 + j*cY + (cY-8)/2;
for (i = 1; i < 10; ++i)
{
sprintf(buf, "%d", i * j);
outtextxy(i*cX + (cX-8)/2, y, buf);
}
}
for (i = 1; i < 10; ++i)
{
sprintf(buf, "%d", i);
outtextxy(i*cX + (cX-8)/2, 20 + (cY-8)/2, buf);
}
for (j = 1; j < 10; ++j)
{
sprintf(buf, "%d", j);
outtextxy(10, j*cY + 20 + (cY-8)/2, buf);
}
}