8
8
import p5 from '../core/main' ;
9
9
10
10
/**
11
- * p5.js communicates with the clock on your computer. The <a href="#/p5/day">day()</a> function
12
- * returns the current day as a value from 1 - 31.
11
+ * Returns the current day as a number from 1–31.
13
12
*
14
13
* @method day
15
- * @return {Integer } the current day
14
+ * @return {Integer } current day between 1 and 31.
15
+ *
16
16
* @example
17
17
* <div>
18
18
* <code>
19
- * let d = day();
20
- * text('Current day: \n' + d, 5, 50);
21
- * describe('Current day is displayed');
19
+ * function setup() {
20
+ * createCanvas(100, 100);
21
+ *
22
+ * background(200);
23
+ *
24
+ * // Get the current day.
25
+ * let d = day();
26
+ *
27
+ * // Style the text.
28
+ * textAlign(LEFT, CENTER);
29
+ * textSize(12);
30
+ * textFont('Courier New');
31
+ *
32
+ * // Display the day.
33
+ * text(`Current day: ${d}`, 20, 50, 60);
34
+ *
35
+ * describe(`The text 'Current day: ${d}' written in black on a gray background.`);
36
+ * }
22
37
* </code>
23
38
* </div>
24
39
*/
@@ -27,17 +42,32 @@ p5.prototype.day = function() {
27
42
} ;
28
43
29
44
/**
30
- * p5.js communicates with the clock on your computer. The <a href="#/p5/hour">hour()</a> function
31
- * returns the current hour as a value from 0 - 23.
45
+ * Returns the current hour as a number from 0–23.
32
46
*
33
47
* @method hour
34
- * @return {Integer } the current hour
48
+ * @return {Integer } current hour between 0 and 23.
49
+ *
35
50
* @example
36
51
* <div>
37
52
* <code>
38
- * let h = hour();
39
- * text('Current hour:\n' + h, 5, 50);
40
- * describe('Current hour is displayed');
53
+ * function setup() {
54
+ * createCanvas(100, 100);
55
+ *
56
+ * background(200);
57
+ *
58
+ * // Get the current hour.
59
+ * let h = hour();
60
+ *
61
+ * // Style the text.
62
+ * textAlign(LEFT, CENTER);
63
+ * textSize(12);
64
+ * textFont('Courier New');
65
+ *
66
+ * // Display the hour.
67
+ * text(`Current hour: ${h}`, 20, 50, 60);
68
+ *
69
+ * describe(`The text 'Current hour: ${h}' written in black on a gray background.`);
70
+ * }
41
71
* </code>
42
72
* </div>
43
73
*/
@@ -46,17 +76,32 @@ p5.prototype.hour = function() {
46
76
} ;
47
77
48
78
/**
49
- * p5.js communicates with the clock on your computer. The <a href="#/p5/minute">minute()</a> function
50
- * returns the current minute as a value from 0 - 59.
79
+ * Returns the current minute as a number from 0–59.
51
80
*
52
81
* @method minute
53
- * @return {Integer } the current minute
82
+ * @return {Integer } current minute between 0 and 59.
83
+ *
54
84
* @example
55
85
* <div>
56
86
* <code>
57
- * let m = minute();
58
- * text('Current minute: \n' + m, 5, 50);
59
- * describe('Current minute is displayed');
87
+ * function setup() {
88
+ * createCanvas(100, 100);
89
+ *
90
+ * background(200);
91
+ *
92
+ * // Get the current minute.
93
+ * let m = minute();
94
+ *
95
+ * // Style the text.
96
+ * textAlign(LEFT, CENTER);
97
+ * textSize(12);
98
+ * textFont('Courier New');
99
+ *
100
+ * // Display the minute.
101
+ * text(`Current minute: ${m}`, 10, 50, 80);
102
+ *
103
+ * describe(`The text 'Current minute: ${m}' written in black on a gray background.`);
104
+ * }
60
105
* </code>
61
106
* </div>
62
107
*/
@@ -65,18 +110,123 @@ p5.prototype.minute = function() {
65
110
} ;
66
111
67
112
/**
68
- * Returns the number of milliseconds (thousandths of a second) since
69
- * starting the sketch (when `setup()` is called). This information is often
70
- * used for timing events and animation sequences.
113
+ * Returns the number of milliseconds since a sketch started running.
114
+ *
115
+ * `millis()` keeps track of how long a sketch has been running in
116
+ * milliseconds (thousandths of a second). This information is often
117
+ * helpful for timing events and animations.
118
+ *
119
+ * If a sketch has a
120
+ * <a href="#/p5/setup">setup()</a> function, then `millis()` begins tracking
121
+ * time before the code in <a href="#/p5/setup">setup()</a> runs. If a
122
+ * sketch includes a <a href="#/p5/preload">preload()</a> function, then
123
+ * `millis()` begins tracking time as soon as the code in
124
+ * <a href="#/p5/preload">preload()</a> starts running.
71
125
*
72
126
* @method millis
73
- * @return {Number } the number of milliseconds since starting the sketch
127
+ * @return {Number } number of milliseconds since starting the sketch.
128
+ *
74
129
* @example
75
130
* <div>
76
131
* <code>
77
- * let millisecond = millis();
78
- * text('Milliseconds \nrunning: \n' + millisecond, 5, 40);
79
- * describe('number of milliseconds since sketch has started displayed');
132
+ * function setup() {
133
+ * createCanvas(100, 100);
134
+ *
135
+ * background(200);
136
+ *
137
+ * // Get the number of milliseconds the sketch has run.
138
+ * let ms = millis();
139
+ *
140
+ * // Style the text.
141
+ * textAlign(LEFT, CENTER);
142
+ * textSize(10);
143
+ * textFont('Courier New');
144
+ *
145
+ * // Display how long it took setup() to be called.
146
+ * text(`Startup time: ${round(ms, 2)} ms`, 5, 50, 90);
147
+ *
148
+ * describe(
149
+ * `The text 'Startup time: ${round(ms, 2)} ms' written in black on a gray background.`
150
+ * );
151
+ * }
152
+ * </code>
153
+ * </div>
154
+ *
155
+ * <div>
156
+ * <code>
157
+ * function setup() {
158
+ * createCanvas(100, 100);
159
+ *
160
+ * describe('The text "Running time: S sec" written in black on a gray background. The number S increases as the sketch runs.');
161
+ * }
162
+ *
163
+ * function draw() {
164
+ * background(200);
165
+ *
166
+ * // Get the number of seconds the sketch has run.
167
+ * let s = millis() / 1000;
168
+ *
169
+ * // Style the text.
170
+ * textAlign(LEFT, CENTER);
171
+ * textSize(10);
172
+ * textFont('Courier New');
173
+ *
174
+ * // Display how long the sketch has run.
175
+ * text(`Running time: ${nf(s, 1, 1)} sec`, 5, 50, 90);
176
+ * }
177
+ * </code>
178
+ * </div>
179
+ *
180
+ * <div>
181
+ * <code>
182
+ * function setup() {
183
+ * createCanvas(100, 100);
184
+ *
185
+ * describe('A white circle oscillates left and right on a gray background.');
186
+ * }
187
+ *
188
+ * function draw() {
189
+ * background(200);
190
+ *
191
+ * // Get the number of seconds the sketch has run.
192
+ * let s = millis() / 1000;
193
+ *
194
+ * // Calculate an x-coordinate.
195
+ * let x = 30 * sin(s) + 50;
196
+ *
197
+ * // Draw the circle.
198
+ * circle(x, 50, 30);
199
+ * }
200
+ * </code>
201
+ * </div>
202
+ *
203
+ * <div>
204
+ * <code>
205
+ * // Load the GeoJSON.
206
+ * function preload() {
207
+ * loadJSON('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson');
208
+ * }
209
+ *
210
+ * function setup() {
211
+ * createCanvas(100, 100);
212
+ *
213
+ * background(200);
214
+ *
215
+ * // Get the number of milliseconds the sketch has run.
216
+ * let ms = millis();
217
+ *
218
+ * // Style the text.
219
+ * textAlign(LEFT, CENTER);
220
+ * textFont('Courier New');
221
+ * textSize(11);
222
+ *
223
+ * // Display how long it took to load the data.
224
+ * text(`It took ${round(ms, 2)} ms to load the data`, 5, 50, 100);
225
+ *
226
+ * describe(
227
+ * `The text "It took ${round(ms, 2)} ms to load the data" written in black on a gray background.`
228
+ * );
229
+ * }
80
230
* </code>
81
231
* </div>
82
232
*/
@@ -90,17 +240,32 @@ p5.prototype.millis = function() {
90
240
} ;
91
241
92
242
/**
93
- * p5.js communicates with the clock on your computer. The <a href="#/p5/month">month()</a> function
94
- * returns the current month as a value from 1 - 12.
243
+ * Returns the current month as a number from 1–12.
95
244
*
96
245
* @method month
97
- * @return {Integer } the current month
246
+ * @return {Integer } current month between 1 and 12.
247
+ *
98
248
* @example
99
249
* <div>
100
250
* <code>
101
- * let m = month();
102
- * text('Current month: \n' + m, 5, 50);
103
- * describe('Current month is displayed');
251
+ * function setup() {
252
+ * createCanvas(100, 100);
253
+ *
254
+ * background(200);
255
+ *
256
+ * // Get the current month.
257
+ * let m = month();
258
+ *
259
+ * // Style the text.
260
+ * textAlign(LEFT, CENTER);
261
+ * textSize(12);
262
+ * textFont('Courier New');
263
+ *
264
+ * // Display the month.
265
+ * text(`Current month: ${m}`, 10, 50, 80);
266
+ *
267
+ * describe(`The text 'Current month: ${m}' written in black on a gray background.`);
268
+ * }
104
269
* </code>
105
270
* </div>
106
271
*/
@@ -110,17 +275,32 @@ p5.prototype.month = function() {
110
275
} ;
111
276
112
277
/**
113
- * p5.js communicates with the clock on your computer. The <a href="#/p5/second">second()</a> function
114
- * returns the current second as a value from 0 - 59.
278
+ * Returns the current second as a number from 0–59.
115
279
*
116
280
* @method second
117
- * @return {Integer } the current second
281
+ * @return {Integer } current second between 0 and 59.
282
+ *
118
283
* @example
119
284
* <div>
120
285
* <code>
121
- * let s = second();
122
- * text('Current second: \n' + s, 5, 50);
123
- * describe('Current second is displayed');
286
+ * function setup() {
287
+ * createCanvas(100, 100);
288
+ *
289
+ * background(200);
290
+ *
291
+ * // Get the current second.
292
+ * let s = second();
293
+ *
294
+ * // Style the text.
295
+ * textAlign(LEFT, CENTER);
296
+ * textSize(12);
297
+ * textFont('Courier New');
298
+ *
299
+ * // Display the second.
300
+ * text(`Current second: ${s}`, 10, 50, 80);
301
+ *
302
+ * describe(`The text 'Current second: ${s}' written in black on a gray background.`);
303
+ * }
124
304
* </code>
125
305
* </div>
126
306
*/
@@ -129,17 +309,32 @@ p5.prototype.second = function() {
129
309
} ;
130
310
131
311
/**
132
- * p5.js communicates with the clock on your computer. The <a href="#/p5/year">year()</a> function
133
- * returns the current year as an integer (2014, 2015, 2016, etc).
312
+ * Returns the current year as a number such as 1999.
134
313
*
135
314
* @method year
136
- * @return {Integer } the current year
315
+ * @return {Integer } current year.
316
+ *
137
317
* @example
138
318
* <div>
139
319
* <code>
140
- * let y = year();
141
- * text('Current year: \n' + y, 5, 50);
142
- * describe('Current year is displayed');
320
+ * function setup() {
321
+ * createCanvas(100, 100);
322
+ *
323
+ * background(200);
324
+ *
325
+ * // Get the current year.
326
+ * let y = year();
327
+ *
328
+ * // Style the text.
329
+ * textAlign(LEFT, CENTER);
330
+ * textSize(12);
331
+ * textFont('Courier New');
332
+ *
333
+ * // Display the year.
334
+ * text(`Current year: ${y}`, 10, 50, 80);
335
+ *
336
+ * describe(`The text 'Current year: ${y}' written in black on a gray background.`);
337
+ * }
143
338
* </code>
144
339
* </div>
145
340
*/
0 commit comments