Sixty circles with a random radius
Last active
March 11, 2018 19:46
-
-
Save pvernier/6eaa8235cb9cff413558e2be39a9f8a3 to your computer and use it in GitHub Desktop.
Sixty circles with a random radius
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
license: gpl-3.0 | |
height: 500 |
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> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<style type="text/css"> | |
svg { | |
background-color: #bdbdbd; | |
width: 100%; | |
height: 500px; | |
} | |
circle { | |
fill: none; | |
stroke: white; | |
} | |
</style> | |
</head> | |
<body> | |
<svg></svg> | |
</body> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script type="text/javascript"> | |
function getRandomR() { | |
// Return a random radius | |
var radius = Math.floor((Math.random() * 40)); | |
return radius | |
} | |
// Create the data | |
var items = 60; | |
var x0 = 250; | |
var y0 = 250; | |
var r = 200 | |
var centers = [] | |
for(var i = 0; i < items; i++) { | |
var x = x0 + r * Math.cos(2 * Math.PI * i / items); | |
var y = y0 + r * Math.sin(2 * Math.PI * i / items); | |
centers.push([x, y]) | |
} | |
var svg = d3.select("svg") | |
svg.selectAll("circle") | |
.data(centers) | |
.enter() | |
.append("circle") | |
.attr("cx", function(d) {return d[0]}) | |
.attr("cy", function(d) {return d[1]}) | |
.attr("r", function() { return getRandomR()}) | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment