Skip to content

Instantly share code, notes, and snippets.

@sarah37
Last active April 28, 2018 11:26
Show Gist options
  • Select an option

  • Save sarah37/58f5da72eb6e52229142727a72ee6867 to your computer and use it in GitHub Desktop.

Select an option

Save sarah37/58f5da72eb6e52229142727a72ee6867 to your computer and use it in GitHub Desktop.
Raindrops I
height: 960
border: no
var w = 960;
var h = 960;
var mycolours = d3.scaleOrdinal()
.domain([0,1,2,3,4,5])
.range(["#566270", //dark grey
"#8395ad", // greyish blue
"#e0e3da", // light greyish
"#a593e0", //purple
"#074e67" //teal
])
// create svg
var svg = d3.select("#svgDiv")
.append("svg")
.attr("width", w)
.attr("height", h);
var locations = []
for (var i = 0; i < 9 ; i++) {
for (var j = 0; j < 9 ; j++) {
locations.push([i*100+80,j*100+80])
}
}
setInterval(function() {
var dot = locations[Math.floor(Math.random() * 81)]
svg
.append("circle")
.attr("cx", function(d) {return dot[0]})
.attr("cy", function(d) {return dot[1]})
.attr("r", 0)
.style("fill", "none")
.style("stroke", mycolours(Math.floor(Math.random() * 5)))
.style("stroke-width", "2px")
.transition()
.duration(3500)
.ease(d3.easeQuadOut)
.attr("r", 75)
.style("stroke", "#fff")
.remove()
}, 10)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Circles</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://d3js.org/d3.v5.min.js"></script>
</head>
<body>
<div id="svgDiv"></div>
<script type="text/javascript" src="circles.js"></script>
</body>
</html>
body, html {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #fff;
}
#svgDiv {
position: absolute;
left: 0;
right: 0;
margin: 0;
padding: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment