Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (36 sloc) 1.13 KB
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Random 6</title>
<link rel="stylesheet" href="../include/style.css">
</head>
<body>
<header>
Example from <a href="http://amzn.com/1430236655?tag=html5anim-20"><em>Foundation HTML5 Animation with JavaScript</em></a>
</header>
<canvas id="canvas" width="400" height="400"></canvas>
<aside>Refresh page for random positions.</aside>
<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;
}
var x = xpos / iterations,
y = canvas.height / 2 + Math.random() * 50 - 25;
context.fillStyle = "#000000";
context.beginPath();
//x, y, radius, start_angle, end_angle, anti-clockwise
context.arc(x, y, 2, 0, (Math.PI * 2), true);
context.closePath();
context.fill();
}
};
</script>
</body>
</html>