1+ /**
2+ * @module Input
3+ * @submodule Acceleration
4+ * @for p5
5+ * @requires core
6+ */
17define ( function ( require ) {
28
39 'use strict' ;
410
511 var p5 = require ( 'core' ) ;
6-
12+
13+ /**
14+ * The system variable deviceOrientation always contains the orientation of
15+ * the device. The value of this variable will either be set 'landscape'
16+ * or 'portrait'. If no data is avaliable it will be set to 'undefined'.
17+ *
18+ * @property deviceOrientation
19+ */
720 p5 . prototype . deviceOrientation = undefined ;
821
22+ /**
23+ * The system variable accelerationX always contains the acceleration of the
24+ * device along the x axis. Value is represented as meters per second squared.
25+ *
26+ * @property accelerationX
27+ */
928 p5 . prototype . accelerationX = 0 ;
29+
30+ /**
31+ * The system variable accelerationY always contains the acceleration of the
32+ * device along the y axis. Value is represented as meters per second squared.
33+ *
34+ * @property accelerationY
35+ */
1036 p5 . prototype . accelerationY = 0 ;
37+
38+ /**
39+ * The system variable accelerationZ always contains the acceleration of the
40+ * device along the z axis. Value is represented as meters per second squared.
41+ *
42+ * @property accelerationZ
43+ */
1144 p5 . prototype . accelerationZ = 0 ;
1245
46+ /**
47+ * The system variable pAccelerationX always contains the acceleration of the
48+ * device along the x axis in the frame previous to the current frame. Value
49+ * is represented as meters per second squared.
50+ *
51+ * @property pAccelerationX
52+ */
1353 p5 . prototype . pAccelerationX = 0 ;
54+
55+ /**
56+ * The system variable pAccelerationY always contains the acceleration of the
57+ * device along the y axis in the frame previous to the current frame. Value
58+ * is represented as meters per second squared.
59+ *
60+ * @property pAccelerationY
61+ */
1462 p5 . prototype . pAccelerationY = 0 ;
63+
64+ /**
65+ * The system variable pAccelerationZ always contains the acceleration of the
66+ * device along the z axis in the frame previous to the current frame. Value
67+ * is represented as meters per second squared.
68+ *
69+ * @property pAccelerationZ
70+ */
1571 p5 . prototype . pAccelerationZ = 0 ;
1672
73+ /**
74+ * _updatePAccelerations updates the pAcceleration values
75+ *
76+ * @private
77+ */
1778 p5 . prototype . _updatePAccelerations = function ( ) {
1879 this . _setProperty ( 'pAccelerationX' , this . accelerationX ) ;
1980 this . _setProperty ( 'pAccelerationY' , this . accelerationY ) ;
@@ -22,6 +83,13 @@ define(function (require){
2283
2384 var move_threshold = 0.5 ;
2485
86+ /**
87+ * The setMoveThreshold() function is used to set the movement threshold for
88+ * the onDeviceMove() function.
89+ *
90+ * @method setMoveThreshold
91+ * @param {number } value The threshold value
92+ */
2593 p5 . prototype . setMoveThreshold = function ( val ) {
2694 if ( typeof val === 'number' ) {
2795 move_threshold = val ;
@@ -31,6 +99,57 @@ define(function (require){
3199 var old_max_axis = '' ;
32100 var new_max_axis = '' ;
33101
102+ /**
103+ * The onDeviceMove() function is called when the devices orientation changes
104+ * by more than the threshold value.
105+ * @method onDeviceMove
106+ * @example
107+ * <div>
108+ * <code>
109+ * // Run this example on a mobile device
110+ * // Move the device around
111+ * // to change the value.
112+ *
113+ * var value = 0;
114+ * function draw() {
115+ * fill(value);
116+ * rect(25, 25, 50, 50);
117+ * }
118+ * function onDeviceMove() {
119+ * value = value + 5;
120+ * if (value > 255) {
121+ * value = 0;
122+ * }
123+ * }
124+ * </code>
125+ * </div>
126+ */
127+
128+ /**
129+ * The onDeviceTurn() function is called when the device rotates by
130+ * more than 90 degrees.
131+ * @method onDeviceTurn
132+ * @example
133+ * <div>
134+ * <code>
135+ * // Run this example on a mobile device
136+ * // Rotate the device by 90 degrees
137+ * // to change the value.
138+ *
139+ * var value = 0;
140+ * function draw() {
141+ * fill(value);
142+ * rect(25, 25, 50, 50);
143+ * }
144+ * function onDeviceTurn() {
145+ * value = value + 5;
146+ * if (value > 255) {
147+ * value = 0;
148+ * }
149+ * }
150+ * </code>
151+ * </div>
152+ */
34153 p5 . prototype . ondevicemotion = function ( e ) {
35154 this . _setProperty ( 'accelerationX' , e . accelerationIncludingGravity . x ) ;
36155 this . _setProperty ( 'accelerationY' , e . accelerationIncludingGravity . y ) ;
@@ -73,7 +192,7 @@ define(function (require){
73192 if ( Math . abs ( this . accelerationZ ) > max_val ) {
74193 new_max_axis = 'z' ; //max_val is now irrelevant
75194 }
76-
195+
77196 if ( old_max_axis !== '' && old_max_axis !== new_max_axis ) {
78197 onDeviceTurn ( new_max_axis ) ;
79198 }
0 commit comments