first commit

This commit is contained in:
Sam Keddy
2019-03-26 23:20:54 +00:00
commit 7126e83f5f
67 changed files with 9722 additions and 0 deletions

21
js/_drawLine.js Normal file
View File

@@ -0,0 +1,21 @@
//draw a line between two points on canvas
function line(x0,y0,x1,y1) {
var dx = Math.abs(x1-x0);
var dy = Math.abs(y1-y0);
var sx = (x0 < x1 ? 1 : -1);
var sy = (y0 < y1 ? 1 : -1);
var err = dx-dy;
var breaker = 0;
while (true) {
//set pixel
context.fillRect(x0-Math.floor(brushSize/2), y0-Math.floor(brushSize/2), brushSize, brushSize);
//if we've reached the end goal, exit the loop
if ((x0==x1) && (y0==y1)) break;
var e2 = 2*err;
if (e2 >-dy) {err -=dy; x0+=sx;}
if (e2 < dx) {err +=dx; y0+=sy;}
}
}