程序 Midpointline(]o, yo, xl, yl, color nt Xo, yU, xl,y l, col int a,b, dl, d2, 2, x,y a=y0-y1;b=x1-x0;d=2*a+b; dl=2*a;d2=2*(a+b) X=XO PutPixel(x y, color) while(x<xl) i if (d<o {x++;y++;d+=d2;} else i x++ d+=d1 PutPixel(x,y, color) 北大计算机系多媒体与人机交互 12北大计算机系多媒体与人机交互 12 程序 Midpointline(x0,y0,x1,y1,color) int x0,y0,x1,y1,color; { int a,b,d1,d2,2,x,y; a = y0-y1; b = x1 – x0; d = 2 * a +b; d1 = 2*a; d2 = 2*(a+b); x = x0; y = y0; PutPixel(x,y,color); while (x<x1) { if (d<0) { x++; y++; d +=d2;} else { x++; d +=d1;} PutPixel(x,y,color); } }