Skip to content

Instantly share code, notes, and snippets.

@roryokane
Last active Dec 10, 2015
Embed
What would you like to do?
random and non-random dot distributions side by side
<!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>
&#8596; <!-- 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