A circle moving in a box, pong style. Same as this block but an easing is added to the transition (line 30) making it smoother.
Last active
March 11, 2018 19:40
-
-
Save pvernier/bfc4e0d06a5751a3495f46b92c77876f to your computer and use it in GitHub Desktop.
Pong - infinite transition with easing
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: gpl-3.0 | |
height: 200 |
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 charset="utf-8"> | |
<style type="text/css"> | |
svg { | |
background-color: #4d4d4d; | |
width: 200px; | |
height: 200px; | |
} | |
circle { | |
fill: #b2182b; | |
} | |
</style> | |
</head> | |
<body> | |
<svg></svg> | |
</body> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="https://d3js.org/d3-timer.v1.min.js"></script> | |
<script type="text/javascript"> | |
var circle = d3.select("svg") | |
.append("circle") | |
.attr("cx", 190) | |
.attr("cy", 100) | |
.attr("r", 10) | |
d3.interval(function(elapsed) { | |
circle.transition() | |
.ease(d3.easeLinear) | |
.attr("cx", 95) | |
.attr("cy", 190) | |
.transition() | |
.attr("cx", 10) | |
.attr("cy", 100) | |
.transition() | |
.attr("cx", 95) | |
.attr("cy", 10) | |
.transition() | |
.attr("cx", 190) | |
.attr("cy", 100) | |
}, 1000); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment