- #include <graphics.h> //采用图库
- #include <conio.h> //控制台相应
- int colors=0; //全局变量,颜色赋初值0对应黑色
- int *pcolors=&colors;
- void change_color(int *x) //局部函数,改变格子颜色
- { if (*x) //设置线的颜色
- { setcolor(RGB(0,0,0));
- *x=0;
- }
- else
- { setcolor(RGB(255,255,255));
- *x=1;
- }
- };
- void main()
- { int x1,y1,x2,y2; //每次横线坐标
- int i,j; //横纵格子坐标
- initgraph(800,800); //初始化棋盘的大小
- setcolor(RGB(0,0,0)); //初始化格子颜色
- for(j=0; j<16; j++)
- { x1=0;
- y1=0; //原点坐标
- for (i=0; i<16; i++,x1+=50)
- { x2=x1+49;
- y2=y1; //终点坐标
- for (y1=0; y1<50; y1++)
- { line(x1,(y1+j*50),x2,(y1+j*50));
- }
- change_color(pcolors); //绘制一格之后,格子的颜色取反
- }
- change_color(pcolors); //每一行之后颜色取反
- }
- getch();
- closegraph();
- }
- //该片段来自于http://www.codesnippet.cn/detail/1809201410479.html
来源: http://www.codesnippet.cn/detail/1809201410479.html