[ Launch: Tributary inlet ] b02120e5436dd40d0d3f by hemulin
-
-
Save hemulin/b02120e5436dd40d0d3f to your computer and use it in GitHub Desktop.
cows_riddle
This file contains hidden or 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
{"description":"cows_riddle","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"ajax-caching":true,"thumbnail":"http://i.imgur.com/61M0jex.png"} |
This file contains hidden or 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 vis = d3.select("svg").append("svg"); | |
var w = 402, | |
h = 400, | |
x = 150, | |
y = 150, | |
r = 10, | |
dur = 1000; | |
var square = vis.append("rect") | |
.attr("width", w) | |
.attr("height", h) | |
.attr("x", x) | |
.attr("y", y) | |
.style("fill", "grey") | |
.style("opacity", 0.5) | |
.on("click", moveCows); | |
var cow1 = vis.append("circle") | |
.attr("r", r) | |
.attr("cx", x) | |
.attr("cy", y) | |
.style("fill", "blue"); | |
var cow2 = vis.append("circle") | |
.attr("r", r) | |
.attr("cx", x + w) | |
.attr("cy", y) | |
.style("fill", "red"); | |
var cow3 = vis.append("circle") | |
.attr("r", r) | |
.attr("cx", x + w) | |
.attr("cy", y + h) | |
.style("fill", "green"); | |
var cow4 = vis.append("circle") | |
.attr("r", r) | |
.attr("cx", x) | |
.attr("cy", y + h) | |
.style("fill", "orange"); | |
function moveCows() { | |
cow1.transition().duration(dur).attr("cx", cow2.attr("cx")).attr("cy", cow2.attr("cy")); | |
cow2.transition().duration(dur).attr("cx", cow3.attr("cx")).attr("cy", cow3.attr("cy")); | |
cow3.transition().duration(dur).attr("cx", cow4.attr("cx")).attr("cy", cow4.attr("cy")); | |
cow4.transition().duration(dur).attr("cx", cow1.attr("cx")).attr("cy", cow1.attr("cy")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment