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,375 @@
1
+ // Sliders vs Device Rotation Comparison
2
+ // Shows traditional RGB sliders vs device rotation control
3
+
4
+ // Color scheme
5
+ let backgroundColor;
6
+
7
+ // Slider properties
8
+ let sliderValues = [0.5, 0.5, 0.5]; // RGB values (0.0-1.0)
9
+ let sliderLabels = ['Red', 'Green', 'Blue'];
10
+ let sliderColors = [];
11
+ let sliderMin = 0.0;
12
+ let sliderMax = 1.0;
13
+ let sliders = [];
14
+ let isDraggingSlider = -1; // -1 = none, 0-2 = slider index
15
+
16
+ // Rotation values
17
+ let rotationValues = [0.0, 0.0, 0.0]; // X, Y, Z rotation
18
+ let normalizedRotation = [0.5, 0.5, 0.5]; // Normalized to 0.0-1.0
19
+
20
+ // Layout properties
21
+ let currentOrientation = 'portrait';
22
+ let topSectionHeight;
23
+ let bottomSectionHeight;
24
+ let dividerY;
25
+
26
+ // Slider dimensions
27
+ let sliderWidth = 250;
28
+ let sliderHeight = 30;
29
+ let sliderSpacing = 60;
30
+
31
+ function addLog(message) {
32
+ console.log(message); // Only log to browser console
33
+ }
34
+
35
+ function setup() {
36
+ createCanvas(windowWidth, windowHeight);
37
+
38
+ // Initialize colors
39
+ backgroundColor = color(44, 62, 80); // Dark blue-gray
40
+ sliderColors = [
41
+ color(231, 76, 60), // Red
42
+ color(46, 204, 113), // Green
43
+ color(52, 152, 219) // Blue
44
+ ];
45
+
46
+ // Enable gesture locking and motion sensors (using new permissionsAll.js system)
47
+ addLog('Calling lockGestures()...');
48
+ lockGestures();
49
+
50
+ addLog('Calling enableGyroTap()...');
51
+ enableGyroTap('Tap to enable device rotation detection');
52
+
53
+ // Calculate layout
54
+ updateLayout();
55
+
56
+ // Initialize slider positions
57
+ updateSliderPositions();
58
+
59
+ addLog('Sliders vs Rotation ready!');
60
+ addLog('Canvas size: ' + width + 'x' + height);
61
+ addLog('Using permissionsAll.js system');
62
+ }
63
+
64
+ function draw() {
65
+ // Update rotation values
66
+ updateRotationValues();
67
+
68
+ // Update orientation
69
+ updateOrientation();
70
+
71
+ // Set background based on current mode
72
+ if (window.sensorsEnabled) {
73
+ // Use rotation for background color
74
+ backgroundColor = color(
75
+ normalizedRotation[0] * 255, // Red from rotation X
76
+ normalizedRotation[1] * 255, // Green from rotation Y
77
+ normalizedRotation[2] * 255 // Blue from rotation Z
78
+ );
79
+ } else {
80
+ // Use sliders for background color
81
+ backgroundColor = color(
82
+ sliderValues[0] * 255, // Red
83
+ sliderValues[1] * 255, // Green
84
+ sliderValues[2] * 255 // Blue
85
+ );
86
+ }
87
+
88
+ background(backgroundColor);
89
+
90
+ // Draw top section - sliders
91
+ drawTopSection();
92
+
93
+ // Draw divider
94
+ drawDivider();
95
+
96
+ // Draw bottom section - rotation
97
+ drawBottomSection();
98
+ }
99
+
100
+ function drawTopSection() {
101
+ // Section title
102
+ fill(255, 255, 255);
103
+ textSize(20);
104
+ if (currentOrientation === 'landscape') {
105
+ textAlign(LEFT, CENTER);
106
+ text('TRADITIONAL UI', 30, 30);
107
+ } else {
108
+ textAlign(CENTER, CENTER);
109
+ text('TRADITIONAL UI', width / 2, 30);
110
+ }
111
+
112
+ // Draw all three sliders
113
+ for (let i = 0; i < 3; i++) {
114
+ drawSlider(i);
115
+ }
116
+
117
+ // Draw color preview rectangle
118
+ let previewColor = color(
119
+ sliderValues[0] * 255,
120
+ sliderValues[1] * 255,
121
+ sliderValues[2] * 255
122
+ );
123
+ fill(previewColor);
124
+ noStroke();
125
+ if (currentOrientation === 'landscape') {
126
+ rect(30, topSectionHeight - 60, 200, 40);
127
+ } else {
128
+ rect(width / 2 - 100, topSectionHeight - 60, 200, 40);
129
+ }
130
+ }
131
+
132
+ function drawBottomSection() {
133
+ // Section title
134
+ fill(255, 255, 255);
135
+ textSize(20);
136
+ if (currentOrientation === 'landscape') {
137
+ textAlign(LEFT, CENTER);
138
+ text('MOBILE INTERACTION', 30, dividerY + 30);
139
+ } else {
140
+ textAlign(CENTER, CENTER);
141
+ text('MOBILE INTERACTION', width / 2, dividerY + 30);
142
+ }
143
+
144
+ // Instructions or rotation values
145
+ if (window.sensorsEnabled) {
146
+ drawRotationDisplay();
147
+ } else {
148
+ fill(255, 255, 255, 200);
149
+ textSize(16);
150
+ textAlign(CENTER, CENTER);
151
+ text('Tap to enable device rotation!', width / 2, dividerY + 80);
152
+ }
153
+ }
154
+
155
+ function drawDivider() {
156
+ // Draw divider line
157
+ stroke(255, 255, 255, 100);
158
+ strokeWeight(2);
159
+ line(0, dividerY, width, dividerY);
160
+ noStroke();
161
+ }
162
+
163
+ function drawSlider(index) {
164
+ let slider = sliders[index];
165
+ if (!slider) return;
166
+
167
+ // Slider track
168
+ fill(100, 100, 100);
169
+ noStroke();
170
+ rect(slider.x, slider.y, sliderWidth, sliderHeight, 15);
171
+
172
+ // Slider fill
173
+ fill(sliderColors[index]);
174
+ let fillWidth = sliderValues[index] * sliderWidth;
175
+ rect(slider.x, slider.y, fillWidth, sliderHeight, 15);
176
+
177
+ // Slider handle
178
+ fill(255, 255, 255);
179
+ let handleX = slider.x + (sliderValues[index] * sliderWidth);
180
+ circle(handleX, slider.y + sliderHeight / 2, sliderHeight + 10);
181
+
182
+ // Label
183
+ fill(255, 255, 255);
184
+ textAlign(LEFT, CENTER);
185
+ textSize(16);
186
+ text(sliderLabels[index], slider.x, slider.y - 20);
187
+
188
+ // Value
189
+ textAlign(RIGHT, CENTER);
190
+ textSize(14);
191
+ text((sliderValues[index] * 255).toFixed(0), slider.x + sliderWidth, slider.y - 20);
192
+ }
193
+
194
+ function drawRotationDisplay() {
195
+ fill(255, 255, 255);
196
+ textAlign(CENTER, CENTER);
197
+ textSize(18); // Increased from 14
198
+
199
+ let startY = dividerY + 80;
200
+
201
+ text('Rotate your device!', width / 2, startY);
202
+
203
+ textSize(20); // Increased from 14 for rotation values
204
+ text('X: ' + rotationValues[0].toFixed(1) + '°', width / 2, startY + 40);
205
+ text('Y: ' + rotationValues[1].toFixed(1) + '°', width / 2, startY + 70);
206
+ text('Z: ' + rotationValues[2].toFixed(1) + '°', width / 2, startY + 100);
207
+
208
+ // Draw color preview from rotation
209
+ let rotationColor = color(
210
+ normalizedRotation[0] * 255,
211
+ normalizedRotation[1] * 255,
212
+ normalizedRotation[2] * 255
213
+ );
214
+ fill(rotationColor);
215
+ noStroke();
216
+ rect(width / 2 - 100, startY + 130, 200, 40);
217
+ }
218
+
219
+ // Slider helper functions
220
+ function updateSliderPositions() {
221
+ sliders = [];
222
+ let startY = 70;
223
+
224
+ for (let i = 0; i < 3; i++) {
225
+ let slider = {
226
+ x: currentOrientation === 'landscape' ? 30 : (width - sliderWidth) / 2,
227
+ y: startY + (i * sliderSpacing),
228
+ width: sliderWidth,
229
+ height: sliderHeight
230
+ };
231
+ sliders.push(slider);
232
+ }
233
+ }
234
+
235
+ function isSliderPressed(sliderIndex, x, y) {
236
+ let slider = sliders[sliderIndex];
237
+ if (!slider) return false;
238
+
239
+ return (x >= slider.x && x <= slider.x + slider.width &&
240
+ y >= slider.y && y <= slider.y + slider.height);
241
+ }
242
+
243
+ function updateSliderValue(sliderIndex, x) {
244
+ let slider = sliders[sliderIndex];
245
+ if (!slider) return;
246
+
247
+ let normalizedX = (x - slider.x) / slider.width;
248
+ normalizedX = constrain(normalizedX, 0, 1);
249
+
250
+ sliderValues[sliderIndex] = map(normalizedX, 0, 1, sliderMin, sliderMax);
251
+ sliderValues[sliderIndex] = constrain(sliderValues[sliderIndex], sliderMin, sliderMax);
252
+ }
253
+
254
+ function updateRotationValues() {
255
+ if (window.sensorsEnabled) {
256
+ // Get rotation values from p5.js - use the same approach as gyroscope-demo
257
+ rotationValues[0] = rotationX || 0;
258
+ rotationValues[1] = rotationY || 0;
259
+ rotationValues[2] = rotationZ || 0;
260
+
261
+ // Normalize rotation values to 0.0-1.0 range
262
+ // Map from -180 to 180 degrees to 0.0 to 1.0
263
+ normalizedRotation[0] = map(rotationValues[0], -180, 180, 0.0, 1.0);
264
+ normalizedRotation[1] = map(rotationValues[1], -180, 180, 0.0, 1.0);
265
+ normalizedRotation[2] = map(rotationValues[2], -180, 180, 0.0, 1.0);
266
+
267
+ // Constrain to 0.0-1.0 range
268
+ normalizedRotation[0] = constrain(normalizedRotation[0], 0.0, 1.0);
269
+ normalizedRotation[1] = constrain(normalizedRotation[1], 0.0, 1.0);
270
+ normalizedRotation[2] = constrain(normalizedRotation[2], 0.0, 1.0);
271
+ }
272
+ }
273
+
274
+ // Handle touch interaction for mobile
275
+ function touchStarted() {
276
+ // Check all sliders for touch in top section
277
+ if (touches && touches.length >= 1) {
278
+ for (let touch of touches) {
279
+ if (touch && touch.y < dividerY) {
280
+ for (let i = 0; i < 3; i++) {
281
+ if (isSliderPressed(i, touch.x, touch.y)) {
282
+ isDraggingSlider = i;
283
+ updateSliderValue(i, touch.x);
284
+ return false; // Only prevent default if we actually handled a slider
285
+ }
286
+ }
287
+ }
288
+ }
289
+ }
290
+ // Don't prevent default if we didn't handle the touch - this allows overlay clicks to work
291
+ }
292
+
293
+ function touchMoved() {
294
+ // Update slider if dragging
295
+ if (isDraggingSlider !== -1 && touches && touches.length >= 1) {
296
+ for (let touch of touches) {
297
+ if (touch && touch.y < dividerY) {
298
+ updateSliderValue(isDraggingSlider, touch.x);
299
+ return false; // Only prevent default when actively dragging
300
+ }
301
+ }
302
+ }
303
+ // Don't prevent default if we're not dragging
304
+ }
305
+
306
+ function touchEnded() {
307
+ // Check if any touches remain in slider area
308
+ if (isDraggingSlider !== -1) {
309
+ let sliderTouchExists = false;
310
+ if (touches && touches.length > 0) {
311
+ for (let touch of touches) {
312
+ if (touch && touch.y < dividerY && isSliderPressed(isDraggingSlider, touch.x, touch.y)) {
313
+ sliderTouchExists = true;
314
+ break;
315
+ }
316
+ }
317
+ }
318
+ if (!sliderTouchExists) {
319
+ isDraggingSlider = -1;
320
+ }
321
+ }
322
+ // Don't prevent default - allow other handlers to process the event
323
+ }
324
+
325
+ // Handle mouse interaction for desktop testing
326
+ function mousePressed() {
327
+ if (mouseY < dividerY) {
328
+ for (let i = 0; i < 3; i++) {
329
+ if (isSliderPressed(i, mouseX, mouseY)) {
330
+ isDraggingSlider = i;
331
+ updateSliderValue(i, mouseX);
332
+ return false;
333
+ }
334
+ }
335
+ }
336
+ }
337
+
338
+ function mouseDragged() {
339
+ if (isDraggingSlider !== -1) {
340
+ updateSliderValue(isDraggingSlider, mouseX);
341
+ return false;
342
+ }
343
+ }
344
+
345
+ function mouseReleased() {
346
+ isDraggingSlider = -1;
347
+ }
348
+
349
+ function updateLayout() {
350
+ topSectionHeight = height * 0.5;
351
+ bottomSectionHeight = height * 0.5;
352
+ dividerY = height * 0.5;
353
+
354
+ updateSliderPositions();
355
+ }
356
+
357
+ function windowResized() {
358
+ resizeCanvas(windowWidth, windowHeight);
359
+ updateLayout();
360
+ }
361
+
362
+ function updateOrientation() {
363
+ currentOrientation = (width > height) ? 'landscape' : 'portrait';
364
+ }
365
+
366
+ // Called when permissions are ready
367
+ function userSetupComplete() {
368
+ addLog('userSetupComplete() called!');
369
+ addLog('Motion sensors should be enabled now');
370
+ addLog('window.sensorsEnabled: ' + window.sensorsEnabled);
371
+ addLog('Checking rotation variables:');
372
+ addLog('rotationX type: ' + typeof rotationX + ' value: ' + rotationX);
373
+ addLog('rotationY type: ' + typeof rotationY + ' value: ' + rotationY);
374
+ addLog('rotationZ type: ' + typeof rotationZ + ' value: ' + rotationZ);
375
+ }
@@ -0,0 +1,31 @@
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">
6
+ <title>Mobile p5.js App</title>
7
+
8
+ <!-- Basic CSS to remove browser defaults and align canvas -->
9
+ <style>
10
+ body {
11
+ margin: 0;
12
+ padding: 0;
13
+ overflow: hidden;
14
+ }
15
+ </style>
16
+
17
+ <!-- Load p5.js library -->
18
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.10/p5.min.js"></script>
19
+
20
+ <!-- Load p5.sound library for microphone -->
21
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.0/addons/p5.sound.min.js"></script>
22
+
23
+ <!-- Load the mobile p5.js permissions library -->
24
+ <script src="https://cdn.jsdelivr.net/npm/mobile-p5-permissions@1.4.4/dist/p5.mobile-permissions.min.js"></script>
25
+
26
+ </head>
27
+ <body>
28
+ <!-- Load the p5.js sketch -->
29
+ <script src="sketch.js"></script>
30
+ </body>
31
+ </html>
@@ -0,0 +1,55 @@
1
+ // Global variable for microphone
2
+ let mic;
3
+
4
+ function setup()
5
+ {
6
+ // Show debug panel FIRST to catch setup errors
7
+ showDebug();
8
+
9
+ createCanvas(windowWidth, windowHeight);
10
+
11
+ // Lock mobile gestures to prevent browser interference
12
+ lockGestures();
13
+
14
+ // Create microphone input
15
+ mic = new p5.AudioIn();
16
+
17
+ // Enable motion sensors with tap-to-start
18
+ enableGyroTap('Tap to enable motion sensors');
19
+
20
+ // Enable microphone with tap-to-start
21
+ enableMicTap('Tap to enable microphone');
22
+ }
23
+
24
+ function draw()
25
+ {
26
+ background(220);
27
+
28
+ if (window.sensorsEnabled)
29
+ {
30
+ // Use device rotation and acceleration
31
+ fill(255, 0, 0);
32
+ circle(width/2 + rotationY * 5, height/2 + rotationX * 5, 50);
33
+ }
34
+
35
+ if (window.micEnabled)
36
+ {
37
+ // Use microphone input
38
+ let micLevel = mic.getLevel();
39
+ let size = map(micLevel, 0, 1, 10, 200);
40
+
41
+ fill(0, 255, 0);
42
+ circle(width/2, height/2, size);
43
+ }
44
+ }
45
+
46
+ // Prevent default touch behavior (optional but recommended)
47
+ function touchStarted()
48
+ {
49
+ return false;
50
+ }
51
+
52
+ function touchEnded()
53
+ {
54
+ return false;
55
+ }