/*
* 文件名称:HuaTuBan.c
* 当前版本:1.2
* (修正绘制圆形sqrt domain error,半径过大边界问题;
* 修正Bezier曲线边界问题;
* 改进保存 加载过程不能实时退出问题。
* )
* 作 者:刘昆 (计算机0781)
* 完成日期:2010年10月2日
*
* 取代版本:1.1
* 作 者:刘昆 (计算机0781)
* 完成日期:2010年9月29日
*/
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
#define NO_PRESS 0
#define LEFT_PRESS 1
#define RIGHT_PRESS 2
#define pi 3.14159
#define ESC 0x11b
#define SPACE 0x3920
int pointX[20];
int pointY[20];
char zhi16K[]={
/* 以下是 '直' 的 16点阵楷体_GB2312 字模,32 byte */
0x01,0x00,0x01,0x00,0x01,0xF0,0x1E,0x00,
0x02,0x00,0x07,0xC0,0x08,0x40,0x0F,0x40,
0x08,0x40,0x0F,0x40,0x08,0x40,0x0F,0x40,
0x08,0x40,0x0F,0xFC,0x70,0x00,0x00,0x00,
};
char xian16K[]={
/* 以下是 '线' 的 16点阵楷体_GB2312 字模,32 byte */
0x00,0x80,0x00,0x90,0x08,0x88,0x10,0x80,
0x24,0xF0,0x45,0x80,0x78,0xB0,0x11,0xC0,
0x2C,0x88,0x70,0x50,0x04,0x60,0x18,0xA4,
0x63,0x14,0x00,0x0C,0x00,0x04,0x00,0x00,
};
char ju16K[]={
/* 以下是 '矩' 的 16点阵楷体_GB2312 字模,32 byte */
0x00,0x00,0x08,0x00,0x08,0x78,0x10,0x80,
0x1E,0x80,0x28,0xF8,0x48,0x88,0x0E,0x88,
0xF8,0xF0,0x08,0x80,0x14,0x80,0x12,0x9E,
0x20,0xE0,0x40,0x00,0x00,0x00,0x00,0x00,
};
char xing16K[]={
/* 以下是 '形' 的 16点阵楷体_GB2312 字模,32 byte */
0x00,0x00,0x07,0x88,0x3A,0x08,0x12,0x10,
0x12,0x20,0x17,0x48,0xFA,0x10,0x12,0x20,
0x12,0xC8,0x12,0x08,0x22,0x10,0x42,0x20,
0x00,0x40,0x00,0x80,0x03,0x00,0x00,0x00,
};
char yuan16K[]={
/* 以下是 '圆' 的 16点阵楷体_GB2312 字模,32 byte */
0x00,0xF8,0x3F,0x08,0x23,0x88,0x24,0x88,
0x27,0x08,0x21,0xC8,0x2E,0x48,0x29,0x48,
0x29,0x48,0x22,0x88,0x24,0x48,0x28,0x08,
0x3F,0xE8,0x00,0x10,0x00,0x00,0x00,0x00,
};
char qing16K[]={
/* 以下是 '清' 的 16点阵楷体_GB2312 字模,32 byte */
0x00,0x80,0x00,0xE0,0x33,0x80,0x10,0xE0,
0x03,0x80,0x40,0xFC,0x2F,0x00,0x01,0xE0,
0x12,0x20,0x13,0xA0,0x22,0x20,0x63,0xA0,
0x42,0x20,0x02,0x60,0x00,0x20,0x00,0x00,
};
char ping16K[]={
/* 以下是 '屏' 的 16点阵楷体_GB2312 字模,32 byte */
0x00,0xF0,0x0F,0x30,0x08,0x60,0x0F,0x80,
0x0A,0x20,0x09,0x40,0x08,0xF8,0x17,0x20,
0x11,0x3E,0x2F,0xE0,0x21,0x20,0x42,0x20,
0x82,0x20,0x04,0x20,0x08,0x20,0x00,0x00,
};
char bao16K[]={
/* 以下是 '保' 的 16点阵楷体_GB2312 字模,32 byte */
0x00,0x00,0x09,0xF0,0x0A,0x10,0x12,0x10,
0x13,0xE0,0x30,0x80,0x50,0xFC,0x9F,0x80,
0x11,0xC0,0x12,0xA0,0x14,0x98,0x18,0x8E,
0x10,0x80,0x10,0x80,0x00,0x00,0x00,0x00,
};
char cun16K[]={
/* 以下是 '存' 的 16点阵楷体_GB2312 字模,32 byte */
0x01,0x00,0x01,0x00,0x01,0xF0,0x1E,0x00,
0x02,0x70,0x05,0x90,0x08,0x20,0x08,0x40,
0x18,0x7E,0x2B,0xA0,0xC8,0x20,0x08,0x20,
0x08,0x20,0x08,0xA0,0x00,0x40,0x00,0x00,
};
char jia16K[]={
/* 以下是 '加' 的 16点阵楷体_GB2312 字模,32 byte */
0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
0x0F,0x00,0x79,0x3C,0x09,0x44,0x11,0x44,
0x11,0x44,0x22,0x44,0x22,0x78,0x4A,0x00,
0x84,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
char zai16K[]={
/* 以下是 '载' 的 16点阵楷体_GB2312 字模,32 byte */
0x00,0x80,0x08,0xA0,0x08,0x90,0x0E,0x80,
0x38,0xF0,0x0F,0x80,0x78,0x50,0x0E,0x50,
0x34,0x20,0x1E,0x20,0x34,0x50,0x0E,0x92,
0x75,0x0A,0x04,0x06,0x04,0x02,0x00,0x00,
};
char bang16K[]={
/* 以下是 '帮' 的 16点阵楷体_GB2312 字模,32 byte */
0x04,0x00,0x07,0x38,0x1C,0x48,0x06,0x50,
0x1C,0x50,0x07,0x48,0x78,0x58,0x11,0x40,
0x21,0xF0,0x4F,0x10,0x09,0x10,0x09,0x50,
0x09,0x20,0x01,0x00,0x01,0x00,0x00,0x00,
};
char zhu16K[]={
/* 以下是 '助' 的 16点阵楷体_GB2312 字模,32 byte */
0x00,0x00,0x00,0x20,0x0C,0x20,0x34,0x20,
0x24,0x20,0x34,0x38,0x25,0xC8,0x34,0x48,
0x24,0x48,0x26,0x88,0x38,0x88,0xE1,0x28,
0x02,0x10,0x04,0x00,0x00,0x00,0x00,0x00,
};
/*
功能:显示汉字 x+j*8+k,y+i
00000001 0000000
00000001 0000000
00100001 0000100
*/
void showChinese(char *zimo,int x,int y,int maxsize,int color)
{
int i;
int j;
int k;
int n;
n = (maxsize-1)/8 + 1;
for (i=0; i<maxsize; i++)
{
for (j=0; j<n; j++)
{
for (k=0; k<8; k++) /*字模转换成二进制8位*/
{
if(zimo[i*n+j] & (0x80>>k)) /*探测每位是否为1,0x80为10000000*/
{
putpixel(x+j*8+k,y+i,color);
}
}
}
}
}
/*功能:用于以指定的填充区域*/
void fillCol(int startx,int starty,int endx,int endy,int color)
{
int i;
int j;
for (i=startx; i<=endx; i++)
{
for (j=starty; j<=starty; j++)
{
putpixel(i,j,color);
}
}
}
/*功能:帮助信息,介绍怎么操作*/
void showHelp()
{
setfillstyle(0,0);
bar(100,40,630,445);
outtextxy(145,150,"Press left button to start until the action is finished");
outtextxy(145,205,"Press left button to start, and right button to end.");
outtextxy(145,245,"Press right button to end the drawing works.");
outtextxy(145,260,"Press any key to continue......");
getch();
setfillstyle(0,0);
bar(100,40,630,445);
}
/*功能:保存画布中的图形*/
void save()
{
int i,j;
FILE *fp;
char fileName[20];
int key;
int xun=1;
int flag=0;
fillCol(0,447,630,477,2);
gotoxy(1,25);
printf("\n\n\n\n press esc to exit,Input the filename press space:");
while (xun)
{
if (bioskey(1))
{
key=bioskey(0);
}
else
{
key=0;
}
switch(key)
{
case ESC:
flag=1;
xun=0;
break;
case SPACE:
gets(fileName);
xun=0;
break;
}
}
if (flag==1)
{
goto end;
}
fillCol(0,447,630,477,2);
/*以读写的方式打开文件*/
if ((fp=fopen(fileName,"wb+")) == NULL)
{
outtextxy(260,455,"Failed to open file!");
goto end;
}
outtextxy(500,455,"saving...");
/*100,40,630,445保存像素到文件*/
for(i=100; i<630; i++)
{
for(j=40; j<=445; j++)
{
fputc(getpixel(i,j),fp);
}
}
end:fclose(fp);
setfillstyle(1,2);
bar(0,445,630,477);
outtextxy(260,455,"save over!");
delay(10000);
setfillstyle(1,2);
bar(0,445,630,477);
}
/*功能:打开已有的图形*/
void load()
{
int i;
int j;
FILE *fp;
int key;
int xun=1;
int flag=0;
char fileName[20];
fillCol(0,447,630,477,2);
gotoxy(1,25);
printf("\n\n\n\n press esc to exit,Input the filename press space:");
while (xun)
{
if (bioskey(1))
{
key=bioskey(0);
}
else
{
key=0;
}
switch(key)
{
case ESC:
flag=1;
xun=0;
break;
case SPACE:
gets(fileName);
xun=0;
break;
}
}
if (flag==1)
{
goto end;
}
fillCol(0,447,630,477,2);
if ((fp=fopen(fileName,"rb+"))== NULL)
{
outtextxy(260,455,"Failed to open file!");
goto end;
}
for(i=100; i<630; i++)
{
for(j=40; j<=445; j++)
{
putpixel(i,j,fgetc(fp));
}
}
end:fclose(fp);
delay(10000);
setfillstyle(1,2);
bar(0,445,630,477);
}
/************************************/
/*
功能:获取鼠标状态、鼠标位置(水平、垂直)以及按键情况
*/
i