i experimented with bresenhams linedraw algorithm a while ago. maybe it's helpful for you:
Code:
var video_mode=8;
var video_depth=32;
on_f5=null;
string debug;
bmap bmp_arrow=<arrow_blue.pcx>;
bmap bmp_canvas=<canvas.tga>; //1024x768 black
panel canvas
{
bmap=bmp_canvas;
flags=d3d,refresh,visible;
}
function putpixel(x,y)
{
var format;
var pixel;
format=bmap_lock(bmp_canvas,0);
pixel=pixel_for_vec(vector(255,255,255),null,888);
pixel_to_bmap(bmp_canvas,x,y,pixel);
bmap_unlock(bmp_canvas);
}
function line(x1,y1,x2,y2) //bresenham algorithm
{
var x;
var y;
var dx;
var dy;
var incx;
var incy;
var balance;
if(x2>=x1)
{
dx=x2-x1;
incx=1;
}
else
{
dx=x1-x2;
incx=-1;
}
if(y2>=y1)
{
dy=y2-y1;
incy=1;
}
else
{
dy=y1-y2;
incy=-1;
}
x=x1;
y=y1;
if(dx>=dy)
{
dy=dy<<1;
balance=dy-dx;
dx=dx<<1;
while(x!=x2)
{
putpixel(x,y);
if(balance>=0)
{
y+=incy;
balance-=dx;
}
balance+=dy;
x+=incx;
}
putpixel(x,y);
}
else
{
dx=dx<<1;
balance=dx-dy;
dy=dy<<1;
while(y!=y2)
{
putpixel(x,y);
if(balance>=0)
{
x+=incx;
balance-=dy;
}
balance+=dx;
y+=incy;
}
putpixel(x,y);
}
}
function main()
{
var ox;
var oy;
var cx;
var cy;
mouse_map=bmp_arrow;
mouse_mode=2;
while(1)
{
mouse_pos.x=pointer.x;
mouse_pos.y=pointer.y;
if(mouse_left)
{
ox=mouse_pos.x;
oy=mouse_pos.y;
while(mouse_left)
{
mouse_pos.x=pointer.x;
mouse_pos.y=pointer.y;
cx=mouse_pos.x;
cy=mouse_pos.y;
line(ox,oy,cx,cy);
ox=mouse_pos.x;
oy=mouse_pos.y;
wait(1);
}
}
wait(1);
}
}