xref: /csrg-svn/lib/libplot/dumb/subr.c (revision 15442)
1 #ifndef lint
2 static char sccsid[] = "@(#)subr.c	4.1 (Berkeley) 11/10/83";
3 #endif
4 
5 #include "dumb.h"
6 
7 /* Does not plot first point -- assumed that it is already plotted */
8 dda_line(ch, x0, y0, x1, y1)
9 	char ch;
10 	int x0, y0;	/* already transformed to screen coords */
11 	int x1, y1;	/* untransformed */
12 {
13 	int length, i;
14 	double deltaX, deltaY;
15 	double x, y;
16 	double floor();
17 	int abs();
18 
19 	scale(x1, y1);
20 
21 	length = abs(x1 - x0);
22 	if (abs(y1 -y0) > length)
23 		length = abs(y1 - y0);
24 
25 	if (length == 0)
26 		return;
27 
28 	deltaX = (double) (x1 - x0)/(double) length;
29 	deltaY = (double) (y1 - y0)/(double) length;
30 
31 	x = (double) x0 + 0.5;
32 	y = (double) y0 + 0.5;
33 
34 	for (i=0; i < length; ++i) {
35 		x += deltaX;
36 		y += deltaY;
37 		x0 = floor(x);
38 		y0 = floor(y);
39 		currentx = x0;
40 		currenty = y0;
41 		screenmat[currentx][currenty] = ch;
42 	}
43 }
44