Skip to content

Instantly share code, notes, and snippets.

@emi-lp
Last active January 13, 2016 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emi-lp/fb99abd4a5f2f0e34860 to your computer and use it in GitHub Desktop.
Save emi-lp/fb99abd4a5f2f0e34860 to your computer and use it in GitHub Desktop.
random circles
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
svg { width:100%; height: 100% }
</style>
</head>
<body>
<svg width="720" height="120">
<circle></circle>
<circle></circle>
<circle></circle>
<circle></circle>
<circle></circle>
</svg>
<script>
var circle = d3.selectAll("circle");
circle.data([32, 57, 112]);
circle.style("fill", "steelblue");
circle.attr("r", function() { return Math.random() * 50; });
function moveCircles(){
circle.transition().attr("r", function() { return Math.random() * 5; });
circle.transition().attr("cx", function() { return Math.random() * 720; });
circle.transition().attr("cy", function() { return Math.random() * 720; });
setTimeout(moveCircles, 500);
}
moveCircles();
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment