From 5d72e5dee76243f21bd23c6a304676420f258b4f Mon Sep 17 00:00:00 2001 From: Lisa Mabley Date: Sun, 15 Sep 2019 11:46:00 -0500 Subject: [PATCH 1/5] Replace const with let in Inline Documentation file, and add instruction for future contributors to use let going forward. --- developer_docs/inline_documentation.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/developer_docs/inline_documentation.md b/developer_docs/inline_documentation.md index c2f2af87ce..4426e3e18a 100644 --- a/developer_docs/inline_documentation.md +++ b/developer_docs/inline_documentation.md @@ -173,7 +173,7 @@ Constructors are defined with `@class`. Each constructor should have the tag `@c ## Adding example code -Optionally, you can add examples with `@example`. Example code can be placed between `` tags with comments included. Unless otherwise specified with a `setup()` function, each `` block is automatically run on a canvas of 100x100 pixels with a gray background. Please see examples in other src files to make sure it is formatted correctly. +Optionally, you can add examples with `@example`. Example code can be placed between `` tags with comments included. Unless otherwise specified with a `setup()` function, each `` block is automatically run on a canvas of 100x100 pixels with a gray background. Define all variables with `let` in examples, as the lowest barrier for beginners learning JS. Please see examples in other src files to make sure it is formatted correctly. ``` @example @@ -213,7 +213,7 @@ If you do not want the example to be run as part of the build tests (for example @example
function setup() { - const c = createCanvas(100, 100); + let c = createCanvas(100, 100); saveCanvas(c, 'myCanvas', 'jpg'); }
@@ -235,18 +235,18 @@ let xoff = 0.0; function draw() { background(204); xoff = xoff + 0.01; - const n = noise(xoff) * width; + let n = noise(xoff) * width; line(n, 0, n, height); }
-const noiseScale=0.02; +let noiseScale=0.02; function draw() { background(0); for (let x=0; x < width; x++) { - const noiseVal = noise((mouseX+x)*noiseScale, mouseY*noiseScale); + let noiseVal = noise((mouseX+x)*noiseScale, mouseY*noiseScale); stroke(noiseVal*255); line(x, mouseY+noiseVal*80, x, height); } From 9fe471efa9d08e185674bbecefa87701f7f6735e Mon Sep 17 00:00:00 2001 From: Lisa Mabley Date: Sun, 15 Sep 2019 12:03:21 -0500 Subject: [PATCH 2/5] Replace var with let --- lib/addons/p5.sound.js | 406 ++++++++++++++++++++--------------------- 1 file changed, 203 insertions(+), 203 deletions(-) diff --git a/lib/addons/p5.sound.js b/lib/addons/p5.sound.js index 33b130454a..1f509e3513 100644 --- a/lib/addons/p5.sound.js +++ b/lib/addons/p5.sound.js @@ -1030,7 +1030,7 @@ audiocontext = function (StartAudioContext, Context, Tone) { * if (getAudioContext().state !== 'running') { * getAudioContext().resume(); * } - * var synth = new p5.MonoSynth(); + * let synth = new p5.MonoSynth(); * synth.play('A4', 0.5, 0, 0.2); * } * @@ -1065,10 +1065,10 @@ audiocontext = function (StartAudioContext, Context, Tone) { * @example *
* function setup() { - * var myDiv = createDiv('click to start audio'); + * let myDiv = createDiv('click to start audio'); * myDiv.position(0, 0); * - * var mySynth = new p5.MonoSynth(); + * let mySynth = new p5.MonoSynth(); * * // This won't play until the context has started * mySynth.play('A6'); @@ -1248,8 +1248,8 @@ helpers = function () { * @return {Number} Frequency value of the given MIDI note * @example *
- * var notes = [60, 64, 67, 72]; - * var i = 0; + * let notes = [60, 64, 67, 72]; + * let i = 0; * * function setup() { * osc = new p5.Oscillator('Triangle'); @@ -1258,7 +1258,7 @@ helpers = function () { * } * * function draw() { - * var freq = midiToFreq(notes[i]); + * let freq = midiToFreq(notes[i]); * osc.freq(freq); * i++; * if (i >= notes.length){ @@ -2032,7 +2032,7 @@ soundfile = function () { * @param {String} str 'restart' or 'sustain' or 'untilDone' * @example *
- * var mySound; + * let mySound; * function preload(){ * mySound = loadSound('assets/Damscray_DancingTiger.mp3'); * } @@ -2077,7 +2077,7 @@ soundfile = function () { * seconds from now * @example *
- * var soundFile; + * let soundFile; * * function preload() { * soundFormats('ogg', 'mp3'); @@ -2289,8 +2289,8 @@ soundfile = function () { * @example *
* - * var ball = {}; - * var soundFile; + * let ball = {}; + * let soundFile; * * function preload() { * soundFormats('ogg', 'mp3'); @@ -2306,7 +2306,7 @@ soundfile = function () { * function mousePressed(){ * // map the ball's x location to a panning degree * // between -1.0 (left) and 1.0 (right) - * var panning = map(ball.x, 0., width,-1.0, 1.0); + * let panning = map(ball.x, 0., width,-1.0, 1.0); * soundFile.pan(panning); * soundFile.play(); * } @@ -2337,7 +2337,7 @@ soundfile = function () { * Values less than zero play backwards. * @example *
- * var song; + * let song; * * function preload() { * song = loadSound('assets/Damscray_DancingTiger.mp3'); @@ -2352,7 +2352,7 @@ soundfile = function () { * * // Set the rate to a range between 0.1 and 4 * // Changing the rate also alters the pitch - * var speed = map(mouseY, 0.1, height, 0, 2); + * let speed = map(mouseY, 0.1, height, 0, 2); * speed = constrain(speed, 0.01, 4); * song.rate(speed); * @@ -2536,7 +2536,7 @@ soundfile = function () { * @method reverseBuffer * @example *
- * var drum; + * let drum; * * function preload() { * drum = loadSound('assets/drum.mp3'); @@ -2969,7 +2969,7 @@ soundfile = function () { * useful for removeCue(id) * @example *
- * var mySound; + * let mySound; * function preload() { * mySound = loadSound('assets/beat.mp3'); * } @@ -3066,13 +3066,13 @@ soundfile = function () { * Save a p5.SoundFile as a .wav file. The browser will prompt the user * to download the file to their device. To upload a file to a server, see * getBlob - * + * * @method save * @param {String} [fileName] name of the resulting .wav file. * @example *
- * var inp, button, mySound; - * var fileName = 'cool'; + * let inp, button, mySound; + * let fileName = 'cool'; * function preload() { * mySound = loadSound('assets/doorbell.mp3'); * } @@ -3113,11 +3113,11 @@ soundfile = function () { * * function setup() { * noCanvas(); - * var soundBlob = mySound.getBlob(); + * let soundBlob = mySound.getBlob(); * * // Now we can send the blob to a server... - * var serverUrl = 'https://jsonplaceholder.typicode.com/posts'; - * var httpRequestOptions = { + * let serverUrl = 'https://jsonplaceholder.typicode.com/posts'; + * let httpRequestOptions = { * method: 'POST', * body: new FormData().append('soundBlob', soundBlob), * headers: new Headers({ @@ -3127,15 +3127,15 @@ soundfile = function () { * httpDo(serverUrl, httpRequestOptions); * * // We can also create an `ObjectURL` pointing to the Blob - * var blobUrl = URL.createObjectURL(soundBlob); + * let blobUrl = URL.createObjectURL(soundBlob); * * // The `