Last active
November 14, 2020 02:55
-
-
Save enthal/3a7e4923c274cb678f60 to your computer and use it in GitHub Desktop.
D3/SVG "finger" articulation: https://bl.ocks.org/enthal/3a7e4923c274cb678f60
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
| <!DOCTYPE html> | |
| <meta charset="utf-8"> | |
| <style> | |
| svg { | |
| fill: none; | |
| stroke: #000; | |
| stroke-width: 4px; | |
| } | |
| svg rect.mouse { | |
| fill: none; | |
| stroke: none; | |
| pointer-events: all; | |
| } | |
| </style> | |
| <body></body> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"></script> | |
| <script> | |
| var width = 960, height = 500; | |
| var svg = d3.select("body").append("svg") | |
| .attr("width", width) | |
| .attr("height", height); | |
| var g0 = svg.append("g") | |
| .attr("transform", "translate(100,200)") | |
| .append("g"); | |
| g0.append("line") | |
| .attr("x2", 200); | |
| var wrist = g0.append("g") | |
| .attr("transform", "translate(200)") | |
| .append("g"); | |
| var hand1 = wrist.append("g"); | |
| hand1.append("line") | |
| .attr("x2", 100); | |
| var hand2 = wrist.append("g"); | |
| hand2.append("line") | |
| .attr("x2", 120) | |
| var knuckle1 = hand1.append("g") | |
| .attr("transform", "translate(100)") | |
| .append("g") | |
| var finger1 = knuckle1.append("g"); | |
| finger1.append("line") | |
| .attr("x2", 50); | |
| svg.append("rect").classed("mouse", true) | |
| .attr("width", width) | |
| .attr("height", height) | |
| .on("click", move); | |
| move(); | |
| function move() { | |
| g0 | |
| .attr("transform", "rotate(0)") | |
| .transition() | |
| .duration(900) | |
| .ease("ease-in") | |
| .attr("transform", "rotate(-25)") | |
| .transition() | |
| .duration(600) | |
| // .ease("linear") | |
| .attr("transform", "rotate(-22)") | |
| .transition() | |
| .duration(600) | |
| .ease("ease-out") | |
| .attr("transform", "rotate(-10)"); | |
| wrist | |
| .attr("transform", "rotate(-15)") | |
| .transition() | |
| .duration(900) | |
| .ease("ease-out") | |
| .attr("transform", "rotate(50)") | |
| .transition() | |
| .duration(1400) | |
| .attr("transform", "rotate(70)"); | |
| hand2 | |
| .attr("transform", "rotate(-30)") | |
| .transition() | |
| .duration(1800) | |
| .ease("linear") | |
| .attr("transform", "rotate(-20)"); | |
| knuckle1 | |
| .attr("transform", "rotate(20)") | |
| .transition() | |
| .duration(1900) | |
| .ease("ease-out") | |
| .attr("transform", "rotate(100)"); | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment