euler 15
by Hensixteen
HTML
<canvas id="canvas" width="500" height="500" style="border:1px solid black"></canvas>
JavaScript
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var x = 0;
var y = 0;
var drawGrid = true;
var counter = 0;
var moveCount = 0;
var total = 0;
var pos = 0;
var endPos = 0;
var right = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
while(counter <= 20) {
pos = (counter*(canvas.width/20));
ctx.moveTo(pos, 0);
ctx.lineTo(pos, canvas.height);
ctx.stroke();
counter++;
}
if(counter >= 20) {
counter = 0;
while(counter<=20) {
pos = (counter*(canvas.height/20));
ctx.moveTo(0, pos);
ctx.lineTo(canvas.width, pos);
ctx.stroke();
counter++;
}
}
counter = 40;
setInterval(function() {
if((x == 20 && y == 20)) {
moveCount = 0;
total++;
right[]
}
if(right[moveCount] == 0) {
x+=1;
}
else {
y+=1;
}
moveCount++;
}, 10);