⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 digline.c

📁 Graphics Gems 源码 a collection of algorithms, programs, and mathematical techniques for the computer
💻 C
字号:
/* * Digital Line Drawing * by Paul Heckbert * from "Graphics Gems", Academic Press, 1990 *//* * digline: draw digital line from (x1,y1) to (x2,y2), * calling a user-supplied procedure at each pixel. * Does no clipping.  Uses Bresenham's algorithm. * * Paul Heckbert	3 Sep 85 */#include "GGems.h"digline(x1, y1, x2, y2, dotproc)int x1, y1, x2, y2;void (*dotproc)();{    int d, x, y, ax, ay, sx, sy, dx, dy;    dx = x2-x1;  ax = ABS(dx)<<1;  sx = SGN(dx);    dy = y2-y1;  ay = ABS(dy)<<1;  sy = SGN(dy);    x = x1;    y = y1;    if (ax>ay) {		/* x dominant */	d = ay-(ax>>1);	for (;;) {	    (*dotproc)(x, y);	    if (x==x2) return;	    if (d>=0) {		y += sy;		d -= ax;	    }	    x += sx;	    d += ay;	}    }    else {			/* y dominant */	d = ax-(ay>>1);	for (;;) {	    (*dotproc)(x, y);	    if (y==y2) return;	    if (d>=0) {		x += sx;		d -= ay;	    }	    y += sy;	    d += ax;	}    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -