From 09306be123fbec036c2be3b136766826880be271 Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Wed, 9 May 2018 21:01:37 +0200 Subject: [PATCH] add missing examples for acceleration functions --- src/events/acceleration.js | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/events/acceleration.js b/src/events/acceleration.js index 32c241600a..3aa0ccd088 100644 --- a/src/events/acceleration.js +++ b/src/events/acceleration.js @@ -353,7 +353,38 @@ var shake_threshold = 30; * * @method setMoveThreshold * @param {number} value The threshold value + * @example + *
+ * + * // Run this example on a mobile device + * // You will need to move the device incrementally further + * // the closer the square's color gets to white in order to change the value. + * + * var value = 0; + * var threshold = 0.5; + * function setup() { + * setMoveThreshold(threshold); + * } + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function deviceMoved() { + * value = value + 5; + * threshold = threshold + 0.1; + * if (value > 255) { + * value = 0; + * threshold = 30; + * } + * setMoveThreshold(threshold); + * } + * + *
+ * + * @alt + * 50x50 black rect in center of canvas. turns white on mobile when device moves */ + p5.prototype.setMoveThreshold = function(val) { p5._validateParameters('setMoveThreshold', arguments); move_threshold = val; @@ -365,7 +396,39 @@ p5.prototype.setMoveThreshold = function(val) { * * @method setShakeThreshold * @param {number} value The threshold value + * @example + *
+ * + * // Run this example on a mobile device + * // You will need to shake the device more firmly + * // the closer the box's fill gets to white in order to change the value. + * + * var value = 0; + * var threshold = 30; + * function setup() { + * setShakeThreshold(threshold); + * } + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function deviceMoved() { + * value = value + 5; + * threshold = threshold + 5; + * if (value > 255) { + * value = 0; + * threshold = 30; + * } + * setShakeThreshold(threshold); + * } + * + *
+ * + * @alt + * 50x50 black rect in center of canvas. turns white on mobile when device + * is being shaked */ + p5.prototype.setShakeThreshold = function(val) { p5._validateParameters('setShakeThreshold', arguments); shake_threshold = val;