我通常可以研究我的问题并从别人的错误中得到答案,但这次我找到答案的时间相当不寻常。这个概念是您可以为网格32x32
上的“像素”着色。16x16
我的完整代码如下:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jscolor.js"></script>
<title>Tiles</title>
</head>
<body>
<canvas id="canvas" height="512" width="512" onclick="draw(window.event)">
Oops, you don't have Canvases
</canvas>
<input type="text" value="000000" class="color"></input>
<script type="text/javascript">
var draw_a = document.getElementById("canvas").getContext("2d");
function draw(e) {
draw_a.fillStyle = "#" + document.getElementById("color").value;
draw_a.fillRect(
math.floor( e.clientX / 16 ),
math.floor( e.clientX / 16 ),
32,
32
);
}
draw_a.fillStyle = "#000000";
draw_a.fillRect( 0 , 0 , 512 , 512 );
</script>
</body>
</html>