1、画图软件C程序代码#include #include #include #include #include #include #include #include /* 定义常量 */* 向上翻页移键 */#define PAGEUP 0x4900/* 向下翻页移键 */#define PAGEDOWN 0x5100/*Escape 键 */#define ESC 0x011b/* 左移键 */#define LEFT 0x4b00/* 右移键 */#define RIGHT 0x4d00/* 下移键 */#define DOWN 0x5000/* 上移键 */#define UP 0x4800
2、/* 空格键 */#define SPACE 0x3920#define NO_PRESSED 0#define LEFT_PRESSED 1#define RIGHT_PRESSED 2#define pi 3.1415926/* 定义全局变量 */int Rx,Ry,R;int TOPx,TOPy,BOTTOMx,BOTTOMy;int Centx,Centy;int lineStartx,lineStarty,lineEndx,lineEndy;int linePoint_x20,linePoint_y20;/*这里的字模数组均由“点阵字模工具”生成,你可以用你自己需要的点阵信息来 替换
3、示例中的字模信息,注意字模大小要一致,否则显示会出问题。 */ char zhi16K=/* 以下是 直 的 16点阵楷体 字模, 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 点阵楷体 字模,0x00,0x80,0x00,0x90,0x08,0x8
4、8,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 点阵楷体 字模,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
5、,0x00,0x00,0x00,0x00,0x00,;char xing16K=/* 以下是 形 的 16 点阵楷体 字模,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 点阵楷体 字模,0x00,0xF8,0x3F,0x08,0x23,0x88,0x24,0x88,0x
6、27,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 点阵楷体 字模,0x00,0x80,0x00,0xE0,0x33,0x80,0x10,0xE0,0x03,0x80,0x40,0xFC,0x2F,0x00,0x01,0xE0,0x12,0x20,0x13,0xA0,0x22,0x20,0x63,0xA0,32 byte */32 byte */32 byt
7、e */32 byte */32 byte */0x42,0x20,0x02,0x60,0x00,0x20,0x00,0x00,;char ping16K=/* 以下是 屏 的 16 点阵楷体 字模,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 点阵楷体 字模,0x00,
8、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 点阵楷体 字模,0x01,0x00,0x01,0x00,0x01,0xF0,0x1E,0x00,0x02,0x70,0x05,0x90,0x08,0x20,0x08,0x40,0x18,0x7E,0x2B,0xA0,0xC8,0x20,
9、0x08,0x20,0x08,0x20,0x08,0xA0,0x00,0x40,0x00,0x00,;char jia16K=/* 以下是 加 的 16 点阵楷体 字模,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 点阵楷体 字模,0x00,0x80,0x08,0xA0,
10、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 点阵楷体 字模,32 byte */32 byte */32 byte */32 byte */32 byte */32 byte */0x04,0x00,0x07,0x38,0x1C,0x48,0x06,0x50,0x1C,0x50,0x07,0x48,0x78
11、,0x58,0x11,0x40,0x21,0xF0,0x4F,0x10,0x09,0x10,0x09,0x50,0x09,0x20,0x01,0x00,0x01,0x00,0x00,0x00,;char zhu16K=/* 以下是 助 的 16点阵楷体 字模, 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
12、,;/* 自定义函数 */void outChinese(char *mat,int matsize,int x,int y,int color);void fill(int startx,int starty,int endx,int endy,int color);void showHelp();void save();void load();int mouseStatus(int* x,int* y);int setMousePos(int x, int y);void DrawMouse(float x,float y);void DrawLine();void DrawRectang
13、le();void LineToCircle(int x0,int y0,int r);void DrawCircle();long factorial(int n);float berFunction(int i,int n,double t);void DrawBezier();/* 根据点阵信息显示中文函数 */void outChinese(char *mat,int matsize,int x,int y,int color)/* 依次:字模指针、点阵大小、起始坐标 (x,y) 、颜色 */int i, j, k, n;n = (matsize - 1) / 8 + 1;for(j
14、= 0; j matsize; j+)for(i = 0; i n; i+)for(k = 0;k k) /*测试为 1 的位则显示 */ putpixel(x + i * 8 + k, y + j, color);/* 填充函数 */void fill(int startx,int starty,int endx,int endy,int color)int i,j;for(i=startx;i=endx;i+) for(j=starty;j=endy;j+)/* 在指定位置以指定颜色画一像素 */ putpixel(i,j,color);/* 显示用户帮助函数 */void showHel
15、p()setcolor(14);1 Press left button to start until to line end.);2 Use UP,DOWN,LEFT,RIGHT keys to move it.);3 Use PAGEUP key to enlarge it, and PAGEDOWN key to shrinkouttextxy(45,50,Line:); setcolor(WHITE); outtextxy(45,50, outtextxy(45,65, outtextxy(45,80,it.);outtextxy(45,95,4 Use SPACE key to rot
16、ate it.);setcolor(WHITE);outtextxy(45,120,outtextxy(45,135,outtextxy(45,150, shrink it.);setcolor(14);outtextxy(45,120,Rectangle:);1 Press left button to start until to right corner.);2 Use UP,DOWN,LEFT,RIGHT keys to move it.);3 Use PAGEUP key to enlarge it, and PAGEDOWN key tosetcolor(14);outtextxy
17、(45,170,Circle:);setcolor(WHITE);outtextxy(45,170,outtextxy(45,185,1 Press left button to start until to end.);2 Use PAGEUP key to enlarge it, and PAGEDOWN key toshrink it.); setcolor(14); outtextxy(45,205,Bezier:); setcolor(WHITE);outtextxy(45,205, Press left button to start, and right button to en
18、d.);outtextxy(45,230,Press ESC key to stop the operation function.); outtextxy(45,245,Press right button to end the drawing works.); outtextxy(45,260,Press any key to continue );getch(); fill(40,40,625,270,0);/* 保存函数 */void save()int i,j;FILE *fp; char fileName20;fill(0,447,630,477,2);gotoxy(1,25);p
19、rintf(nnnn Input the file name.dat:); scanf(%s,fileName);fill(0,447,630,477,2);/* 以读写的方式打开文件 */ if(fp=fopen(fileName,w+)=NULL) outtextxy(260,455,Failed to open file!); exit(0); outtextxy(280,455,saving.);/* 保存像素到文件 */ for(i=5;i630;i+) for(j=30;j=445;j+) fputc(getpixel(i,j),fp);fclose(fp);fill(0,447,
20、630,477,2);outtextxy(260,455,save over!);/* 打开函数 */void load()int i,j;char fileName20;FILE *fp;fill(0,447,630,477,2);gotoxy(1,25);printf(nnnn Input the file name.dat:); scanf(%s,fileName);/* 打开指定的文件 */ if(fp=fopen(fileName,r+)!=NULL) fill(0,447,630,477,2); outtextxy(280,455,loading.);/* 从文件中读出像素 */
21、for(i=5;i630;i+) for(j=30;j=10 & lineStarty=40 & lineEndx =620 & lineEndy =445)/* 清除原有的直线 */setwritemode(XOR_PUT); line(lineStartx,lineStarty,lineEndx,lineEndy);/*计算旋转 30 度后的起点坐标 */lineStartx=(temStartx-Centx)*cos(pi/6)-(temStarty-Centy)*sin(pi/6)+Centx;lineEndx=(temEndx-Centx)*cos(pi/6)-(temEndy-Ce
22、nty)*sin(pi/6)+Centx;/*计算旋转 30 度后的终点坐标 */lineStarty=(temStartx-Centx)*sin(pi/6)+(temStarty-Centy)*cos(pi/6)+Centy;lineEndy=(temEndx-Centx)*sin(pi/6)+(temEndy-Centy)*cos(pi/6)+Centy;temStartx=lineStartx;temStarty=lineStarty;temEndx=lineEndx;temEndy=lineEndy;/* 绘制旋转后的直线 */line(lineStartx,lineStarty,lineEndx,lineEndy);/* 左移直线 */if(key=LEFT)if(lineSt
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1