First draft
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="300" height="300"
style="border:1px solid #d3d3d3;">
Your browser does not support the canvas element.
</canvas>
<script>
var x=0,y=0,l=11;r=0,s=15,n=20,q="hello world";
window.addEventListener('keydown',this.check,false);
//initialize
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.font='15px Courier New';
update();
function check(e) {
var code = e.keyCode;
switch (code) {
case 37: x--; break; //Left key
case 38: y--; break; //Up key
case 39: x++; break; //Right key
case 40: y++; break; //Down key
case 82: if (r==0){r=1;}else{r=0;} break; //Rotate
default: alert(code); //Everything else
}
update();
}
function update(){
//keep word inside canvas
x=Math.max(x,0);
y=Math.max(y,1);
x=Math.min(x,n-(l-1)*r-1);
y=Math.min(y,n+(l-1)*(r-1)-1);
//update canvas
ctx.beginPath();
ctx.rect(0, 0, 300, 300);
ctx.fillStyle = "white";
ctx.fill();
ctx.fillStyle = "black";
for (var i=0;i<l;i++){
ctx.fillText(q.charAt(i),(x+i*r)*s,(y-i*(r-1))*s);
}
}
</script>
</body>
</html>
Lattjo
Crossword puzzle
More posts
- Larger screen, timer and colorsMay 30, 2021
- Third draftMay 17, 2021
- Second draftMay 17, 2021
Leave a comment
Log in with itch.io to leave a comment.