最近上课在学计算机图形学,第一个实验是用Bresenham算法画直线(可画出各种长度、宽度、斜率的直线),代码如下:
#include <winbgim.h>
#include <conio2.h>
#include <cmath>
void lineBres(int x0,int y0,int xend,int yend,unsigned int width);
int main()
{
initwindow(640,480); //open a 640x480 graphics window
lineBres(320,240,400,460,2);
lineBres(320,240,520,440,2);
lineBres(320,240,520,400,2);
lineBres(320,240,520,240,2);
lineBres(320,240,350,190,2);
lineBres(320,240,560,0,2);
lineBres(320,240,520,200,2);
lineBres(320,240,320,20,2);
lineBres(320,240,20,40,2);
lineBres(320,240,120,40,2);
lineBres(320,240,130,190,2);
lineBres(320,240,50,240,2);
lineBres(320,240,50,270,2);
lineBres(320,240,90,470,2);
lineBres(320,240,20,480,2);
lineBres(320,240,320,440,2);
getch(); //wait for user to press a key
closegraph(); //close graphics window
retu