xref: /csrg-svn/lib/libplot/dumb/subr.c (revision 61365)
148505Sbostic /*-
2*61365Sbostic  * Copyright (c) 1980, 1993
3*61365Sbostic  *	The Regents of the University of California.  All rights reserved.
448505Sbostic  *
548505Sbostic  * %sccs.include.proprietary.c%
619971Sdist  */
719971Sdist 
815442Sralph #ifndef lint
9*61365Sbostic static char sccsid[] = "@(#)subr.c	8.1 (Berkeley) 06/04/93";
1048505Sbostic #endif /* not lint */
1115442Sralph 
1215442Sralph #include "dumb.h"
1315442Sralph 
1415442Sralph /* Does not plot first point -- assumed that it is already plotted */
1515442Sralph dda_line(ch, x0, y0, x1, y1)
1615442Sralph 	char ch;
1715442Sralph 	int x0, y0;	/* already transformed to screen coords */
1815442Sralph 	int x1, y1;	/* untransformed */
1915442Sralph {
2015442Sralph 	int length, i;
2115442Sralph 	double deltaX, deltaY;
2215442Sralph 	double x, y;
2315442Sralph 	double floor();
2415442Sralph 	int abs();
2515442Sralph 
2615442Sralph 	scale(x1, y1);
2715442Sralph 
2815442Sralph 	length = abs(x1 - x0);
2915442Sralph 	if (abs(y1 -y0) > length)
3015442Sralph 		length = abs(y1 - y0);
3115442Sralph 
3215442Sralph 	if (length == 0)
3315442Sralph 		return;
3415442Sralph 
3515442Sralph 	deltaX = (double) (x1 - x0)/(double) length;
3615442Sralph 	deltaY = (double) (y1 - y0)/(double) length;
3715442Sralph 
3815442Sralph 	x = (double) x0 + 0.5;
3915442Sralph 	y = (double) y0 + 0.5;
4015442Sralph 
4115442Sralph 	for (i=0; i < length; ++i) {
4215442Sralph 		x += deltaX;
4315442Sralph 		y += deltaY;
4415442Sralph 		x0 = floor(x);
4515442Sralph 		y0 = floor(y);
4615442Sralph 		currentx = x0;
4715442Sralph 		currenty = y0;
4815442Sralph 		screenmat[currentx][currenty] = ch;
4915442Sralph 	}
5015442Sralph }
51