Sine Wave Noise ...to be used for something else later maybe.
A Pen by Tiffany Rayside on CodePen.
| <canvas id="canv"></canvas> |
Sine Wave Noise ...to be used for something else later maybe.
A Pen by Tiffany Rayside on CodePen.
| window.requestAnimFrame = (function() { | |
| return window.requestAnimationFrame || | |
| window.webkitRequestAnimationFrame || | |
| window.mozRequestAnimationFrame || | |
| window.oRequestAnimationFrame || | |
| window.msRequestAnimationFrame || | |
| function(callback) { | |
| window.setTimeout(callback, 1000 / 60); | |
| }; | |
| })(); | |
| var c = document.getElementById('canv'), | |
| $ = c.getContext('2d'), | |
| sin = 0; | |
| function resize() { | |
| c.style.width = window.innerWidth + 'px'; | |
| c.style.height = window.innerHeight + 'px'; | |
| } | |
| resize(); | |
| window.onresize = resize; | |
| function noise($) { | |
| var w = $.canvas.width, | |
| h = $.canvas.height, | |
| imgD = $.getImageData(0, 0, w, h), | |
| buffer32 = new Uint32Array(imgD.data.buffer), | |
| len = buffer32.length, | |
| i = 0, | |
| pr = 456 * Math.random(), | |
| prs = 716 * Math.random();; | |
| for(; i < len;) { | |
| //black, grey, and white | |
| //buffer32[i++] = (((pr % 255)|0) << 24) | 0x110000; | |
| //Or colorful | |
| buffer32[i++] = (((pr % 255)|0) << 24) | 0x770000 + (Math.random() * 16777216)|0; | |
| pr += prs * 2.5; | |
| } | |
| $.putImageData(imgD, 0, 0); | |
| // wave | |
| for(i = 0; i < w; i += 1.2) { | |
| var x = i * Math.sin((i+(sin++))/200); | |
| $.drawImage($.canvas, i,0, 1, h, i, x, 1, h); | |
| } | |
| } | |
| (function run() { | |
| noise($); | |
| window.requestAnimFrame(run); | |
| })(); |
| body{ | |
| width:100%; | |
| margin:0; | |
| overflow:hidden; | |
| } | |
| canvas{ | |
| background:hsla(255,255%,255%,1); | |
| } |