This example was created using building blocks and was used to show 100 dots of varying sizes and colors using d3.
Last active
October 17, 2016 20:57
-
-
Save jonsadka/274fe6247fd561425296 to your computer and use it in GitHub Desktop.
Simple Dots Example
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: mit |
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> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
</head> | |
<body> | |
<script> | |
var width = 960, | |
height = 500; | |
var svg = d3.select('body').append('svg') | |
.attr('width', width) | |
.attr('height', height); | |
var circle = svg.selectAll("circle") | |
.data(new Array(45)); | |
circle.enter().append("circle") | |
.attr("cy", function(){ return Math.random()*height; }) | |
.attr("cx", function(){ return Math.random()*width; }) | |
.attr("r", function(){ return Math.random()*35;}) | |
.attr("fill", function(){ | |
return '#' + Math.floor(Math.random()*16777215).toString(16); | |
}); | |
setInterval(function(){ | |
var randomNumber = Math.round(Math.random()*45); | |
existingCircles = svg.selectAll("circle") | |
.data(new Array(randomNumber)); | |
existingCircles.transition().duration(1000) | |
.attr("cy", function(){ return Math.random()*height; }) | |
.attr("cx", function(){ return Math.random()*width; }) | |
.attr('r', function(){ return Math.random()*35;}) | |
existingCircles.enter().append("circle") | |
.attr("cy", function(){ return Math.random()*height; }) | |
.attr("cx", function(){ return Math.random()*width; }) | |
.attr('r', 0) | |
.attr("fill", function(){ | |
return '#' + Math.floor(Math.random()*16777215).toString(16); | |
}) | |
.transition().duration(1000) | |
.attr('r', function(){ return Math.random()*30;}) | |
existingCircles.exit().remove(); | |
}, 1200); | |
</script> | |
</body> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment