UNPKG

alloytouch

Version:

super tiny size touch and physical motion library for the web

59 lines (47 loc) 1.92 kB
<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="200" height="200" style="border: 1px solid #d3d3d3;">Your browser does not support the HTML5 canvas tag.</canvas> <script> ; (function () { var waveWidth = 300, offset = 0, waveHeight = 8, waveCount = 5, startX = -100, startY = 208, progress = 0, progressStep = 1, d2 = waveWidth / waveCount, d = d2 / 2, hd = d / 2, c = document.getElementById("myCanvas"), ctx = c.getContext("2d"); function tick() { offset -= 5; progress += progressStep; if (progress > 220 || progress < 0) progressStep *= -1; if (-1 * offset === d2) offset = 0; ctx.clearRect(0, 0, c.width, c.height); ctx.beginPath(); var offsetY = startY - progress; ctx.moveTo(startX - offset, offsetY); for (var i = 0; i < waveCount; i++) { var dx = i * d2; var offsetX = dx + startX - offset; ctx.quadraticCurveTo(offsetX + hd, offsetY + waveHeight, offsetX + d, offsetY); ctx.quadraticCurveTo(offsetX + hd + d, offsetY - waveHeight, offsetX + d2, offsetY); } ctx.lineTo(startX + waveWidth, 300); ctx.lineTo(startX, 300); ctx.fill(); requestAnimationFrame(tick); } tick(); })(); </script> <a href="https://github.com/AlloyTeam/AlloyTouch" target="_blank" style="position: fixed; right: 0; top: 0; z-index: 3;width:140px;height:140px;"> <img src="//alloyteam.github.io/github.png" alt=""> </a> </body> </html>