p5-phone 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +509 -0
  3. package/dist/p5-phone.js +1062 -0
  4. package/dist/p5-phone.min.js +10 -0
  5. package/examples/Phone Sensor Examples/microphone/01_mic_level/index.html +19 -0
  6. package/examples/Phone Sensor Examples/microphone/01_mic_level/sketch.js +117 -0
  7. package/examples/Phone Sensor Examples/movement/01_orientation_basic/index.html +28 -0
  8. package/examples/Phone Sensor Examples/movement/01_orientation_basic/sketch.js +123 -0
  9. package/examples/Phone Sensor Examples/movement/02_rotational_velocity/index.html +28 -0
  10. package/examples/Phone Sensor Examples/movement/02_rotational_velocity/sketch.js +144 -0
  11. package/examples/Phone Sensor Examples/movement/03_acceleration/index.html +28 -0
  12. package/examples/Phone Sensor Examples/movement/03_acceleration/sketch.js +87 -0
  13. package/examples/Phone Sensor Examples/sound/01_dual_audio/index.html +31 -0
  14. package/examples/Phone Sensor Examples/sound/01_dual_audio/sketch.js +225 -0
  15. package/examples/Phone Sensor Examples/sound/01_dual_audio/tracks/audio1.mp3 +0 -0
  16. package/examples/Phone Sensor Examples/sound/01_dual_audio/tracks/audio2.mp3 +0 -0
  17. package/examples/Phone Sensor Examples/sound/02_volume_touches/index.html +31 -0
  18. package/examples/Phone Sensor Examples/sound/02_volume_touches/sketch.js +269 -0
  19. package/examples/Phone Sensor Examples/sound/02_volume_touches/tracks/audio1.mp3 +0 -0
  20. package/examples/Phone Sensor Examples/touch/01_touch_basic/index.html +28 -0
  21. package/examples/Phone Sensor Examples/touch/01_touch_basic/sketch.js +94 -0
  22. package/examples/Phone Sensor Examples/touch/02_touch_zones/index.html +28 -0
  23. package/examples/Phone Sensor Examples/touch/02_touch_zones/sketch.js +220 -0
  24. package/examples/Phone Sensor Examples/touch/03_touch_count/index.html +28 -0
  25. package/examples/Phone Sensor Examples/touch/03_touch_count/sketch.js +93 -0
  26. package/examples/Phone Sensor Examples/touch/04_touch_distance/index.html +28 -0
  27. package/examples/Phone Sensor Examples/touch/04_touch_distance/sketch.js +120 -0
  28. package/examples/Phone Sensor Examples/touch/05_touch_angle/index.html +28 -0
  29. package/examples/Phone Sensor Examples/touch/05_touch_angle/sketch.js +117 -0
  30. package/examples/Phone Sensor Examples - Minimal/microphone/01_mic_level/index.html +19 -0
  31. package/examples/Phone Sensor Examples - Minimal/microphone/01_mic_level/sketch.js +72 -0
  32. package/examples/Phone Sensor Examples - Minimal/movement/01_orientation_basic/index.html +18 -0
  33. package/examples/Phone Sensor Examples - Minimal/movement/01_orientation_basic/sketch.js +51 -0
  34. package/examples/Phone Sensor Examples - Minimal/movement/02_rotational_velocity/index.html +18 -0
  35. package/examples/Phone Sensor Examples - Minimal/movement/02_rotational_velocity/sketch.js +70 -0
  36. package/examples/Phone Sensor Examples - Minimal/movement/03_acceleration/index.html +18 -0
  37. package/examples/Phone Sensor Examples - Minimal/movement/03_acceleration/sketch.js +83 -0
  38. package/examples/Phone Sensor Examples - Minimal/sound/01_sound_basic/index.html +19 -0
  39. package/examples/Phone Sensor Examples - Minimal/sound/01_sound_basic/sketch.js +96 -0
  40. package/examples/Phone Sensor Examples - Minimal/sound/01_sound_basic/tracks/audio1.mp3 +0 -0
  41. package/examples/Phone Sensor Examples - Minimal/sound/02_sound_amplitude/index.html +19 -0
  42. package/examples/Phone Sensor Examples - Minimal/sound/02_sound_amplitude/sketch.js +118 -0
  43. package/examples/Phone Sensor Examples - Minimal/sound/02_sound_amplitude/tracks/audio1.mp3 +0 -0
  44. package/examples/Phone Sensor Examples - Minimal/touch/01_touch_basic/index.html +18 -0
  45. package/examples/Phone Sensor Examples - Minimal/touch/01_touch_basic/sketch.js +58 -0
  46. package/examples/Phone Sensor Examples - Minimal/touch/02_touch_zones/index.html +18 -0
  47. package/examples/Phone Sensor Examples - Minimal/touch/02_touch_zones/sketch.js +78 -0
  48. package/examples/Phone Sensor Examples - Minimal/touch/03_touch_count/index.html +18 -0
  49. package/examples/Phone Sensor Examples - Minimal/touch/03_touch_count/sketch.js +64 -0
  50. package/examples/Phone Sensor Examples - Minimal/touch/04_touch_distance/index.html +18 -0
  51. package/examples/Phone Sensor Examples - Minimal/touch/04_touch_distance/sketch.js +69 -0
  52. package/examples/Phone Sensor Examples - Minimal/touch/05_touch_angle/index.html +18 -0
  53. package/examples/Phone Sensor Examples - Minimal/touch/05_touch_angle/sketch.js +85 -0
  54. package/examples/Phone and Gif/collision/README.md +31 -0
  55. Gif/collision/gifs/spaceSuit2.png +0 -0
  56. package/examples/Phone and Gif/collision/index.html +19 -0
  57. package/examples/Phone and Gif/collision/sketch.js +226 -0
  58. Gif/fetch/gifs/corgiswimflip.gif +0 -0
  59. package/examples/Phone and Gif/fetch/index.html +18 -0
  60. package/examples/Phone and Gif/fetch/sketch.js +139 -0
  61. Gif/fly/gifs/comparison.gif +0 -0
  62. package/examples/Phone and Gif/fly/index.html +18 -0
  63. package/examples/Phone and Gif/fly/sketch.js +103 -0
  64. Gif/roll/gifs/how-penciles-are-made.gif +0 -0
  65. package/examples/Phone and Gif/roll/index.html +18 -0
  66. package/examples/Phone and Gif/roll/sketch.js +121 -0
  67. package/examples/UXcompare/button-vs-movement/index.html +45 -0
  68. package/examples/UXcompare/button-vs-movement/sketch.js +355 -0
  69. package/examples/UXcompare/button-vs-orientation/index.html +25 -0
  70. package/examples/UXcompare/button-vs-orientation/sketch.js +317 -0
  71. package/examples/UXcompare/button-vs-shake/index.html +45 -0
  72. package/examples/UXcompare/button-vs-shake/sketch.js +320 -0
  73. package/examples/UXcompare/gyroscope-demo/index.html +78 -0
  74. package/examples/UXcompare/gyroscope-demo/sketch.js +166 -0
  75. package/examples/UXcompare/index.html +419 -0
  76. package/examples/UXcompare/microphone-demo/index.html +79 -0
  77. package/examples/UXcompare/microphone-demo/sketch.js +210 -0
  78. package/examples/UXcompare/slider-vs-angle/index.html +25 -0
  79. package/examples/UXcompare/slider-vs-angle/sketch.js +429 -0
  80. package/examples/UXcompare/slider-vs-distance/index.html +25 -0
  81. package/examples/UXcompare/slider-vs-distance/sketch.js +401 -0
  82. package/examples/UXcompare/slider-vs-microphone/index.html +26 -0
  83. package/examples/UXcompare/slider-vs-microphone/sketch.js +336 -0
  84. package/examples/UXcompare/slider-vs-touches/index.html +25 -0
  85. package/examples/UXcompare/slider-vs-touches/sketch.js +376 -0
  86. package/examples/UXcompare/sliders-vs-acceleration/index.html +25 -0
  87. package/examples/UXcompare/sliders-vs-acceleration/sketch.js +361 -0
  88. package/examples/UXcompare/sliders-vs-rotation/index.html +25 -0
  89. package/examples/UXcompare/sliders-vs-rotation/sketch.js +375 -0
  90. package/examples/blankTemplate/index.html +31 -0
  91. package/examples/blankTemplate/sketch.js +55 -0
  92. package/examples/homepage/index.html +506 -0
  93. package/package.json +73 -0
  94. package/src/p5-phone.js +1062 -0
  95. package/src/permissionMic.js +240 -0
  96. package/src/permissionsGesture.js +213 -0
  97. package/src/permissionsGyro.js +246 -0
