C语言 百分网手机站

如何实现C语言画图教程

时间:2020-11-19 08:22:43 C语言 我要投稿

如何实现C语言画图教程

  C语言有丰富的数据结构和运算符。包含了各种数据结构,如整型、数组类型、指针类型和联合类型等,用来实现各种数据结构的运算。以下是小编为大家搜索整理的C语言如何实现画图教程,希望能给大家带来帮助!更多精彩内容请及时关注我们考试网!

  程序中定义了几个特殊键:

  "V”:画笔提起

  "W”:开始画图

  "R”:开始擦图

  "S”:当前图形存入文件

  "E”:调出已有文件

  "C”:画圆

  程序一运行,屏幕上出现一个黄色的边框来设定画图的`区域,区域中间出现提起的画笔符号 ,当按下”W“键时,画笔符号变为 ,此时可移动方向键(上、下、左、右、左上、左下、右上、右下)来画图;当按下”R“键时,画笔符号变为 ,此时可移动方向键来擦图;在画图过程中,按下“C”键,可画出一个半径为20个象素点的圆;当结束画图时,按下“S”键,将画好的图形存盘;按下“E”键可调出已有的图形进行编辑。

  3.源程序清单

  # include "graphics.h"

  # include "stdio.h"

  # include "fcntl.h"

  # include "stdlib.h"

  main()

  void save(),load();

  void *wg,*rg,*vg,*fy;

  int driver,mode;

  int c=RED;

  int x=320,y=225;

  int x1,y1,x2,y2;

  int k,k1,k2;

  /* initialize grapher */

  detectgraph(&driver,&mode);

  initgraph(&driver,&mode,"c: c");

  /* write the pen */

  bar(200,10,206,16);

  line(203,7,200,10);

  line(203,7,206,10);

  line(243,7,240,16);

  line(243,7,246,16);

  line(283,7,280,10);

  line(283,7,286,10);

  line(283,7,283,16);

  /* save the pen */

  wg=malloc(imagesize(200,7,206,16));

  rg=malloc(imagesize(240,7,246,16));

  vg=malloc(imagesize(280,7,286,16));

  fy=malloc(imagesize(200,7,206,16));

  getimage(200,7,206,16,wg);

  getimage(240,7,246,16,rg);

  getimage(280,7,286,16,vg);

  cleardevice();

  /* write the box */

  setcolor(YELLOW);

  rectangle(4,19,637,447);

  x1=x-3;

  y1=y+1;

  x2=x+3;

  y2=y+10;

  getimage(x1,y1,x2,y2,fy);

  putimage(x1,y1,vg,XOR_PUT);

  /* receive the command */

  for (;;)

  while (bioskey(1)==0);

  k=bioskey(0);

  putimage(x1,y1,fy,AND_PUT);

  if (((k&0x00ff)|0x00)==0)

  k1=k&0xff?0:k>>8; /* k1 is the specialkey value */

  else

  k2=k&0x00ff; /* k2 is the non-specialkey value */

  if (((k&0x00ff)|0x00)==0) /* Special key */

  switch(k1)

  case 45:

  restorecrtmode();

  exit(0);

  case 72:

  if (y>20)

  y=y-1;

  break;

  case 75:

  if (x>5)

  x=x-1;

  break;

  case 77:

  if (x<636)

  x=x+1;

  break;

  case 80:

  if (y<446)

  y=y+1;

  break;

  case 71:

  if ((x>5)&&(y>20))

  x=x-1;

  y=y-1;

  break;

  case 79:

  if ((x>5)&&(y<446))

  x=x-1;

  y=y+1;

【如何实现C语言画图教程】相关文章:

1.c语言中怎么画图

2.如何实现C语言多个函数值的返回

3.C语言的HashTable简单实现

4.C语言常用库函数实现

5.冒泡排序(C语言实现)

6.希尔排序(C语言实现)

7.C 语言基础教程

8.如何学习c语言