HTML and CSS Reference
In-Depth Information
<script>
window.onload = function () {
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d'),
numDots = 300,
iterations = 6;
while (numDots--) {
for (var i = 0, xpos = 0; i < iterations; i++) {
xpos += Math.random() * canvas.width;
}
for (var j = 0, ypos = 0; j < iterations; j++) {
ypos += Math.random() * canvas.height;
}
var x = xpos / iterations,
y = ypos / iterations;
context.fillStyle = "#000000";
context.beginPath();
context.arc(x, y, 2, 0, (Math.PI * 2), true);
context.closePath();
context.fill();
}
};
</script>
</body>
</html>
This gives you a distribution like the one in Figure 19-9.
Figure 19-9. Two-dimensional biased distribution
This is the most random, explosive, star system-like distribution of them all, but it is also the most
computationally intensive to generate.
Search WWH ::




Custom Search