Skip to content
Browse files

more

  • Loading branch information...
1 parent c9434e5 commit 8c250f70c60d11f964d3aa02ddc440bc10fe27ab @substack committed Jan 17, 2015
Showing with 340 additions and 0 deletions.
  1. +65 −0 datacenter.js
  2. +57 −0 funksynth.js
  3. +28 −0 grime.js
  4. +60 −0 hotdub.js
  5. +25 −0 laserpower.js
  6. +35 −0 repluck.js
  7. +21 −0 suspense.js
  8. +19 −0 warmup.js
  9. +30 −0 workpocalypse.js
View
65 datacenter.js
@@ -0,0 +1,65 @@
+var d = snare();
+var melody = [ 17, 5, -13, 14, 17, 5, -56, -80, 19 ];
+var rhythm = [ 64, 32, 100, 1000 ];
+var factors = [ 1, 4, 1, 1/4, 12800, 80, 1 ];
+var warp = [ 1, 2000, 1/100 ];
+var scratch = [ 4, 4, 4, 50, 1, 4, 4, 1, 40, 4, 4, 4 ];
+var mults = [ 50, 800, 2000, 25, 15, 1 ];
+
+return function (t) {
+ var m = Math.pow(2,melody[Math.floor(t*4) % melody.length]/12);
+ var f = factors[Math.floor(t/4) % factors.length];
+ var r = Math.pow(2,rhythm[Math.floor(t*f) % rhythm.length]/12);
+ var w = warp[Math.floor(t/2) % warp.length];
+ var sc = scratch[Math.floor(t*4) % scratch.length];
+ var mu = mults[Math.floor(t/8) % mults.length];
+ var x = dub((t*m*mu+1+w)%0.5*Math.abs(Math.sin((t/r*w+10)%0.1*1000*m)/100));
+ return (1-x)/2 + d(t%(1/2)) * 0.4 + d(t % 1/4) * 0.4 + d(t*8%1/sc) * 0.2;
+};
+
+function dub (t) {
+ var m = sin(Math.pow(2,melody[Math.floor(t * 8) % melody.length]/12));
+ return saw(850 * m + (Math.floor(sin(10)*18) % 5) * 10) * 0.7
+ + saw(850 * 2 * m) * 0.2
+ + saw(850 * 2 * m + 5) * 0.3
+ + saw(851 * 5 * m - t%4) * 0.9
+ + saw(85*80 * m) * (1-saw(8)) * (1 + saw(4))
+ ;
+ return noise(t/2) / 7
+ + saw(800 + (Math.floor(sin(15)*18) % 8) * 10)
+ + d((t + 1/2) % (1/2)) * 8 * saw(8) * sin(8000) * 2
+ + d(((t+1/2)*4) % 1) * sin(4000) * 4
+ ;
+ function sin (x) { return Math.sin(2 * Math.PI * t * x) }
+ function saw (x) { return 1 - t % (1/x) * x * 2 }
+}
+function noise (t) {
+ return 0
+ + saw(saw(40)) * sin(12000)
+ + saw(40) + saw(41)
+ + saw(80) + saw(81 + saw(1/3)) * sin(100)
+ ;
+ function sin (x) { return Math.sin(2 * Math.PI * t * x) }
+ function saw (x) { return 1 - t % (1/x) * x * 2 }
+}
+
+function snare () {
+ var low0 = lowpass(30);
+ var low1 = lowpass(80);
+ var low2 = lowpass(20);
+ return function (t) {
+ return low0(snare(80, t))*5
+ + low1(snare(40, t+1/60))*10
+ + low2(snare(80, t+1/30))*5
+ ;
+ function snare (n, o) {
+ var scalar = Math.max(0, 0.95 - (o * n) / ((o * n) + 1));
+ return sin(sin(sin(137)*139)*4217) * scalar;
+ }
+ function sin (x) { return Math.sin(2 * Math.PI * t * x) }
+ };
+ function lowpass (n) {
+ var value = 0;
+ return function (x) { return value += (x - value) / n }
+ }
+}
View
57 funksynth.js
@@ -0,0 +1,57 @@
+var funk = [
+ [8,2,1/8], [1/8,1,1], [1,8,40], [8,1,8],
+ [4,2,15], [1/8,1,1], [4,4,20], [4,4,20]
+];
+var melody = [ 40, 60, 50, 0, 50, 50, 0 ];
+var d = snare();
+
+return function (t) {
+ var p = funk[Math.floor(t*4)%funk.length];
+ var m = melody[Math.floor(t)%melody.length];
+ var n = melody[Math.floor(t/4)%melody.length];
+ return 0
+ + clip(d(t % (1/p[0]) * p[1]) * sq(p[2]*100)) * 0.3
+ + saw(m) * (1-saw(4))/2 * (1+sq(2))/2 * 0.3
+ + saw(m + 1/8) * (1-saw(4))/2 * (1+sq(2))/2 * 0.3
+ + saw(4*m) * (1-saw(4))/2 * (1-sq(2))/2 * 0.3
+ + saw(4*m - 1/8) * (1-saw(4))/2 * (1-sq(2))/2 * 0.3
+ + tri(2*m + 0.13 + tri(400)) * (1-sq(8))/2 * 0.1 * (1-sq(1/4))/2
+ + saw(2*m + tri(1800)) * (1-sq(8))/2 * 0.1 * (1+sq(1/4))/2
+ + (
+ saw(n*8) * 0.2
+ + saw(n*8 + 1/16) * 0.2
+ + saw(n * 4) * 0.2
+ + saw(n * 16 - 1/24) * 0.2
+ + tri(n + tri(n * 4 + 100)) * 0.2
+ ) * (1-saw(4)) / 2 * (1+sq(1/4))/2 * 0.3
+ ;
+ function tri (x) { return Math.abs(1 - t % (1/x) * x * 2) * 2 - 1}
+ function saw (x) { return t%(1/x)*x*2-1 }
+ function sin (x) { return Math.sin(2 * Math.PI * t * x) }
+ function sq (x) { return t*x % 1 < 0.5 ? -1 : 1 }
+ function clip (x) {
+ if (x === Infinity || x === -Infinity || isNaN(x)) return 0;
+ return Math.min(1, Math.max(-1, x));
+ }
+};
+
+function snare () {
+ var low0 = lowpass(800);
+ var low1 = lowpass(80);
+ var low2 = lowpass(20);
+ return function (t) {
+ return low0(snare(80, t))*5
+ + low1(snare(40, t+1/60))*10
+ + low2(snare(80, t+1/30))*5
+ ;
+ function snare (n, o) {
+ var scalar = Math.max(0, 0.95 - (o * n) / ((o * n) + 1));
+ return sin(sin(sin(137)*139)*4217) * scalar;
+ }
+ function sin (x) { return Math.sin(2 * Math.PI * t * x) }
+ };
+ function lowpass (n) {
+ var value = 0;
+ return function (x) { return value += (x - value) / n }
+ }
+}
View
28 grime.js
@@ -0,0 +1,28 @@
+var n
+//var melody = [ 0, -1, -3, -5,-7,-8,-10,-12 ] // reverse DoSiLaSoFaMiReDo
+//var melody = [ 0, 2, 4, 5,7,9,11,12 ] //DoReMiFaSoLaSi
+ var melody =[
+ 34, 4, n, 4, n, 0, 4, n, 7, n, n, n, -5, n, n, n,
+ 0,n,n,-5,n,n,-8,n,n,-3,n,-1,n,-2,-3,n,-5,4,n,7,9,n,5,7,n,4,n,0,2,-1,n,n,n,
+ 0,n,n,-5,n,n,-8,n,n,-3,n,-1,n,-2,-3,n,-5,4,n,7,9,n,5,7,n,4,n,0,2,-1,n,n,n,
+ n,-5,7,6,5,3,n,4,n,-5,-3,0,0,-3,0,2,n,n,n,7,6,5,3,n,4,n,n,12,n,12,12,n,n,n,n,
+ n,n,7,6,5,3,n,4,n,-5,-3,0,n,-3,0,2,n,n,3,n,n,2,n,n,0,n,n,-5,-5,n,-12,n,
+ 0,0,n,0,n,0,2,n,4,0,n,-3,-5,n,n,n,
+ 0,0,n,0,n,0,2,n,4,n,n,n,n,n,n,n,
+ 0,0,n,0,n,0,2,n,4,0,n,-3,-5,n,n,n
+]
+var interval = 9
+var feq = 260
+return function (t) {
+
+ var m =note(t);
+ return sin(m * feq)*2;
+ function sin (x) { return Math.sin(2 * Math.PI * t * x) }
+
+ function note(x) {
+ var index =melody[Math.floor(x*interval) % melody.length];
+ if (index == null) return
+ return Math.pow(2, index / 12)
+ }
+
+}
View
60 hotdub.js
@@ -0,0 +1,60 @@
+var melody = [ -2, -2, -1, -1, 0, 0, 3, 0, 3, 0 ];
+var base = [ 12, 11 ];
+
+var times = [ 16, 16, 16, 16 ];
+var duration = times.reduce(function (sum, t) { return sum + t });
+var offsets = times.reduce(function (acc, t) {
+ return acc.concat((acc[acc.length-1] || 0) + t);
+}, []);
+
+return function (t) {
+ var d = t % duration;
+ if (d < offsets[0]) {
+ return intro(t,1) * (t < 8 ? (1 - saw(1/8)) / 2 : 1)
+ + (d > 11) * scrape(d > offsets[0]-1 ? 800 : 8)
+ ;
+ }
+ else if (d < offsets[1]) {
+ return intro(t + sin(t*2)/5000,1) + scrape(8);
+ }
+ else if (d < offsets[2]) {
+ return intro(t + sin(t/8000)/40 + sin(t/80)/16000,1)
+ + (d > offsets[2]-1 ? scrape(800) : 0) + scrape(8)
+ ;
+ }
+ else { //if (d < offsets[3]) {
+ return intro(t + sin(t/500)/1000 + sin(t*2)/5000,1)
+ + (d > offsets[3]-1 ? scrape(800) : 0) + scrape(8)
+ ;
+ }
+
+ function scrape (n) {
+ return pre(((t%1)+10000-4)*6400,64000) * saw(n || 8) * 2
+ }
+ function sin (x) { return Math.sin(2 * Math.PI * t * x) }
+ function saw (x, tt) { return 1 - (tt || t) % (1/x) * x * 2 }
+};
+
+function pre (t, n) {
+ return intro(t / n % Math.floor(t * 4 % 16 + 1));
+}
+
+function intro (t, n) {
+ var b = base[Math.floor(t/melody.length) % base.length];
+ var m = Math.pow(2, melody[Math.floor(t*4) % melody.length]/b);
+ return (synth(m) * 0.5
+ + synth(m * Math.floor(t % 4 + 1)) * 0.3
+ + saw(m*60+1/2) * 0.3
+ + synth(m*120 + sin(60)) * 0.25
+ ) * (n === undefined ? (1 - saw(2)) : n);
+
+ function sin (x) { return Math.sin(2 * Math.PI * t * x) }
+ function saw (x) { return 1 - t % (1/x) * x * 2 }
+ function synth (x) {
+ var m = 120 * x;
+ return sin(m) * 0.1
+ + saw(m * 2) * 0.2
+ + saw(m * 2 + 4) * 0.2
+ ;
+ }
+}
View
25 laserpower.js
@@ -0,0 +1,25 @@
+var melody = [ 5, 3, 1, 8, 4, 7, 0 ];
+var speed = [ 4, 2, 8, 1 ];
+var power = [ 200, 2000, 500, 2, 100, 20, 200, 400, 1, 100 ];
+
+return function (t) {
+ var m = melody[Math.floor(t*2) % melody.length];
+ var sp = speed[Math.floor(t) % speed.length];
+ var up = (Math.floor(t/8) % 4 + 1) * 8;
+ var pow = power[Math.floor(t / 8) % power.length];
+ var xm = Math.pow(2,m/12) * 50;
+ var tm = t % (1/sp) + 1/8;
+ return 0
+ + saw_(xm + saw(xm)*4 + 0.21, t%(1/4) - 1)*0.2 * (1+sq(1/15))/2
+ + saw_(xm + saw(xm*8*sp)*8, t%(1/4)*4)*0.2 * (1+sq(1/11))/2
+ + saw_(xm + saw(xm*up) + 0.11, t%(1/2))*0.2 * (1+sq(1/4))/2
+ + tri_(xm*4 + tri_(pow, tm)*xm/40, tm)*0.4 * tri_(sp*4, t/4%2)
+ ;
+ function tri (x) { return Math.abs(1 - t % (1/x) * x * 2) * 2 - 1}
+ function saw (x) { return t%(1/x)*x*2-1 }
+ function sin (x) { return Math.sin(2 * Math.PI * t * x) }
+ function sq (x) { return t*x % 1 < 0.5 ? -1 : 1 }
+ function tri_ (x, t) { return Math.abs(1 - t % (1/x) * x * 2) * 2 - 1}
+ function saw_ (x, t) { return t%(1/x)*x*2-1 }
+ function sin_ (x, t) { return Math.sin(2 * Math.PI * t * x) }
+}
View
35 repluck.js
@@ -0,0 +1,35 @@
+var melody = [ 80, 20, 30, 90, 80, 20, 30, 70 ];
+var alt = [ 6, 20 ];
+var bells = [ 1, 300, 1/8 ];
+var freq = 100;
+var n = 10;
+
+var speed = [ 2, 0.25, 0.5, 0.15, 0.5, 0.25 ];
+
+return function (t) {
+ var tt0 = t % speed[Math.floor(t/16)%speed.length];
+ var tt1 = (t + 0.1) % speed[Math.floor(t/20)%speed.length];
+ var freq = 100;
+ var n = 10;
+ var m = melody[Math.floor(t) % melody.length];
+ var a = alt[Math.floor(t/8) % alt.length];
+ var b = bells[Math.floor(t/10) % bells.length];
+ var ph0 = Math.max(0, 0.95 - (tt0 * n) / ((tt0 * n) + 1));
+ var ph1 = Math.max(0, 0.95 - (tt1 * n) / ((tt1 * n) + 1));
+ return (
+ tri(freq/2+m/80)
+ + tri(2*freq + 1)
+ + sin(5*freq+3*m + tri(a+b*m)*800000)
+ + tri(6*freq-8 + tri(b)/a) * 0.5
+ + sin(8*freq*m/40)
+ + saw(freq*2) * 0.2
+ ) / 5 * ph0
+ + (
+ saw(freq * 2 + 1) * 0.1
+ + saw(freq / 4 - 1/8) * 0.05
+ ) * ph1
+ ;
+ function sin (x) { return Math.sin(3 * Math.PI * t * x) }
+ function tri (x) { return Math.abs(1 - t % (1/x) * x * 2) * 2 - 1}
+ function saw (x) { return t%(1/x)*x*2-1 }
+}
View
21 suspense.js
@@ -0,0 +1,21 @@
+var waves = [], last = 0, lastw = 0;
+var rates = [ 2, 4, 8, 2, 256 ];
+
+return function (t) {
+ var rate = rates[Math.floor(t / 8) % rates.length];
+ if (t - lastw > 8) {
+ waves = waves.slice(-2);
+ lastw = t;
+ }
+ if (t - last > 1/rate) {
+ waves.push(Math.random());
+ last = t;
+ }
+ if (waves.length > 20) waves = waves.slice(-20)
+ var sum = 0;
+ for (var i = 0; i < waves.length; i++) {
+ sum += saw(Math.pow(2,waves[i]*8)*10 + 40);
+ }
+ return sum / waves.length;
+ function saw (x) { return 1 - t % (1/x) * x * 2 }
+}
View
19 warmup.js
@@ -0,0 +1,19 @@
+var melody = [ 800, 500, 450, 1600, 400, 400, 400 ];
+
+return function (t) {
+ var m = melody[Math.floor(t * 2) % melody.length];
+ var r = t > 10 ? m / 400 : 1;
+ return (sin(5+sin(100)) * 0.5
+ + sin(5+sin(100.0001)) * 0.5
+ + sin(t > 0 && t % (1/8) < 1/9 ? 50 * r : 0) * sin(200) * 2
+ + sin(t > 2 && t % (1/8) < 1/9 ? 100 * r : 0) * sin(400) * 2
+ + sin(t > 4 && t % (1/8) < 1/9 ? 200 * r : 0) * sin(800) * 2
+ + sin(t > 6 && t % (1/8) < 1/9 ? 400 * r : 0) * sin(1600) * 2
+ ) * (t % 16 > 12
+ ? sin_(sin_(m * 4, t % 1) * 100, 1+tri(800)+tri(1/400))
+ : 1
+ );
+ function sin (x) { return Math.sin(2 * Math.PI * t * x) }
+ function sin_ (x, t) { return Math.sin(2 * Math.PI * t * x) }
+ function tri (x) { return Math.abs(1 - t % (1/x) * x * 2) * 2 - 1}
+}
View
30 workpocalypse.js
@@ -0,0 +1,30 @@
+var work = [ 100, 400, 200, 300 ];
+var melody = [ 1, 2, 5, 1, 0, -2, 6 ];
+var plucks = [ 1, 5/2, -2, 1/9, 1/3 ];
+var times = [ 1, 1024, 64, 1, 1, 8064, 16, 256, 1, 32, 1024 ];
+
+return function (t) {
+ var w = work[Math.floor(t*4)%work.length];
+ var tm = times[Math.floor(t/8)%times.length];
+ var m = melody[Math.floor(t*tm)%melody.length];
+ var x = Math.pow(2,m/12);
+ var p = plucks[Math.floor(t/4)%plucks.length];
+ return pluck(t%(1/2), x/p*w+sin(sin(1/40)/w), 4, sin(4)*4+1)
+ + pluck(t%2,500*x,50,sin(1/4)*10+5)*2
+ + pluck(t%2,100*x,15,sin(1/2)*4)*10
+ + pluck(t%(1/Math.floor((t%2+1)*2))/2,w,5,sin(1/2)+1)*2
+ + pluck(t%(1/2),w*(m*t%4)/2,4,sin(8+sin(1/8)*4)*2+1)*0.5
+ + pluck(t%2,1200*x,8,sin(1/2)*4+5)
+ ;
+ function sin (x) { return Math.sin(2 * Math.PI * t * x) }
+}
+
+function pluck (t, freq, duration, steps) {
+ var n = duration;
+ var scalar = Math.max(0, 0.95 - (t * n) / ((t * n) + 1));
+ var sum = 0;
+ for (var i = 0; i < steps; i++) {
+ sum += Math.sin(2 * Math.PI * t * (freq + i * freq));
+ }
+ return scalar * sum / 6;
+}

0 comments on commit 8c250f7

Please sign in to comment.
Something went wrong with that request. Please try again.