Created
September 19, 2014 11:45
-
-
Save island205/206be812c1b797bf24cd to your computer and use it in GitHub Desktop.
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
window.requestAnimFrame = (function() { | |
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(a) { | |
window.setTimeout(a, 1000 / 60) | |
} | |
})(); | |
window.onload = function() { | |
var m = canvas.getContext("2d"), | |
k, g; | |
canvas.width = k = window.innerWidth * 2.1; | |
canvas.height = g = window.innerHeight * 1.4; | |
var i = new j(), | |
e = new j(), | |
c = new j(), | |
b = g * 0.5; | |
count = 40, step = Math.ceil(k / count), buffer = new ArrayBuffer(count * 4), points = new Float32Array(buffer); | |
i.max = 15; | |
e.max = 5; | |
e.speed = 0.03; | |
e.max = 5; | |
e.speed = 0.015; | |
function l() { | |
for (var h = 0; h < count; h++) { | |
points[h] = a(i, e, c) | |
} | |
} | |
l(); | |
m.lineWidth = 20; | |
m.strokeStyle = "#393d46"; | |
m.fillStyle = "#393d46"; | |
function f() { | |
var h; | |
for (h = 0; h < count - 1; h++) { | |
points[h] = points[h + 1] | |
} | |
points[count - 1] = a(i, e, c); | |
m.clearRect(0, 0, k, g); | |
m.beginPath(); | |
m.moveTo(-5, points[0]); | |
for (h = 1; h < count; h++) { | |
m.lineTo(h * step, points[h]) | |
} | |
m.lineTo(k, g); | |
m.lineTo(-5, g); | |
m.lineTo(-5, points[1]); | |
m.stroke(); | |
m.fill() | |
} | |
function j() { | |
this.variation = 0.4; | |
this.max = 150; | |
this.speed = 0.02; | |
var o = this, | |
n = 0, | |
h = p(); | |
this.getAmp = function() { | |
n += this.speed; | |
if (n >= 2) { | |
n = 0; | |
h = p() | |
} | |
return h * Math.sin(n * Math.PI) | |
}; | |
function p() { | |
return Math.random() * o.max * o.variation + o.max * (1 - o.variation) | |
} | |
return this | |
} | |
function a() { | |
var o = arguments.length, | |
h = o, | |
n = 0; | |
if (o < 1) { | |
return 0 | |
} | |
while (h--) { | |
n += arguments[h].getAmp() | |
} | |
return n / o + b | |
}(function d() { | |
requestAnimFrame(d); | |
f() | |
})() | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment