Skip to content

Commit a7f6426

Browse files
authored
Merge pull request #2867 from m90/m90-acceleration-examples
Add missing examples for acceleration functions
2 parents 097af31 + 09306be commit a7f6426

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/events/acceleration.js

+63
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,38 @@ var shake_threshold = 30;
353353
*
354354
* @method setMoveThreshold
355355
* @param {number} value The threshold value
356+
* @example
357+
* <div class="norender">
358+
* <code>
359+
* // Run this example on a mobile device
360+
* // You will need to move the device incrementally further
361+
* // the closer the square's color gets to white in order to change the value.
362+
*
363+
* var value = 0;
364+
* var threshold = 0.5;
365+
* function setup() {
366+
* setMoveThreshold(threshold);
367+
* }
368+
* function draw() {
369+
* fill(value);
370+
* rect(25, 25, 50, 50);
371+
* }
372+
* function deviceMoved() {
373+
* value = value + 5;
374+
* threshold = threshold + 0.1;
375+
* if (value > 255) {
376+
* value = 0;
377+
* threshold = 30;
378+
* }
379+
* setMoveThreshold(threshold);
380+
* }
381+
* </code>
382+
* </div>
383+
*
384+
* @alt
385+
* 50x50 black rect in center of canvas. turns white on mobile when device moves
356386
*/
387+
357388
p5.prototype.setMoveThreshold = function(val) {
358389
p5._validateParameters('setMoveThreshold', arguments);
359390
move_threshold = val;
@@ -365,7 +396,39 @@ p5.prototype.setMoveThreshold = function(val) {
365396
*
366397
* @method setShakeThreshold
367398
* @param {number} value The threshold value
399+
* @example
400+
* <div class="norender">
401+
* <code>
402+
* // Run this example on a mobile device
403+
* // You will need to shake the device more firmly
404+
* // the closer the box's fill gets to white in order to change the value.
405+
*
406+
* var value = 0;
407+
* var threshold = 30;
408+
* function setup() {
409+
* setShakeThreshold(threshold);
410+
* }
411+
* function draw() {
412+
* fill(value);
413+
* rect(25, 25, 50, 50);
414+
* }
415+
* function deviceMoved() {
416+
* value = value + 5;
417+
* threshold = threshold + 5;
418+
* if (value > 255) {
419+
* value = 0;
420+
* threshold = 30;
421+
* }
422+
* setShakeThreshold(threshold);
423+
* }
424+
* </code>
425+
* </div>
426+
*
427+
* @alt
428+
* 50x50 black rect in center of canvas. turns white on mobile when device
429+
* is being shaked
368430
*/
431+
369432
p5.prototype.setShakeThreshold = function(val) {
370433
p5._validateParameters('setShakeThreshold', arguments);
371434
shake_threshold = val;

0 commit comments

Comments
 (0)