A web-page, more-readable version of the code by praptak on https://news.ycombinator.com/item?id=4956101.
Last active
December 10, 2015 01:28
-
-
Save roryokane/4358325 to your computer and use it in GitHub Desktop.
random and non-random dot distributions side by side
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> | |
<!-- original code by praptak on https://news.ycombinator.com/item?id=4956101 --> | |
<html> | |
<head> | |
<title>random and non-random dot distributions side by side</title> | |
</head> | |
<body> | |
<canvas height="200" id="tutorial" width="200">foo</canvas> | |
↔ <!-- left right arrow --> | |
<canvas height="200" id="tutorial2" width="200">foo</canvas> | |
<script> | |
var canvas = document.getElementById('tutorial'); | |
var ctx = canvas.getContext('2d'); | |
ctx.fillStyle = "rgb(000,0,0)"; | |
for (var i=0;i<400;i++) { | |
ctx.fillRect (Math.random() * 200,Math.random() * 200, 2, 2); | |
}; | |
</script> | |
<script> | |
var canvas = document.getElementById('tutorial2'); | |
var ctx = canvas.getContext('2d'); | |
ctx.fillStyle = "rgb(000,0,0)"; | |
for (var i=0;i<20;i++) | |
for(var j=0;j<20;j++) | |
for(k=0;k<1;k++) { | |
ctx.fillRect (i * 10 + Math.random() * 10, j * 10 + Math.random() * 10, 2, 2); | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment