Last active
August 27, 2017 22:49
-
-
Save tmcw/99a9320f0c9bf128d2e81ff667b81e03 to your computer and use it in GitHub Desktop.
Badge
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
var c = document.body.appendChild(document.createElement('canvas')); | |
var w = 1050, h = 1500; | |
//c.style.width = `${1050 / 2}px`; | |
//c.style.height = `${1050 / 2}px`; | |
c.width = w; | |
c.height = h; | |
var ctx = c.getContext('2d'); | |
ctx.fillStyle = '#000'; | |
ctx.strokeStyle = '#005791'; | |
ctx.lineWidth = 2; | |
function wave(t, n, f) { | |
var val = 0; | |
for (var k = 1; k < n; k ++) { | |
val += Math.sin(Math.PI * 4 * ((2 * k) - 1) * f * t) / ((2 * k) - 1); | |
} | |
return (4 / Math.PI) * val; | |
} | |
function draw(n, f, a) { | |
ctx.clearRect(0,0,w,h); | |
ctx.beginPath(); | |
ctx.moveTo(0, 0); | |
ctx.lineTo(0, h/2); | |
for (var t = 0; t < 1.05; t += 0.002) { | |
var y = wave(t * Math.PI, n, f) | |
ctx.lineTo(t * w * 1.26, (h/2) + (y * h/4)); | |
} | |
ctx.lineTo(w, 0); | |
ctx.fill(); | |
} | |
function drawAt(n) { | |
draw(n, 0.2); | |
} | |
// drawAt((Math.floor(e.pageX * 20 / window.innerWidth)) + 1); | |
drawAt(0.5); | |
var i = 0; | |
setInterval(() => { | |
drawAt(0.5 * i); | |
i++; | |
}, 500); |
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
<body> | |
<script src='badge.js'></script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment