Last active
June 6, 2016 15:26
-
-
Save EmilienDupont/d060695221c6f3f874990e9192337b98 to your computer and use it in GitHub Desktop.
Rain
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> | |
| <meta charset="utf-8"> | |
| <body> | |
| <script src="//d3js.org/d3.v3.min.js"></script> | |
| <script> | |
| var width = 960, | |
| height = 500; | |
| var svg = d3.select("body") | |
| .append("svg") | |
| .attr("width", width) | |
| .attr("height", height); | |
| function raindrop(size, duration, delay, x_pos, y_pos) { | |
| var drop = svg.append("circle") | |
| .attr("cx", x_pos) | |
| .attr("cy", y_pos) | |
| .attr("r", 0) | |
| .attr("stroke", "#5FC3E4") | |
| .attr("stroke-width", 2) | |
| .attr("fill", "none") | |
| .attr("opacity", 1); | |
| drop.transition() | |
| .delay(delay) | |
| .duration(duration) | |
| .attr("r", size) | |
| .attr("stroke-width", 0) | |
| .attr("opacity", 0.5) | |
| .ease("circleout"); | |
| } | |
| function make_it_rain(num_drops) { | |
| console.log("Making it rain"); | |
| for (i = 0; i < num_drops; i++) { | |
| var size = 50 * Math.random() + 50, | |
| duration = 50 * Math.random() + 750, | |
| delay = 5000 * Math.random(), | |
| x_pos = width * Math.random(), | |
| y_pos = height * Math.random(); | |
| raindrop(size, duration, delay, x_pos, y_pos); | |
| } | |
| } | |
| d3.timer(function(elapsed) { | |
| if (elapsed % 5000 < 50) { | |
| make_it_rain(50); | |
| } | |
| }) | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment