A circle moving in a box, pong style.
Last active
March 11, 2018 19:37
-
-
Save pvernier/2ba5a32840c7d5125afe071c6b68e5ac to your computer and use it in GitHub Desktop.
Pong - infinite transition
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() | |
.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