Built with blockbuilder.org
Last active
October 30, 2017 20:56
-
-
Save enyim/f96390ffc0e5f0f4d996eadd9cd13dee to your computer and use it in GitHub Desktop.
fresh block
This file contains hidden or 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: mit |
This file contains hidden or 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> | |
| <head> | |
| <meta charset="utf-8"> | |
| <script src="https://d3js.org/d3.v4.min.js"></script> | |
| <style> | |
| body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
| body { background: #333; } | |
| circle { | |
| stroke: #000; | |
| stroke-width: 1.5px; | |
| } | |
| </style> | |
| </head> | |
| <svg width="960" height="960"><g transform="translate(480,480)"></g></svg> | |
| <body> | |
| <script> | |
| var svg = d3.select("svg"), | |
| width = +svg.attr("width"), | |
| height = +svg.attr("height"), | |
| size = Math.max(width, height); | |
| var color = d3.scaleSequential(d3["interpolateRainbow"]).domain([0, 2 * Math.PI]); | |
| var circles = d3.packSiblings(d3.range(2000) | |
| .map(d3.randomUniform(8, 26)) | |
| .map(function(r) { return {r: r}; })) | |
| .filter(function(d) { return -500 < d.x && d.x < 500 && -500 < d.y && d.y < 500; }); | |
| svg | |
| .select("g") | |
| .selectAll("circle") | |
| .data(circles) | |
| .enter().append("circle") | |
| .style("fill", function(d) { return color(d.angle = Math.atan2(d.y, d.x)); }) | |
| .attr("cx", function(d) { return Math.cos(d.angle) * (size / Math.SQRT2 + 30); }) | |
| .attr("cy", function(d) { return Math.sin(d.angle) * (size / Math.SQRT2 + 30); }) | |
| .attr("r", function(d) { return d.r - 0.25; }) | |
| .transition() | |
| .attr("cx", function(d) { return d.x; }) | |
| .attr("cy", function(d) { return d.y; }); | |
| </script> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment