Pen Settings



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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


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


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.


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.


    <script src=""></script>
     <script src=""></script>
    <script src=""></script>
    <link rel="stylesheet" type="text/css" href="style.css">
    <meta charset="utf-8" />

    <script src="sketch.js"></script>



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


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

let simpSynth, attack, decay, sus, release; //first, you need a variable to store each synth you want to makea

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.05,
      decay: 0.5,
      sustain: 1,
      release: 5
  }).toDestination(); //sends the synth's output to the master speakers

  attack = createSlider(0, 1, 0.5, 0.01);
  decay = createSlider(0, 1, 0.5, 0.01);
  decay.position(150, 300);
  sus = createSlider(0, 1, 0.5, 0.01);
  release = createSlider(0, 1, 0.5, 0.01);
  release.position(150, 350);

//never trigger sounds in the draw function. it will cause playback malfunctions
function draw() {
  text("Press spacebar to play 'tuning A'", width / 2, height / 2- 70);
  text("Adjust the envelope with the sliders", width / 2, height / 2);
  text('attack', 55, 290);
  text('decay', 200, 290);
  text('sustain', 50, 350);
  text('release', 195, 350);
  simpSynth.envelope.attack = attack.value();
  simpSynth.envelope.decay = decay.value();
  simpSynth.envelope.sustain = sus.value();
  simpSynth.envelope.release = release.value();

function keyPressed() {
  //triggers the synth. you can specify the pitch and the duration
  if(keyCode === 32){
  simpSynth.triggerAttackRelease("A4", 1);