Created
August 28, 2013 10:39
-
-
Save Sarah-W/6364673 to your computer and use it in GitHub Desktop.
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> | |
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<meta charset="utf-8"> | |
<title></title> | |
<!--<script type="text/javascript" src="./D3 Page Template_files/d3.v3.min.js"></script>--> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<style type="text/css"> | |
div{ | |
background-color:darkgrey; | |
width:950px; | |
border:2px solid black; | |
text-align:center; | |
font-family:sans-serif; | |
} | |
circle{stroke : black; | |
} | |
</style> | |
</head> | |
<body> | |
<div></div> | |
<div style= "display:inline-block;"> | |
<button id=start>Start</button><button id=stop>Stop</button> | |
</div> | |
<script type="text/javascript"> | |
var npoints = 50, | |
width = 500, | |
t =0, | |
r = function(th,t){return 1.2+ Math.cos(t+th/3)}, | |
x = function(th,t){return (1.2+ Math.cos(t+th*3))*Math.cos(th)}, | |
y = function(th,t){return (1.2+ Math.cos(t+th*3))*Math.sin(th)}; | |
var thetas = d3.range(npoints).map(function (d){return 2*Math.PI*d/npoints}); | |
//var colour = d3.scale.linear().domain([-1, 1]).range([0,360]); | |
var svg = d3.select("div").append("svg") | |
.attr("width",width) | |
.attr("height",width); | |
svg.selectAll("circle").data(thetas).enter().append("circle") | |
.attr("r",5) | |
.attr("cx",function(d){return 100*x(d,t)}) | |
.attr("cy",function(d){return 100*y(d,t)}) | |
.attr("fill",function(d){return "hsl(" + d*360/(2*Math.PI) + ",100%,50%)"}) | |
.attr("transform","translate(250,250)") | |
; | |
d3.select("#start").on("click",function(){ | |
stop=false | |
var myVar=setInterval(function(){ | |
t= t + Math.PI/100; | |
d3.selectAll("circle") | |
.attr("cx",function(d){return 100*x(d,t)}) | |
.attr("cy",function(d){return 100*y(d,t)}); | |
//STOP! | |
//if (time > dateend){stop = true;} | |
if (stop == true){clearTimeout(myVar); | |
stop = false;} | |
},20); | |
}); | |
d3.select("#stop").on("click",function(){stop=true;}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment