88import p5 from '../core/main' ;
99
1010/**
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.
1312 *
1413 * @method day
15- * @return {Integer } the current day
14+ * @return {Integer } current day between 1 and 31.
15+ *
1616 * @example
1717 * <div>
1818 * <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+ * }
2237 * </code>
2338 * </div>
2439 */
@@ -27,17 +42,32 @@ p5.prototype.day = function() {
2742} ;
2843
2944/**
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.
3246 *
3347 * @method hour
34- * @return {Integer } the current hour
48+ * @return {Integer } current hour between 0 and 23.
49+ *
3550 * @example
3651 * <div>
3752 * <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+ * }
4171 * </code>
4272 * </div>
4373 */
@@ -46,17 +76,32 @@ p5.prototype.hour = function() {
4676} ;
4777
4878/**
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.
5180 *
5281 * @method minute
53- * @return {Integer } the current minute
82+ * @return {Integer } current minute between 0 and 59.
83+ *
5484 * @example
5585 * <div>
5686 * <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+ * }
60105 * </code>
61106 * </div>
62107 */
@@ -65,18 +110,123 @@ p5.prototype.minute = function() {
65110} ;
66111
67112/**
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.
71125 *
72126 * @method millis
73- * @return {Number } the number of milliseconds since starting the sketch
127+ * @return {Number } number of milliseconds since starting the sketch.
128+ *
74129 * @example
75130 * <div>
76131 * <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+ * }
80230 * </code>
81231 * </div>
82232 */
@@ -90,17 +240,32 @@ p5.prototype.millis = function() {
90240} ;
91241
92242/**
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.
95244 *
96245 * @method month
97- * @return {Integer } the current month
246+ * @return {Integer } current month between 1 and 12.
247+ *
98248 * @example
99249 * <div>
100250 * <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+ * }
104269 * </code>
105270 * </div>
106271 */
@@ -110,17 +275,32 @@ p5.prototype.month = function() {
110275} ;
111276
112277/**
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.
115279 *
116280 * @method second
117- * @return {Integer } the current second
281+ * @return {Integer } current second between 0 and 59.
282+ *
118283 * @example
119284 * <div>
120285 * <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+ * }
124304 * </code>
125305 * </div>
126306 */
@@ -129,17 +309,32 @@ p5.prototype.second = function() {
129309} ;
130310
131311/**
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.
134313 *
135314 * @method year
136- * @return {Integer } the current year
315+ * @return {Integer } current year.
316+ *
137317 * @example
138318 * <div>
139319 * <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+ * }
143338 * </code>
144339 * </div>
145340 */
0 commit comments