Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
  <h1>Surf Simulator</h1>
  <div id="preamble"><a href="http://kentskyo.com/sculpting-sound/">Hacking a chunk of noise</a>
  </div>

  <div id="dials">
    <div id="panel1">
      <div class="dlab">Interval</div>
      <div id="interval"></div>
    </div>
    <div id="panel2">
      <div class="dlab">Power</div>
      <div id="power"></div>
    </div>
    <div id="panel3">
      <div class="dlab">Cutoff</div>
      <div id="cutoff"></div>
    </div>
  </div>

  <div id="p5Panel"></div>
  <div id="switchLabel">Sound Switch</div>
  <div id="sndswitch"></div>
</div>    


              
            
!

CSS

              
                html, body {
  height: 100%;
}

body {
  margin: 0;
  padding: 0; 
  background-color: #000000;
  color: #1ecbea;
}
.container {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  margin: 1em;
  padding: 1em;
  border: 1px solid #1ecbea;
}

.dlab {
  text-align: center;
  padding-bottom: 0.5em;
}

#dials {
  display: flex;
  flex-direction: row;
}

#panel1, #panel2 {
  padding-right: 2em;
}

#p5Panel {
  padding-top: 1em;
  padding-bottom: 1em;
}

#preamble {
  padding-bottom: 1.5em;
  text-alignment: center;
}

#sndswitch {
  padding-top: 0.5em;
}

#footer {
  padding-bottom: 1.5em;
}



a:link, a:visited {
    color: #1ecbea;
    text-decoration: none;
}


              
            
!

JS

              
                var carrier; 
var modulator; 
var fft; 
var lop; 
var reverb;
var pCanvas;
var interval, power, cutoff, sndswitch; // ui elements

function setup() {
    pCanvas = createCanvas(330,200);
    pCanvas.parent('p5Panel');
  	pCanvas.class("p5Canvas")
    // fill(135, 206, 235);
    fill(2, 168, 243); 
    background(30); 
    carrier = new p5.Noise("white");
    lop = new p5.Filter("lowpass");
    lop.freq(900);
    carrier.amp(0);
    carrier.disconnect();
    carrier.connect(lop);
    modulator = new p5.Oscillator('sine');
    modulator.disconnect();  
    modulator.freq(0.05);
    modulator.amp(0.15);
    modulator.start();
    // Modulate the carrier's amplitude with the modulator
    // Optionally, we can scale the signal.
    //carrier.amp(modulator.scale(0,1,0,1));
    carrier.amp(modulator);
    carrier.stop();
    fft = new p5.FFT();

    Nexus.colors.accent = "#E040FB";
    Nexus.colors.fill = "#212121";
    Nexus.colors.dark = "#212121";
  
    interval = new Nexus.Dial('#interval');
    interval.min = 0;
    interval.max = 100;
    interval.resize(100,100);
    interval.value = 0;

    power = new Nexus.Dial('#power');
    power.min = 0;
    power.max = 100;
    power.resize(100,100);
    power.value = 15;

    cutoff = new Nexus.Dial('#cutoff');
    cutoff.min = 100;
    cutoff.max = 5000;
    cutoff.resize(100,100);
    cutoff.value = 900;
  
    sndswitch = new Nexus.Toggle('#sndswitch');
    sndswitch.state = false;
    sndswitch.resize(85,25);

    wireui();
}

function draw() {
    background(30);
	  var spectrum = fft.analyze();
  	noStroke();
  	for (var i = 0; i < spectrum.length; i++) {
    	var x = map(i, 0, spectrum.length, 0, width);
    	var h = -height + map(spectrum[i], 0, 255, height, 0);
    	rect(x, height, width/spectrum.length, h);
    	}
} // end of draw

function wireui() {
interval.on('change', function(data) {
     var f = map(data,0,100,0.05,0.1); 
     modulator.freq(f);
     // intervalLabel.innerHTML = f;    
  });

power.on('change', function(data) {
     var f = map(data,0,100,0,1); 
     modulator.amp(f);
     // intervalLabel.innerHTML = f;    
  });

cutoff.on('change', function(data) {
    lop.freq(data);
     // intervalLabel.innerHTML = f;    
  });

sndswitch.on('change',function(v) {
    if(v) {
      		console.log("start...");
          carrier.start();
    }
  	else {
      		console.log("stop...");
          carrier.stop();
    }
});

}


// $(function() {
// 	$("#freq").knob({
//   	'change' : function (v) {
//      var f = map(v,0,100,0.05,0.1); 
//      modulator.freq(f);
//   }});
// 	$("#power").knob({
//     'change' : function (v) {
//      var f = map(v,0,100,0,1); 
//      modulator.amp(f);
//   }});
//   $("#lop").knob({
//   	'change' : function (v) {
//     lop.freq(v);
//   }});  
 
// $("#myonoffswitch").change(function() {
//     if(this.checked) {
//       		console.log("start...");
//           carrier.start();
//     }
//   	else {
//       		console.log("stop...");
//           carrier.stop();
//     }
// });
  


              
            
!
999px

Console