@@ -0,0 +1,355 @@
1
+ // Button vs Movement Comparison
2
+ // Shows traditional button UI vs mobile device movement interaction
3
+
4
+ // Color states
5
+ let isBlueBackground = true; // true = blue, false = orange
6
+ let buttonColor1 = '#3498db'; // Blue
7
+ let buttonColor2 = '#e67e22'; // Orange
8
+
9
+ // Counters
10
+ let buttonClickCount = 0;
11
+ let movementCount = 0;
12
+
13
+ // Button properties
14
+ let buttonWidth = 200;
15
+ let buttonHeight = 60;
16
+ let buttonX, buttonY;
17
+
18
+ // Slider properties
19
+ let sliderX, sliderY;
20
+ let sliderWidth = 200;
21
+ let sliderHeight = 20;
22
+ let sliderValue = 5; // Default movement threshold (higher = less sensitive)
23
+ let sliderMin = 1;
24
+ let sliderMax = 50;
25
+ let isDraggingSlider = false;
26
+
27
+ // Simple movement debounce
28
+ let lastMovementFrame = 0;
29
+
30
+ // Layout properties
31
+ let topSectionHeight;
32
+ let bottomSectionHeight;
33
+ let dividerY;
34
+
35
+ function setup() {
36
+ createCanvas(windowWidth, windowHeight);
37
+
38
+ // Enable gesture locking and motion sensors
39
+ lockGestures();
40
+ enableGyroTap('Tap to enable movement detection');
41
+
42
+ // Calculate layout for portrait orientation
43
+ topSectionHeight = height * 0.5;
44
+ bottomSectionHeight = height * 0.5;
45
+ dividerY = height * 0.5;
46
+
47
+ // Position button in top section
48
+ buttonX = width / 2 - buttonWidth / 2;
49
+ buttonY = topSectionHeight / 2 - buttonHeight / 2;
50
+
51
+ // Position slider in bottom section
52
+ sliderX = width / 2 - sliderWidth / 2;
53
+ sliderY = height - 120;
54
+
55
+ // Set initial movement threshold (higher value = less sensitive)
56
+ setMoveThreshold(sliderValue);
57
+
58
+ textAlign(CENTER, CENTER);
59
+ }
60
+
61
+ function draw() {
62
+ // Set background color based on current state
63
+ if (isBlueBackground) {
64
+ background(buttonColor1);
65
+ } else {
66
+ background(buttonColor2);
67
+ }
68
+
69
+ // Draw divider line
70
+ stroke(255, 255, 255, 100);
71
+ strokeWeight(2);
72
+ line(0, dividerY, width, dividerY);
73
+
74
+ // Draw top section - Traditional Button UI
75
+ drawTopSection();
76
+
77
+ // Draw bottom section - Movement Interaction
78
+ drawBottomSection();
79
+ }
80
+
81
+ function drawTopSection() {
82
+ // Section title
83
+ fill(255);
84
+ textSize(24);
85
+ text('TRADITIONAL UI', width / 2, 40);
86
+
87
+ // Draw button
88
+ drawButton();
89
+
90
+ // Draw counter
91
+ textSize(20);
92
+ text('Button pressed: ' + buttonClickCount + ' times', width / 2, buttonY + buttonHeight + 40);
93
+ }
94
+
95
+ function drawBottomSection() {
96
+ // Section title
97
+ fill(255);
98
+ textSize(24);
99
+ text('MOBILE INTERACTION', width / 2, dividerY + 40);
100
+
101
+ // Instructions or movement indicator
102
+ textSize(18);
103
+ if (window.sensorsEnabled) {
104
+ text('Move your device!', width / 2, dividerY + 80);
105
+ } else {
106
+ text('Enable motion sensors first', width / 2, dividerY + 80);
107
+ }
108
+
109
+ // Draw movement visualization
110
+ if (window.sensorsEnabled) {
111
+ drawMovementIndicator();
112
+ }
113
+
114
+ // Draw movement threshold slider
115
+ drawSlider();
116
+
117
+ // Draw counter
118
+ textSize(20);
119
+ text('Device moved: ' + movementCount + ' times', width / 2, height - 30);
120
+ }
121
+
122
+ function drawButton() {
123
+ // Button shadow
124
+ fill(0, 0, 0, 50);
125
+ noStroke();
126
+ rect(buttonX + 3, buttonY + 3, buttonWidth, buttonHeight, 8);
127
+
128
+ // Button background
129
+ if (isBlueBackground) {
130
+ fill(255, 255, 255, 200);
131
+ } else {
132
+ fill(255, 255, 255, 200);
133
+ }
134
+
135
+ // Check if button is being pressed
136
+ if (isButtonPressed()) {
137
+ fill(255, 255, 255, 255); // Brighter when pressed
138
+ }
139
+
140
+ rect(buttonX, buttonY, buttonWidth, buttonHeight, 8);
141
+
142
+ // Button text
143
+ fill(0);
144
+ textSize(18);
145
+ text('TOGGLE COLOR', width / 2, buttonY + buttonHeight / 2);
146
+ }
147
+
148
+ function drawMovementIndicator() {
149
+ // Simple movement visualization - arrows showing device movement
150
+ let centerX = width / 2;
151
+ let centerY = dividerY + (bottomSectionHeight / 2) - 40;
152
+
153
+ // Get motion intensity for visualization
154
+ let motionX = 0;
155
+ let motionY = 0;
156
+ let motionZ = 0;
157
+
158
+ if (typeof accelerationX !== 'undefined') {
159
+ motionX = accelerationX || 0;
160
+ motionY = accelerationY || 0;
161
+ motionZ = accelerationZ || 0;
162
+ }
163
+
164
+ // Draw device representation (rectangle)
165
+ fill(255, 150);
166
+ stroke(255);
167
+ strokeWeight(2);
168
+ rect(centerX - 40, centerY - 20, 80, 40, 5);
169
+
170
+ // Draw movement arrows based on acceleration
171
+ strokeWeight(3);
172
+
173
+ // X-axis movement (left/right)
174
+ if (abs(motionX) > 0.5) {
175
+ stroke(255, 200, 100);
176
+ if (motionX > 0) {
177
+ // Arrow pointing right
178
+ line(centerX + 50, centerY, centerX + 80, centerY);
179
+ line(centerX + 75, centerY - 5, centerX + 80, centerY);
180
+ line(centerX + 75, centerY + 5, centerX + 80, centerY);
181
+ } else {
182
+ // Arrow pointing left
183
+ line(centerX - 50, centerY, centerX - 80, centerY);
184
+ line(centerX - 75, centerY - 5, centerX - 80, centerY);
185
+ line(centerX - 75, centerY + 5, centerX - 80, centerY);
186
+ }
187
+ }
188
+
189
+ // Y-axis movement (up/down)
190
+ if (abs(motionY) > 0.5) {
191
+ stroke(100, 255, 200);
192
+ if (motionY > 0) {
193
+ // Arrow pointing down
194
+ line(centerX, centerY + 25, centerX, centerY + 55);
195
+ line(centerX - 5, centerY + 50, centerX, centerY + 55);
196
+ line(centerX + 5, centerY + 50, centerX, centerY + 55);
197
+ } else {
198
+ // Arrow pointing up
199
+ line(centerX, centerY - 25, centerX, centerY - 55);
200
+ line(centerX - 5, centerY - 50, centerX, centerY - 55);
201
+ line(centerX + 5, centerY - 50, centerX, centerY - 55);
202
+ }
203
+ }
204
+
205
+ // Center dot
206
+ fill(255);
207
+ noStroke();
208
+ circle(centerX, centerY, 8);
209
+ }
210
+
211
+ function drawSlider() {
212
+ // Slider label
213
+ fill(255);
214
+ textSize(16);
215
+ text('Movement Sensitivity: ' + sliderValue, width / 2, sliderY - 25);
216
+
217
+ // Slider track (background)
218
+ fill(255, 255, 255, 100);
219
+ noStroke();
220
+ rect(sliderX, sliderY, sliderWidth, sliderHeight, sliderHeight / 2);
221
+
222
+ // Calculate slider handle position
223
+ let handleX = map(sliderValue, sliderMin, sliderMax, sliderX, sliderX + sliderWidth - 20);
224
+
225
+ // Slider handle
226
+ fill(255);
227
+ if (isDraggingSlider) {
228
+ fill(255, 255, 0); // Yellow when dragging
229
+ }
230
+
231
+ // Handle shadow
232
+ fill(0, 0, 0, 50);
233
+ circle(handleX + 12, sliderY + sliderHeight / 2 + 2, 24);
234
+
235
+ // Handle
236
+ if (isDraggingSlider) {
237
+ fill(255, 255, 0);
238
+ } else {
239
+ fill(255);
240
+ }
241
+ circle(handleX + 10, sliderY + sliderHeight / 2, 24);
242
+
243
+ // Handle indicator
244
+ fill(0);
245
+ circle(handleX + 10, sliderY + sliderHeight / 2, 8);
246
+ }
247
+
248
+ function isButtonPressed() {
249
+ return mouseIsPressed &&
250
+ mouseX >= buttonX &&
251
+ mouseX <= buttonX + buttonWidth &&
252
+ mouseY >= buttonY &&
253
+ mouseY <= buttonY + buttonHeight;
254
+ }
255
+
256
+ function isSliderPressed() {
257
+ let handleX = map(sliderValue, sliderMin, sliderMax, sliderX, sliderX + sliderWidth - 20);
258
+ return mouseX >= handleX &&
259
+ mouseX <= handleX + 20 &&
260
+ mouseY >= sliderY - 10 &&
261
+ mouseY <= sliderY + sliderHeight + 10;
262
+ }
263
+
264
+ // Handle button clicks
265
+ function mousePressed() {
266
+ // Check button press
267
+ if (mouseX >= buttonX &&
268
+ mouseX <= buttonX + buttonWidth &&
269
+ mouseY >= buttonY &&
270
+ mouseY <= buttonY + buttonHeight) {
271
+
272
+ // Toggle background color
273
+ isBlueBackground = !isBlueBackground;
274
+
275
+ // Increment counter
276
+ buttonClickCount++;
277
+
278
+ console.log('Button clicked! Count:', buttonClickCount);
279
+
280
+ return false; // Prevent default
281
+ }
282
+
283
+ // Check slider press
284
+ if (isSliderPressed()) {
285
+ isDraggingSlider = true;
286
+ updateSliderValue();
287
+ return false;
288
+ }
289
+ }
290
+
291
+ function mouseDragged() {
292
+ if (isDraggingSlider) {
293
+ updateSliderValue();
294
+ return false;
295
+ }
296
+ }
297
+
298
+ function mouseReleased() {
299
+ isDraggingSlider = false;
300
+ }
301
+
302
+ function updateSliderValue() {
303
+ // Calculate new slider value based on mouse position
304
+ let newValue = map(mouseX, sliderX, sliderX + sliderWidth, sliderMin, sliderMax);
305
+ newValue = constrain(newValue, sliderMin, sliderMax);
306
+ sliderValue = round(newValue);
307
+
308
+ // Update movement threshold
309
+ setMoveThreshold(sliderValue);
310
+
311
+ console.log('Movement threshold set to:', sliderValue);
312
+ }
313
+
314
+ // Handle device movement (built-in p5.js function)
315
+ function deviceMoved() {
316
+ // Only respond if motion sensors are enabled
317
+ if (window.sensorsEnabled) {
318
+ // Simple debounce - ignore if movement happened in last 5 frames (about 1/12 second)
319
+ if (frameCount - lastMovementFrame > 5) {
320
+ // Toggle background color
321
+ isBlueBackground = !isBlueBackground;
322
+
323
+ // Increment counter
324
+ movementCount++;
325
+
326
+ // Update last movement frame
327
+ lastMovementFrame = frameCount;
328
+
329
+ console.log('Device moved! Count:', movementCount);
330
+ }
331
+ }
332
+ }
333
+
334
+ // Handle screen rotation
335
+ function windowResized() {
336
+ resizeCanvas(windowWidth, windowHeight);
337
+
338
+ // Recalculate layout
339
+ topSectionHeight = height * 0.5;
340
+ bottomSectionHeight = height * 0.5;
341
+ dividerY = height * 0.5;
342
+
343
+ // Reposition button
344
+ buttonX = width / 2 - buttonWidth / 2;
345
+ buttonY = topSectionHeight / 2 - buttonHeight / 2;
346
+
347
+ // Reposition slider
348
+ sliderX = width / 2 - sliderWidth / 2;
349
+ sliderY = height - 120;
350
+ }
351
+
352
+ // Called when permissions are ready
353
+ function userSetupComplete() {
354
+ console.log('Motion sensors enabled! You can now move the device.');
355
+ }
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
6
+ <title>Button vs Orientation - Mobile p5 Permissions</title>
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ padding: 0;
11
+ overflow: hidden;
12
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
13
+ }
14
+
15
+ canvas {
16
+ display: block;
17
+ }
18
+ </style>
19
+ </head>
20
+ <body>
21
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.7.0/p5.min.js"></script>
22
+ <script src="https://cdn.jsdelivr.net/npm/mobile-p5-permissions@1.4.4/dist/p5.mobile-permissions.min.js"></script>
23
+ <script src="sketch.js"></script>
24
+ </body>
25
+ </html>
@@ -0,0 +1,317 @@
1
+ // Button vs Orientation Comparison
2
+ // Shows traditional button UI vs mobile device orientation change interaction
3
+
4
+ // Color states
5
+ let isBlueBackground = true; // true = blue, false = orange
6
+ let buttonColor1 = '#3498db'; // Blue
7
+ let buttonColor2 = '#e67e22'; // Orange
8
+
9
+ // Counters
10
+ let buttonClickCount = 0;
11
+ let orientationCount = 0;
12
+
13
+ // Button properties
14
+ let buttonWidth = 200;
15
+ let buttonHeight = 60;
16
+ let buttonX, buttonY;
17
+
18
+ // Orientation tracking
19
+ let lastOrientation = '';
20
+ let currentOrientation = '';
21
+
22
+ // Simple orientation debounce
23
+ let lastOrientationFrame = 0;
24
+
25
+ // Layout properties
26
+ let topSectionHeight;
27
+ let bottomSectionHeight;
28
+ let dividerY;
29
+
30
+ function setup() {
31
+ createCanvas(windowWidth, windowHeight);
32
+
33
+ // Enable gesture locking and motion sensors
34
+ lockGestures();
35
+ enableGyroTap('Tap to enable orientation detection');
36
+
37
+ // Calculate layout for portrait orientation
38
+ topSectionHeight = height * 0.5;
39
+ bottomSectionHeight = height * 0.5;
40
+ dividerY = height * 0.5;
41
+
42
+ // Position button in top section
43
+ buttonX = width / 2 - buttonWidth / 2;
44
+ buttonY = topSectionHeight / 2 - buttonHeight / 2;
45
+
46
+ // Initialize orientation tracking
47
+ updateOrientation();
48
+
49
+ textAlign(CENTER, CENTER);
50
+ }
51
+
52
+ function draw() {
53
+ // Set background color based on current state
54
+ if (isBlueBackground) {
55
+ background(buttonColor1);
56
+ } else {
57
+ background(buttonColor2);
58
+ }
59
+
60
+ // Draw divider line
61
+ stroke(255, 255, 255, 100);
62
+ strokeWeight(2);
63
+ line(0, dividerY, width, dividerY);
64
+
65
+ // Draw top section - Traditional Button UI
66
+ drawTopSection();
67
+
68
+ // Draw bottom section - Orientation Interaction
69
+ drawBottomSection();
70
+
71
+ // Check for orientation changes
72
+ checkOrientationChange();
73
+ }
74
+
75
+ function drawTopSection() {
76
+ // Section title
77
+ fill(255);
78
+ textSize(24);
79
+ if (currentOrientation === 'landscape') {
80
+ textAlign(LEFT, CENTER);
81
+ text('TRADITIONAL UI', 30, 40);
82
+ } else {
83
+ textAlign(CENTER, CENTER);
84
+ text('TRADITIONAL UI', width / 2, 40);
85
+ }
86
+
87
+ // Draw button
88
+ drawButton();
89
+
90
+ // Draw counter
91
+ textSize(20);
92
+ if (currentOrientation === 'landscape') {
93
+ textAlign(LEFT, CENTER);
94
+ text('Button pressed: ' + buttonClickCount + ' times', 30, buttonY + buttonHeight);
95
+ } else {
96
+ textAlign(CENTER, CENTER);
97
+ text('Button pressed: ' + buttonClickCount + ' times', width / 2, buttonY + buttonHeight + 40);
98
+ }
99
+ }
100
+
101
+ function drawBottomSection() {
102
+ // Section title
103
+ fill(255);
104
+ textSize(24);
105
+ if (currentOrientation === 'landscape') {
106
+ textAlign(LEFT, CENTER);
107
+ text('MOBILE INTERACTION', 30, dividerY + 40);
108
+ } else {
109
+ textAlign(CENTER, CENTER);
110
+ text('MOBILE INTERACTION', width / 2, dividerY + 40);
111
+ }
112
+
113
+ // Instructions or orientation indicator
114
+ textSize(18);
115
+ if (window.sensorsEnabled) {
116
+ if (currentOrientation === 'landscape') {
117
+ textAlign(LEFT, CENTER);
118
+ text('Rotate your device!', 30, dividerY + 80);
119
+ } else {
120
+ textAlign(CENTER, CENTER);
121
+ text('Rotate your device!', width / 2, dividerY + 80);
122
+ }
123
+ } else {
124
+ if (currentOrientation === 'landscape') {
125
+ textAlign(LEFT, CENTER);
126
+ text('Enable motion sensors first', 30, dividerY + 80);
127
+ } else {
128
+ textAlign(CENTER, CENTER);
129
+ text('Enable motion sensors first', width / 2, dividerY + 80);
130
+ }
131
+ }
132
+
133
+ // Draw orientation visualization
134
+ if (window.sensorsEnabled) {
135
+ drawOrientationIndicator();
136
+ }
137
+
138
+ // Draw counter
139
+ textSize(20);
140
+ if (currentOrientation === 'landscape') {
141
+ textAlign(LEFT, CENTER);
142
+ text('Device rotated: ' + orientationCount + ' times', 30, height - 40);
143
+ } else {
144
+ textAlign(CENTER, CENTER);
145
+ text('Device rotated: ' + orientationCount + ' times', width / 2, height - 40);
146
+ }
147
+ }
148
+
149
+ function drawButton() {
150
+ // Button shadow
151
+ fill(0, 0, 0, 50);
152
+ noStroke();
153
+ rect(buttonX + 3, buttonY + 3, buttonWidth, buttonHeight, 8);
154
+
155
+ // Button background
156
+ if (isBlueBackground) {
157
+ fill(255, 255, 255, 200);
158
+ } else {
159
+ fill(255, 255, 255, 200);
160
+ }
161
+
162
+ // Check if button is being pressed
163
+ if (isButtonPressed()) {
164
+ fill(255, 255, 255, 255); // Brighter when pressed
165
+ }
166
+
167
+ rect(buttonX, buttonY, buttonWidth, buttonHeight, 8);
168
+
169
+ // Button text
170
+ fill(0);
171
+ textSize(18);
172
+ textAlign(CENTER, CENTER);
173
+ text('TOGGLE COLOR', width / 2, buttonY + buttonHeight / 2);
174
+ }
175
+
176
+ function drawOrientationIndicator() {
177
+ // Device orientation visualization
178
+ let centerX = width / 2;
179
+ let centerY = dividerY + (bottomSectionHeight / 2) - 20;
180
+
181
+ // Draw device representation based on current orientation
182
+ fill(255, 150);
183
+ stroke(255);
184
+ strokeWeight(2);
185
+
186
+ if (currentOrientation === 'portrait' || currentOrientation === 'portrait-flipped') {
187
+ // Draw tall rectangle for portrait
188
+ rect(centerX - 30, centerY - 40, 60, 80, 8);
189
+
190
+ // Draw orientation indicator
191
+ fill(255, 200, 100);
192
+ textSize(14);
193
+ textAlign(CENTER, CENTER);
194
+ text('PORTRAIT', centerX, centerY + 60);
195
+
196
+ } else if (currentOrientation === 'landscape' || currentOrientation === 'landscape-flipped') {
197
+ // Draw wide rectangle for landscape
198
+ rect(centerX - 50, centerY - 25, 100, 50, 8);
199
+
200
+ // Draw orientation indicator
201
+ fill(255, 200, 100);
202
+ textSize(14);
203
+ textAlign(CENTER, CENTER);
204
+ text('LANDSCAPE', centerX, centerY + 50);
205
+ } else {
206
+ // Unknown orientation
207
+ rect(centerX - 40, centerY - 30, 80, 60, 8);
208
+
209
+ fill(255, 100, 100);
210
+ textSize(14);
211
+ textAlign(CENTER, CENTER);
212
+ text('UNKNOWN', centerX, centerY + 50);
213
+ }
214
+
215
+ // Center dot
216
+ fill(255);
217
+ noStroke();
218
+ circle(centerX, centerY, 8);
219
+
220
+ // Current orientation text
221
+ fill(255);
222
+ textSize(16);
223
+ if (currentOrientation === 'landscape') {
224
+ textAlign(LEFT, CENTER);
225
+ text('Current: ' + currentOrientation, 30, centerY - 70);
226
+ } else {
227
+ textAlign(CENTER, CENTER);
228
+ text('Current: ' + currentOrientation, centerX, centerY - 70);
229
+ }
230
+ }
231
+
232
+ function isButtonPressed() {
233
+ return mouseIsPressed &&
234
+ mouseX >= buttonX &&
235
+ mouseX <= buttonX + buttonWidth &&
236
+ mouseY >= buttonY &&
237
+ mouseY <= buttonY + buttonHeight;
238
+ }
239
+
240
+ // Handle button clicks
241
+ function mousePressed() {
242
+ // Check button press
243
+ if (mouseX >= buttonX &&
244
+ mouseX <= buttonX + buttonWidth &&
245
+ mouseY >= buttonY &&
246
+ mouseY <= buttonY + buttonHeight) {
247
+
248
+ // Toggle background color
249
+ isBlueBackground = !isBlueBackground;
250
+
251
+ // Increment counter
252
+ buttonClickCount++;
253
+
254
+ console.log('Button clicked! Count:', buttonClickCount);
255
+
256
+ return false; // Prevent default
257
+ }
258
+ }
259
+
260
+ function updateOrientation() {
261
+ // Determine orientation based on screen dimensions
262
+ if (width > height) {
263
+ currentOrientation = 'landscape';
264
+ } else {
265
+ currentOrientation = 'portrait';
266
+ }
267
+ }
268
+
269
+ function checkOrientationChange() {
270
+ // Only check if motion sensors are enabled
271
+ if (window.sensorsEnabled) {
272
+ // Update current orientation
273
+ let newOrientation = (width > height) ? 'landscape' : 'portrait';
274
+
275
+ // Check if orientation changed
276
+ if (newOrientation !== currentOrientation && currentOrientation !== '') {
277
+ // Simple debounce - ignore if orientation changed in last 30 frames (about 1/2 second)
278
+ if (frameCount - lastOrientationFrame > 30) {
279
+ // Toggle background color
280
+ isBlueBackground = !isBlueBackground;
281
+
282
+ // Increment counter
283
+ orientationCount++;
284
+
285
+ // Update tracking variables
286
+ lastOrientation = currentOrientation;
287
+ currentOrientation = newOrientation;
288
+ lastOrientationFrame = frameCount;
289
+
290
+ console.log('Orientation changed from', lastOrientation, 'to', currentOrientation, '! Count:', orientationCount);
291
+ }
292
+ } else {
293
+ // Update current orientation without triggering change
294
+ currentOrientation = newOrientation;
295
+ }
296
+ }
297
+ }
298
+
299
+ // Handle screen rotation (this will trigger our orientation change detection)
300
+ function windowResized() {
301
+ resizeCanvas(windowWidth, windowHeight);
302
+
303
+ // Recalculate layout
304
+ topSectionHeight = height * 0.5;
305
+ bottomSectionHeight = height * 0.5;
306
+ dividerY = height * 0.5;
307
+
308
+ // Reposition button
309
+ buttonX = width / 2 - buttonWidth / 2;
310
+ buttonY = topSectionHeight / 2 - buttonHeight / 2;
311
+ }
312
+
313
+ // Called when permissions are ready
314
+ function userSetupComplete() {
315
+ console.log('Motion sensors enabled! You can now rotate the device.');
316
+ updateOrientation(); // Initialize orientation tracking
317
+ }