Created
April 5, 2017 13:14
-
-
Save hyuki0000/0ed09c729e81a7ef2f7f0820f43eb33d to your computer and use it in GitHub Desktop.
九九の表に類似した100x100の表で、積がnで割り切れる点を黒く塗る。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
var current = 1; | |
function drawit(n) { | |
var ctx = $('#canvas')[0].getContext('2d'); | |
var size = 5; | |
var screen = 500; | |
var cols = screen / size; | |
for (var y = 0; y < cols; y++) { | |
for (var x = 0; x < cols; x++) { | |
if ((x+1) * (y+1) % n == 0) { | |
ctx.fillStyle = 'black'; | |
} else { | |
ctx.fillStyle = 'white'; | |
} | |
ctx.strokeStyle = 'lightgray'; | |
ctx.fillRect(x * size, y * size, size, size); | |
ctx.strokeRect(x * size, y * size, size, size); | |
} | |
} | |
$('#label').text("n = " + current); | |
} | |
setInterval(function() { | |
drawit(current); | |
current += 1; | |
}, 500); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<div id="label"></div> | |
<canvas id="canvas" width="500" height="500" style="border:1px solid black;">canvas is not supported.</canvas> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
<script src="canvas.js"></script> | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ループ内の処理を以下のようにすると、剰余を色相に割り当てることができる。