Built with blockbuilder.org
Created
October 30, 2017 10:35
-
-
Save jfourmond/3066888f4bb81e29b937b60db0214e8c to your computer and use it in GitHub Desktop.
Loading Circle V0 - Movement
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://d3js.org/d3.v4.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
</style> | |
</head> | |
<body> | |
<script> | |
const width = 960; | |
const height = 500; | |
const midWidth = Math.floor(width/2); | |
const midHeight = Math.floor(height/2); | |
const color = d3.scaleOrdinal(d3.schemeCategory10); | |
let colorVar = 0; | |
function rotateClockwise(transition) { | |
transition | |
.duration(5000) | |
.ease(d3.easeLinear) | |
.attrTween("cx", function() { | |
let that = d3.select(this); | |
return function(t) { | |
return(midWidth + 50 * Math.cos(2 * Math.PI * t)); | |
} | |
}) | |
.attrTween("cy", function() { | |
let that = d3.select(this); | |
return function(t) { | |
return(midHeight + 50 * Math.sin(2 * Math.PI * t)); | |
} | |
}).on("end", function() { | |
d3.select(this).transition().call(rotateClockwise); | |
});; | |
} | |
const svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
const circle = svg.append("circle") | |
.attr("cx", midWidth) | |
.attr("cy", midHeight) | |
.attr("r", 20) | |
.attr("fill", color(colorVar++)); | |
circle.transition().call(rotateClockwise); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment