| 204 | |
| 205 | var timeSinceLastKeyTimeout; |
| 206 | function drawKey(keySel, scanType) { |
| 207 | |
| 208 | module.bot.emote("keyboardmash"); |
| 209 | clearInterval(timeSinceLastKeyTimeout); |
| 210 | timeSinceLastKeyTimeout = setTimeout(function () { |
| 211 | module.bot.emote("keyboardmash_rest"); |
| 212 | }, 500); |
| 213 | |
| 214 | // random path for scancode to spin out |
| 215 | var driftX = (Math.random()*300).toFixed(); |
| 216 | var driftY = (Math.random()*300).toFixed(); |
| 217 | var driftθ = (Math.random()*360-180).toFixed(); |
| 218 | |
| 219 | // color is random shade of green for make, red for break |
| 220 | var colors = { |
| 221 | "make": d3.scale.linear().range(["#00c770", "#91f29b"]), |
| 222 | "break": d3.scale.linear().range(["#f94600","#fec343"]) |
| 223 | }; |
| 224 | var color = colors[scanType](Math.random()); |
| 225 | |
| 226 | // scancodes pour out of the keys |
| 227 | keySel.append("div.key-event").text(ƒ(scanType)) |
| 228 | .style("color", color) |
| 229 | .transition() |
| 230 | .duration(2000) |
| 231 | .style("transform", "rotate(" + driftθ + "deg) translate("+ driftX +"px, " + driftY + "px)") |
| 232 | .style("opacity",0) |
| 233 | .remove(); |
| 234 | |
| 235 | // light up key background for a moment w/ a random pretty color |
| 236 | keySel.style("background-color", d3.hsl(Math.floor(Math.random()*180), .8, .8)) |
| 237 | .transition() |
| 238 | .duration(300) |
| 239 | .style("background-color", "rgba(255,255,255,0)"); |
| 240 | |
| 241 | } |
| 242 | |
| 243 | } |
| 244 | |