xref: /original-bsd/lib/libplot/dumb/subr.c (revision c3e32dec)
1 /*-
2  * Copyright (c) 1980, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)subr.c	8.1 (Berkeley) 06/04/93";
10 #endif /* not lint */
11 
12 #include "dumb.h"
13 
14 /* Does not plot first point -- assumed that it is already plotted */
15 dda_line(ch, x0, y0, x1, y1)
16 	char ch;
17 	int x0, y0;	/* already transformed to screen coords */
18 	int x1, y1;	/* untransformed */
19 {
20 	int length, i;
21 	double deltaX, deltaY;
22 	double x, y;
23 	double floor();
24 	int abs();
25 
26 	scale(x1, y1);
27 
28 	length = abs(x1 - x0);
29 	if (abs(y1 -y0) > length)
30 		length = abs(y1 - y0);
31 
32 	if (length == 0)
33 		return;
34 
35 	deltaX = (double) (x1 - x0)/(double) length;
36 	deltaY = (double) (y1 - y0)/(double) length;
37 
38 	x = (double) x0 + 0.5;
39 	y = (double) y0 + 0.5;
40 
41 	for (i=0; i < length; ++i) {
42 		x += deltaX;
43 		y += deltaY;
44 		x0 = floor(x);
45 		y0 = floor(y);
46 		currentx = x0;
47 		currenty = y0;
48 		screenmat[currentx][currenty] = ch;
49 	}
50 }
51