Advertisement
KekSec

BRAINFUCK Trip Bineural Beat Algorithm UserScript

Oct 29th, 2015
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        BRAINFUCK
  3. // @namespace   BRAINFUCK
  4. // @description This MAY KILL YOU OR GIVE YOU A SEZIURE, OR MAKE YOU TRIP THE FUCK OUT, USE AT OWN RISK
  5. // @include     *
  6. // @version     1
  7. // @grant       none
  8. // Created by http://pastebin.com/u/SalamanderSquad
  9. // ==/UserScript==
  10.  
  11. //LSD.js
  12. //Modified Isotronic wave generator from http://onlinetonegenerator.com/
  13. //The code can be found here if anyone is interested http://onlinetonegenerator.com/js/binaural.js
  14.  
  15.  
  16. var contextClass = (window.AudioContext ||
  17.     window.webkitAudioContext ||
  18.     window.mozAudioContext ||
  19.     window.oAudioContext ||
  20.     window.msAudioContext);
  21.  
  22. if (contextClass) {
  23.     // Web Audio API is available.
  24.     var context = new contextClass();
  25. }
  26.  
  27. var oscOn = function (freq1, freq2) {
  28.  
  29.     merger = context.createChannelMerger(2);
  30.  
  31.     oscillator1 = context.createOscillator();
  32.     oscillator1.type = 0;
  33.     oscillator1.frequency.value = freq1;
  34.     gainNode = context.createGain ? context.createGain() : context.createGainNode();
  35.     oscillator1.connect(gainNode, 0, 0);
  36.     // gainNode.connect(context.destination,0,0);
  37.     gainNode.gain.value = .1;
  38.     oscillator1.start ? oscillator1.start(0) : oscillator1.noteOn(0)
  39.  
  40.     gainNode.connect(merger, 0, 1);
  41.  
  42.     oscillator2 = context.createOscillator();
  43.     oscillator2.type = 0;
  44.     oscillator2.frequency.value = freq2;
  45.     gainNode = context.createGain ? context.createGain() : context.createGainNode();
  46.     oscillator2.connect(gainNode);
  47.     // gainNode.connect(context.destination,0,1);
  48.     gainNode.connect(merger, 0, 0);
  49.  
  50.  
  51.     gainNode.gain.value = .1;
  52.     oscillator2.start ? oscillator2.start(0) : oscillator2.noteOn(0)
  53.  
  54.     merger.connect(context.destination);
  55.  
  56.  
  57. }
  58.  
  59. function start() {
  60.     if (typeof oscillator1 != 'undefined') oscillator1.disconnect();
  61.     if (typeof oscillator2 != 'undefined') oscillator2.disconnect();
  62.     rand = getRandomInt(432, 852) //432Hz and 852Hz are the lowest and highest meditation tones I could find with a little bit of searching
  63.     oscOn(rand, rand + 3);
  64. }
  65.  
  66. function stop() {
  67.     oscillator1.disconnect();
  68.     oscillator2.disconnect();
  69. }
  70.  
  71. function getRandomInt(min, max) {
  72.     return Math.floor(Math.random() * (max - min + 1)) + min;
  73. }
  74.  
  75. function BRAINFUCKTrip() {
  76.     start();
  77.  
  78.     var randColour = '#'+Math.floor(Math.random()*16777215).toString(16);
  79.     document.body.style.background = randColour; //Take advantage of the pavlovian affect to associate different colours with different brain waves, which is basically what a psychedelic does.
  80. }
  81.  
  82. start();
  83.  
  84. setTimeout(BRAINFUCKTrip, 100);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement