home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d2xx
/
d222
/
plplot.lha
/
Plplot
/
src
/
source.zoo
/
genlin.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-05-15
|
2KB
|
103 lines
/* General line-drawing routine which takes line styles into account */
#include "plplot.h"
#include "declare.h"
#include <math.h>
static int lastx=-100000, lasty=-100000;
void genlin(x1,y1,x2,y2)
int x1,y1,x2,y2;
{
int nx,ny;
int modulo, incr, dx, dy, diax, diay, i, temp, x, y;
int px, py, tstep;
/* Check for solid line */
if (nms == 0) {
grline(x1,y1,x2,y2);
return;
}
/* Check if pattern needs to be restarted */
if (x1 != lastx || y1 != lasty) {
curel = 0;
pendn = 1;
timecnt = 0;
alarm = mark[curel];
if (x1 == x2 && y1 == y2) grline(x1,y1,x2,y2);
}
lastx = x1;
lasty = y1;
if (x1 == x2 && y1 == y2) return;
nx = x2 - x1;
ny = y2 - y1;
if (abs(ny) > abs(nx)) {
modulo = abs(ny);
incr = abs(nx);
dx = 0;
dy = -1;
if (ny > 0) dy = 1;
}
else {
modulo = abs(nx);
incr = abs(ny);
dx = -1;
if (nx > 0) dx = 1;
dy = 0;
}
diax = -1;
if (nx > 0) diax = 1;
diay = -1;
if (ny > 0) diay = 1;
temp = modulo/2;
x = x1;
y = y1;
i = 1;
/* Compute the timer step */
tstep = sqrt(pow((double)(abs(nx)*umx),2.)+
pow((double)(abs(ny)*umy),2.))/modulo;
loop:
if (i > modulo) goto exit;
i = i+1;
temp = temp+incr;
px = x;
py = y;
if (temp > modulo) {
temp = temp-modulo;
x = x + diax;
y = y + diay;
}
else {
x = x + dx;
y = y + dy;
}
timecnt += tstep;
if (timecnt >= alarm) {
plupd();
if (pendn == 0) grline(lastx,lasty,px,py);
lastx = x;
lasty = y;
}
goto loop;
exit:
if (pendn != 0) grline(lastx,lasty,x,y);
lastx = x2;
lasty = y2;
}