Last active
August 29, 2015 14:02
-
-
Save fabiovalse/804b9f96b38242c77d01 to your computer and use it in GitHub Desktop.
Point on Archimedean Spiral
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
svg { | |
border: 1px solid black; | |
} | |
.spiral { | |
fill: none; | |
stroke: #303030; | |
stroke-width: 3px; | |
} | |
circle { | |
fill: orange; | |
stroke: black; | |
stroke-width: 1.5px; | |
} |
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> | |
<head> | |
<meta name="description" content="Point on Archimedean Spiral" /> | |
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"> | |
<title>Point on Archimedean Spiral</title> | |
<script type="text/javascript" src="http://d3js.org/d3.v2.js"></script> | |
</head> | |
<body> | |
<div id="chart"></div> | |
</body> | |
</html> |
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
var duration = 5000; | |
var width = 600, | |
height = 430, | |
num_axes = 8, | |
start = 0, | |
end = 6; | |
var theta = function (r) { | |
return 2*Math.PI*r; | |
}; | |
var radius = d3.scale.linear() | |
.domain([start, end]) | |
.range([0, d3.min([width,height])/2.5]); | |
var angle = d3.scale.linear() | |
.domain([0, num_axes]) | |
.range([0,360]); | |
var svg = d3.select("#chart").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.append("g") | |
.attr("transform", "translate(" + width/2 + "," + (height/2) +")"); | |
var pieces = d3.range(start, end+0.01, (end-start)/1000); | |
var spiral = d3.svg.line.radial() | |
.interpolate("cardinal") | |
.angle(theta) | |
.radius(radius); | |
var path = svg.selectAll(".spiral") | |
.data([pieces]) | |
.enter().append("path") | |
.attr("class", "spiral") | |
.attr("d", spiral) | |
.attr("transform", function(d, i) { | |
return "translate(" + (-width/1.8*i) + ", 0)"; | |
}); | |
var circle = svg.append("circle") | |
.attr("r", 5.5); | |
function transition() { | |
circle.transition() | |
.duration(duration) | |
.attrTween("transform", translateAlong(path.node())) | |
.each("end", transition); | |
} | |
transition(); | |
function speed_change(val) { | |
duration = 10000 - (val*1000); | |
} | |
function translateAlong(path) { | |
var l = path.getTotalLength(); | |
return function(d, i, a) { | |
return function(t) { | |
var p = path.getPointAtLength(t * l); | |
return "translate(" + p.x + "," + p.y + ")"; | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment