I'd like to submit a function for TinyC5 if I may. At the moment I'm using the following code in the main function:
tinyC5.line=function(x0,y0,x1,y1,rd,gn,bu,a){
var xd,xda,xt,yd,yda,yt,g,tmp,pxl,w,h;
w=this.WIDTH;
h=this.HEIGHT;
xd=x1-x0;
yd=y1-y0;
xda=Math.abs(xd);
yda=Math.abs(yd);
if(xda>yda){
if(x0>x1){
tmp=x0;
x0=x1;
x1=tmp;
tmp=y0;
y0=y1;
y1=tmp;
}
g=yd/xd;
for(i=0;i<=xda;i++){
xt=x0+i;
yt=y0+Math.round(i*g);
pxl=(w*yt+xt)*4;
this.pixels[pxl]=rd;
this.pixels[pxl+1]=gn;
this.pixels[pxl+2]=bu;
this.pixels[pxl+3]=a;
}
}else{
if(y0>y1){
tmp=x0;
x0=x1;
x1=tmp;
tmp=y0;
y0=y1;
y1=tmp;
}
g=xd/yd;
for(i=0;i<=yda;i++){
yt=y0+i;
xt=x0+Math.round(i*g);
pxl=(w*yt+xt)*4;
this.pixels[pxl]=rd;
this.pixels[pxl+1]=gn;
this.pixels[pxl+2]=bu;
this.pixels[pxl+3]=a;
}
}
}
This allows me to draw a line from x0,y0 to x1,y1 with a colour defined by rd, gn, bu and a.
I'm using as follows to draw a line in the update function:
this.line(xx0,yy0,yy1,xx1,red,green,blue,alpha);
If you choose to add this function to a future update of TinyC5, please let me know. You may be able to optimise it better than I have.