@@ -70,6 +70,69 @@ const _brownNoiseBuffer = (function () {
70
70
* @constructor
71
71
* @param {String } type Type of noise can be 'white' (default),
72
72
* 'brown' or 'pink'.
73
+ * @example
74
+ * <div><code>
75
+ * let noise,fft;
76
+ * let playing = false;
77
+ *
78
+ * function setup() {
79
+ * let cnv = createCanvas(100, 100);
80
+ * cnv.mousePressed(playNoise);
81
+ * cnv.mouseReleased(stopNoise);
82
+ * noStroke();
83
+ * fill(255,0,255);
84
+ *
85
+ * // Create a new p5.Noise object
86
+ * noise = new p5.Noise();
87
+ * // Create a new p5.FFT object
88
+ * fft = new p5.FFT();
89
+ * }
90
+ *
91
+ * function draw() {
92
+ * background(220);
93
+ * // Display the current type of noise or "Tap to play"
94
+ * textAlign(CENTER, CENTER);
95
+ * if (playing) {
96
+ * text('Noise type: '+noise.getType(), width / 2, 20);
97
+ * } else {
98
+ * text('Tap to play', width / 2, 20);
99
+ * }
100
+ * drawSpectrum();
101
+ * }
102
+ *
103
+ * function playNoise() {
104
+ * noise.start();
105
+ * playing = true;
106
+ * }
107
+ *
108
+ * function stopNoise() {
109
+ * noise.stop();
110
+ * playing = false;
111
+ *
112
+ * // Change the type of noise
113
+ * if (noise.getType() === 'white') {
114
+ * noise.setType('pink');
115
+ * } else if (noise.getType() === 'pink'){
116
+ * noise.setType('brown');
117
+ * } else {
118
+ * noise.setType('white');
119
+ * }
120
+ * }
121
+ *
122
+ * function drawSpectrum() {
123
+ * // Get and draw the frequency spectrum of the noise
124
+ * let spectrum = fft.analyze();
125
+ * beginShape();
126
+ * vertex(0, height);
127
+ * for (let i = 0; i < spectrum.length; i++) {
128
+ * let x = map(i, 0, spectrum.length, 0, width);
129
+ * let h = map(spectrum[i], 0, 255, height, 0);
130
+ * vertex(x, h);
131
+ * }
132
+ * vertex(width, height);
133
+ * endShape();
134
+ * }
135
+ * </code> </div>
73
136
*/
74
137
class Noise extends Oscillator {
75
138
constructor ( type ) {
0 commit comments