Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                
<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.min.js"></script>
     <script src="https://cdn.jsdelivr.net/gh/molleindustria/p5.play/lib/p5.play.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/addons/p5.dom.min.js"></script>
  
    <link rel="stylesheet" type="text/css" href="style.css">
    <meta charset="utf-8" />

  </head>
  <body>
    <script src="sketch.js"></script>
  </body>
</html>

              
            
!

CSS

              
                html, body {
  margin: 0;
  padding: 0;
}
              
            
!

JS

              
                /*
Creating a simple synthesizer using Tone.js
Programming Digital Media
Code by Matthew A. Bardin [2020]
*/

let simpSynth; //first, you need a variable to store each synth you want to make.

function setup() {
  createCanvas(400, 400);
//then you assign that variable to be a new Tone.Synth object and sets its unique parapeters
  simpSynth = new Tone.Synth({
    oscillator: {
      type: "square" //the type of waveform the synthesizer produces. Can be square, since, triangle, or sawtooth
    },
    envelope: { //sets the various sound properties for the synth
      attack: 0.15,
      decay: 0.15,
      sustain: 1,
      release: 5
    }
  }).toDestination(); //sends the synth's output to the master speakers



}
//never trigger sounds in the draw function. it will cause playback malfunctions
function draw() {
  background(220);
  textAlign(CENTER);
  textFont('futura');
  text("Click me to play 'tuning A'", width / 2, height / 2);
 
}

//use mousePressed or keyPressed instead
function mousePressed() {
  //triggers the synth. you can specify the pitch and the duration
  simpSynth.triggerAttackRelease("A4", 1);
}
              
            
!
999px

Console