📄 1-3.c
字号:
#include<graphics.h>/*加入c图形库*/
#include<math.h>/*数学库*/
#include<conio.h>/*键盘控制*/
void Bresenham_Line(int x0,int y0,int x1,int y1,int value)/*从坐标(x0,y0)到(x1,y1)画颜色为value的直线*/
{
int i;
int x,y,dx,dy;
float e;
dx=x1-x0;
dy=y1-y0;
e=-dx; x=x0; y=y0;
for(i=0;i<=dx;i++)
{
if(getch()==17)exit();/*读入键盘按键*/
putpixel(x,y,value);
x=x+1;
e=e+2*dy;
if(e>=0)
{
y=y+1;
e=e-2*dx;
}
}
}
void main()
{
int i,driver,mode;
driver=DETECT;/*初始化显示模式参数*/
initgraph(&driver,&mode,"..\\bgi");/*初始化显示为默认驱动的640*480、16色模式*/
printf("Press any key to continue except 'Ctrl+Q' to quit.\n");
Bresenham_Line(100,100,500,400,15);/*设置画线起始点*/
closegraph();/*关闭图形模式*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -