Skip to content

Commit ef23528

Browse files
authored
Merge pull request #809 from processing/new-20-docs
Update 2.0 documentation
2 parents b6a0e4a + 85b1f7c commit ef23528

File tree

1,103 files changed

+43413
-52414
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,103 files changed

+43413
-52414
lines changed

Diff for: public/reference/data.json

+22,932-25,836
Large diffs are not rendered by default.

Diff for: public/search-indices/en.json

+1-1
Large diffs are not rendered by default.

Diff for: public/search-indices/es.json

+1-1
Large diffs are not rendered by default.

Diff for: public/search-indices/hi.json

+1-1
Large diffs are not rendered by default.

Diff for: public/search-indices/ko.json

+1-1
Large diffs are not rendered by default.

Diff for: public/search-indices/zh-Hans.json

+1-1
Large diffs are not rendered by default.

Diff for: src/content/contributor-docs/en/creating_libraries.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,4 @@ p5.prototype.myMethod = function(){
306306

307307
**Examples are great, too!** They show people what your library can do. Because this is all JavaScript, people can see them running online before they download anything.[ ](http://jsfiddle.net/) You can create a collection of examples on the p5.js web editor to showcase how your library works.
308308

309-
**Submit your library!** Once your library is ready for distribution and you’d like it included on the [p5js.org/libraries](https://p5js.org/libraries/) page, please submit a pull request on the p5.js website GitHub repository following [this instruction](https://github.com/processing/p5.js-website/blob/main/docs/contributing_libraries.md)!
309+
**Submit your library!** Once your library is ready for distribution and you’d like it included on the [p5js.org/libraries](https://p5js.org/libraries/) page, please submit a pull request on the p5.js website GitHub repository following [this intruction](https://github.com/processing/p5.js-website/blob/main/docs/contributing_libraries.md)!

Diff for: src/content/contributor-docs/en/jsdoc.mdx

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
---
2+
title: |
3+
JSDoc Best Practices
4+
description: >
5+
Documentation on the website is built from the comments in the p5.js repo.
6+
Here are a few things to keep in mind in order for the documentation to be
7+
parsed correctly!
8+
---
9+
10+
11+
Documentation on the website is built from the comments in the p5.js repo. Here are a few things to keep in mind in order for the documentation to be parsed correctly!
12+
13+
## For everything
14+
15+
* At the top of a file, add a comment with the `@module` tag, and optionally also the `@submodule`. These reference the category and subcategory names that the contents of the file should appear under in the reference:
16+
17+
e.g. for just a category:
18+
19+
```js
20+
/**
21+
* @module Rendering
22+
*/
23+
```
24+
25+
e.g. for both:
26+
27+
```js
28+
/**
29+
* @module Data
30+
* @submodule LocalStorage
31+
*/
32+
```
33+
34+
## For classes
35+
36+
* Create classes *outside* of the addon function, and assign them to `p5` *inside.* The class name should be the same always:
37+
38+
```js
39+
class MyClass {
40+
// ...
41+
}
42+
43+
export default function myAddon(p5, fn) {
44+
p5.MyClass = MyClass;
45+
}
46+
```
47+
48+
* Document class methods directly above the members in classes, *without* a `@method` tag:
49+
50+
```js
51+
class MyClass {
52+
/**
53+
* Description goes here
54+
*/
55+
myMethod() {
56+
return 4;
57+
}
58+
}
59+
```
60+
61+
* Documentation for the class itself should go at the spot where the class is added to `p5` and not right next to the class definition. This needs to include the `@class` tag, including a `p5.` prefix on the class name. Also include the parameters for the constructor in this description, if they exist.
62+
63+
```js
64+
class MyClass {
65+
constructor(n) {
66+
this.n = n;
67+
}
68+
}
69+
70+
export default function myAddon(p5, fn) {
71+
/**
72+
* Description of the class goes here!
73+
*
74+
* @class p5.MyClass
75+
* @param {Number} n A number to pass in
76+
*/
77+
p5.MyClass = MyClass;
78+
}
79+
```
80+
81+
* Documentation for class properties should appear after the class is added to `p5`, not within the class itself. It needs to have the `@for` tag referencing its class, and the `@property` tag naming the property itself:
82+
83+
```js
84+
class MyClass {
85+
myProperty;
86+
constructor() {
87+
myProperty = 2;
88+
}
89+
}
90+
91+
export default function myAddon(p5, fn) {
92+
/**
93+
* Description of the class goes here!
94+
*
95+
* @class p5.MyClass
96+
*/
97+
p5.MyClass = MyClass;
98+
99+
/**
100+
* Description of the property goes here!
101+
*
102+
* @property {Number} myProperty
103+
* @for p5.MyClass
104+
*/
105+
}
106+
```
107+
108+
## For global functions
109+
110+
* Add a comment with the `@method` tag listing its name:
111+
112+
```js
113+
export default function myAddon(p5, fn) {
114+
/**
115+
* Description goes here!
116+
*
117+
* @method myFunction
118+
*/
119+
p5.myFunction = function() {
120+
return 8;
121+
};
122+
}
123+
```
124+
125+
* For dynamically generated methods, do the same as usual, but add `@for p5`.
126+
127+
```js
128+
function myAddon(p5, fn) {
129+
for (const key of ['nameA', 'nameB']) {
130+
fn[key] = function() {
131+
return `Hello from ${key}!`;
132+
};
133+
}
134+
135+
/**
136+
* @method nameA
137+
* @for p5
138+
*/
139+
140+
/**
141+
* @method nameB
142+
* @for p5
143+
*/
144+
}
145+
```
146+
147+
* Mark things that you don't want showing up as `@private`. This is done automatically for methods whose names start with `_`.
148+
149+
```js
150+
class MyClass {
151+
/**
152+
* @private
153+
*/
154+
privateMethodA() {
155+
// ...
156+
}
157+
158+
_privateMethodB() {
159+
// ...
160+
}
161+
}
162+
```

Diff for: src/content/reference/en/p5.Amplitude/getLevel.mdx

+4-44
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,14 @@
22
title: getLevel
33
module: p5.sound
44
submodule: p5.sound
5-
file: lib/addons/p5.sound.js
6-
description: |
7-
<p>Returns a single Amplitude reading at the moment it is called.
8-
For continuous readings, run in the draw loop.</p>
9-
line: 3209
5+
file: src/Amplitude.js
6+
description: Get the current amplitude value of a sound.
7+
line: 63
108
isConstructor: false
119
itemtype: method
12-
example:
13-
- |-
14-
15-
<div><code>
16-
function preload(){
17-
sound = loadSound('/assets/beat.mp3');
18-
}
19-
20-
function setup() {
21-
let cnv = createCanvas(100, 100);
22-
cnv.mouseClicked(toggleSound);
23-
amplitude = new p5.Amplitude();
24-
}
25-
26-
function draw() {
27-
background(220, 150);
28-
textAlign(CENTER);
29-
text('tap to play', width/2, 20);
30-
31-
let level = amplitude.getLevel();
32-
let size = map(level, 0, 1, 0, 200);
33-
ellipse(width/2, height/2, size, size);
34-
}
35-
36-
function toggleSound(){
37-
if (sound.isPlaying()) {
38-
sound.stop();
39-
} else {
40-
sound.play();
41-
}
42-
}
43-
</code></div>
4410
class: p5.Amplitude
45-
params:
46-
- name: channel
47-
description: |
48-
<p>Optionally return only channel 0 (left) or 1 (right)</p>
49-
type: Number
50-
optional: true
5111
return:
52-
description: Amplitude as a number between 0.0 and 1.0
12+
description: Amplitude level (volume) of a sound.
5313
type: Number
5414
chainable: false
5515
---

Diff for: src/content/reference/en/p5.Amplitude/setInput.mdx

+6-53
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,16 @@
22
title: setInput
33
module: p5.sound
44
submodule: p5.sound
5-
file: lib/addons/p5.sound.js
6-
description: |
7-
<p>Connects to the p5sound instance (main output) by default.
8-
Optionally, you can pass in a specific source (i.e. a soundfile).</p>
9-
line: 3117
5+
file: src/Amplitude.js
6+
description: Connect an audio source to the amplitude object.
7+
line: 53
108
isConstructor: false
119
itemtype: method
12-
example:
13-
- |-
14-
15-
<div><code>
16-
function preload(){
17-
sound1 = loadSound('/assets/beat.mp3');
18-
sound2 = loadSound('/assets/drum.mp3');
19-
}
20-
function setup(){
21-
cnv = createCanvas(100, 100);
22-
cnv.mouseClicked(toggleSound);
23-
24-
amplitude = new p5.Amplitude();
25-
amplitude.setInput(sound2);
26-
}
27-
28-
function draw() {
29-
background(220);
30-
text('tap to play', 20, 20);
31-
32-
let level = amplitude.getLevel();
33-
let size = map(level, 0, 1, 0, 200);
34-
ellipse(width/2, height/2, size, size);
35-
}
36-
37-
function toggleSound(){
38-
if (sound1.isPlaying() && sound2.isPlaying()) {
39-
sound1.stop();
40-
sound2.stop();
41-
} else {
42-
sound1.play();
43-
sound2.play();
44-
}
45-
}
46-
</code></div>
4710
class: p5.Amplitude
4811
params:
49-
- name: snd
50-
description: |
51-
<p>set the sound source
52-
(optional, defaults to
53-
main output)</p>
54-
type: SoundObject|undefined
55-
optional: true
56-
- name: smoothing
57-
description: |
58-
<p>a range between 0.0 and 1.0
59-
to smooth amplitude readings</p>
60-
type: Number|undefined
61-
optional: true
12+
- name: input
13+
description: '- An object that has audio output.'
14+
type: Object
6215
chainable: false
6316
---
6417

Diff for: src/content/reference/en/p5.Amplitude/smooth.mdx

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
title: smooth
33
module: p5.sound
44
submodule: p5.sound
5-
file: lib/addons/p5.sound.js
6-
description: |
7-
<p>Smooth Amplitude analysis by averaging with the last analysis
8-
frame. Off by default.</p>
9-
line: 3293
5+
file: src/Amplitude.js
6+
description: Get the current amplitude value of a sound.
7+
line: 73
108
isConstructor: false
119
itemtype: method
1210
class: p5.Amplitude
1311
params:
14-
- name: set
15-
description: |
16-
<p>smoothing from 0.0 <= 1</p>
12+
- name: Smooth
13+
description: >-
14+
Amplitude analysis by averaging with the last analysis frame. Off by
15+
default.
1716
type: Number
1817
chainable: false
1918
---

Diff for: src/content/reference/en/p5.Amplitude/toggleNormalize.mdx

-29
This file was deleted.

Diff for: src/content/reference/en/p5.AudioIn/amp.mdx

+5-12
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,16 @@
22
title: amp
33
module: p5.sound
44
submodule: p5.sound
5-
file: lib/addons/p5.sound.js
6-
description: |
7-
<p>Set amplitude (volume) of a mic input between 0 and 1.0. <br/></p>
8-
line: 6257
5+
file: src/AudioIn.js
6+
description: Set amplitude (volume) of a mic input between 0 and 1.0.
7+
line: 81
98
isConstructor: false
109
itemtype: method
1110
class: p5.AudioIn
1211
params:
13-
- name: vol
14-
description: |
15-
<p>between 0 and 1.0</p>
12+
- name: amplitudeAmount
13+
description: An amplitude value between 0 and 1.
1614
type: Number
17-
- name: time
18-
description: |
19-
<p>ramp time (optional)</p>
20-
type: Number
21-
optional: true
2215
chainable: false
2316
---
2417

Diff for: src/content/reference/en/p5.AudioIn/amplitude.mdx

-16
This file was deleted.

0 commit comments

Comments
 (0)