Skip to content

Instantly share code, notes, and snippets.

@neon-ninja
Created May 11, 2021 06:27
Show Gist options
  • Save neon-ninja/424bd094e6267bc68e6e038a4ef89fa9 to your computer and use it in GitHub Desktop.
Save neon-ninja/424bd094e6267bc68e6e038a4ef89fa9 to your computer and use it in GitHub Desktop.
D3 circles
<svg id="circles"/>
var svg = d3.select("#circles");
d3.interval(function () {
var x = Math.random() * parseInt(svg.style('width'));
var y = Math.random() * parseInt(svg.style('height'));
//console.log("Spawning circle at " + x + "," + y);
svg.append('circle')
.attr('cx', x)
.attr('cy', y)
.attr('r', 0)
.style("opacity", .2)
.transition()
.duration(10000)
.style("opacity", 0)
.attr('r', 500)
.on("end", function() { this.remove() })
}, 1000);
<script src="https://d3js.org/d3.v4.min.js"></script>
html, body, svg {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
<link href="https://d3js.org/d3.v4.min.js" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment