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,336 @@
1
+ // Slider vs Microphone Comparison
2
+ // Shows traditional volume slider vs microphone input
3
+
4
+ // Color scheme
5
+ let backgroundColor;
6
+
7
+ // Slider properties
8
+ let sliderValue = 0.5; // Volume value (0.0-1.0)
9
+ let sliderMin = 0.0;
10
+ let sliderMax = 1.0;
11
+ let slider = {};
12
+ let isDraggingSlider = false;
13
+
14
+ // Microphone properties
15
+ let mic;
16
+ let micLevel = 0.0;
17
+
18
+ // Layout properties
19
+ let currentOrientation = 'portrait';
20
+ let topSectionHeight;
21
+ let bottomSectionHeight;
22
+ let dividerY;
23
+
24
+ // Slider dimensions
25
+ let sliderWidth = 250;
26
+ let sliderHeight = 30;
27
+
28
+ function setup() {
29
+ createCanvas(windowWidth, windowHeight);
30
+
31
+ // Initialize colors
32
+ backgroundColor = color(44, 62, 80); // Dark blue-gray
33
+
34
+ // Create microphone input (this is the key - create it here first!)
35
+ mic = new p5.AudioIn();
36
+
37
+ // Enable gesture locking and microphone using the new system
38
+ lockGestures();
39
+ enableMicTap('Tap to enable microphone');
40
+
41
+ // Calculate layout
42
+ updateLayout();
43
+
44
+ // Initialize slider position
45
+ updateSliderPosition();
46
+
47
+ console.log('Slider vs Microphone ready!');
48
+ }
49
+
50
+ function draw() {
51
+ // Update microphone level
52
+ updateMicLevel();
53
+
54
+ // Update orientation
55
+ updateOrientation();
56
+
57
+ // Set background based on current mode
58
+ if (window.micEnabled && mic) {
59
+ // Use microphone for background intensity
60
+ let intensity = micLevel * 255;
61
+ backgroundColor = color(intensity * 0.8, intensity * 0.6, intensity * 1.0);
62
+ } else {
63
+ // Use slider for background intensity
64
+ let intensity = sliderValue * 255;
65
+ backgroundColor = color(intensity * 0.8, intensity * 0.6, intensity * 1.0);
66
+ }
67
+
68
+ background(backgroundColor);
69
+
70
+ // Draw top section - slider
71
+ drawTopSection();
72
+
73
+ // Draw divider
74
+ drawDivider();
75
+
76
+ // Draw bottom section - microphone
77
+ drawBottomSection();
78
+ }
79
+
80
+ function drawTopSection() {
81
+ // Section title
82
+ fill(255, 255, 255);
83
+ textSize(20);
84
+ if (currentOrientation === 'landscape') {
85
+ textAlign(LEFT, CENTER);
86
+ text('TRADITIONAL UI', 30, 30);
87
+ } else {
88
+ textAlign(CENTER, CENTER);
89
+ text('TRADITIONAL UI', width / 2, 30);
90
+ }
91
+
92
+ // Draw volume slider
93
+ drawSlider();
94
+
95
+ // Draw volume bars visualization
96
+ drawVolumeBars(sliderValue, 80);
97
+ }
98
+
99
+ function drawBottomSection() {
100
+ // Section title
101
+ fill(255, 255, 255);
102
+ textSize(20);
103
+ if (currentOrientation === 'landscape') {
104
+ textAlign(LEFT, CENTER);
105
+ text('MOBILE INTERACTION', 30, dividerY + 30);
106
+ } else {
107
+ textAlign(CENTER, CENTER);
108
+ text('MOBILE INTERACTION', width / 2, dividerY + 30);
109
+ }
110
+
111
+ // Instructions or microphone visualization
112
+ if (window.micEnabled && mic) {
113
+ drawMicrophoneDisplay();
114
+ } else {
115
+ fill(255, 255, 255, 200);
116
+ textSize(16);
117
+ textAlign(CENTER, CENTER);
118
+ text('Tap to enable microphone!', width / 2, dividerY + 80);
119
+ }
120
+ }
121
+
122
+ function drawDivider() {
123
+ // Draw divider line
124
+ stroke(255, 255, 255, 100);
125
+ strokeWeight(2);
126
+ line(0, dividerY, width, dividerY);
127
+ noStroke();
128
+ }
129
+
130
+ function drawSlider() {
131
+ // Slider track
132
+ fill(100, 100, 100);
133
+ noStroke();
134
+ rect(slider.x, slider.y, sliderWidth, sliderHeight, 15);
135
+
136
+ // Slider fill
137
+ fill(100, 200, 255); // Blue color
138
+ let fillWidth = sliderValue * sliderWidth;
139
+ rect(slider.x, slider.y, fillWidth, sliderHeight, 15);
140
+
141
+ // Slider handle
142
+ fill(255, 255, 255);
143
+ let handleX = slider.x + (sliderValue * sliderWidth);
144
+ circle(handleX, slider.y + sliderHeight / 2, sliderHeight + 10);
145
+
146
+ // Label
147
+ fill(255, 255, 255);
148
+ textAlign(LEFT, CENTER);
149
+ textSize(16);
150
+ text('Volume', slider.x, slider.y - 20);
151
+
152
+ // Value
153
+ textAlign(RIGHT, CENTER);
154
+ textSize(14);
155
+ text((sliderValue * 100).toFixed(0) + '%', slider.x + sliderWidth, slider.y - 20);
156
+ }
157
+
158
+ function drawVolumeBars(level, startY) {
159
+ let barCount = 20;
160
+ let barWidth = Math.min(200, width - 60) / barCount;
161
+ let barSpacing = 2;
162
+ let maxBarHeight = 80;
163
+
164
+ let centerX = width / 2;
165
+ let totalWidth = (barWidth + barSpacing) * barCount - barSpacing;
166
+ let startX = centerX - totalWidth / 2;
167
+
168
+ for (let i = 0; i < barCount; i++) {
169
+ let barHeight = (level * maxBarHeight) * (1 - (abs(i - barCount/2) / (barCount/2)));
170
+ barHeight = Math.max(barHeight, 5);
171
+
172
+ // Color based on position
173
+ let hue = map(i, 0, barCount - 1, 0.3, 0.7);
174
+ fill(hue * 255, 200, 255);
175
+
176
+ let x = startX + i * (barWidth + barSpacing);
177
+ let y = startY + maxBarHeight - barHeight;
178
+
179
+ rect(x, y, barWidth, barHeight, 2);
180
+ }
181
+ }
182
+
183
+ function drawMicrophoneDisplay() {
184
+ fill(255, 255, 255);
185
+ textAlign(CENTER, CENTER);
186
+ textSize(18);
187
+
188
+ let startY = dividerY + 80;
189
+
190
+ text('Speak or make noise!', width / 2, startY);
191
+
192
+ // Show microphone level
193
+ textSize(20);
194
+ text('Level: ' + (micLevel * 100).toFixed(0) + '%', width / 2, startY + 40);
195
+
196
+ // Draw volume bars visualization for microphone
197
+ drawVolumeBars(micLevel, startY + 80);
198
+
199
+ // Draw microphone level indicator
200
+ fill(255, 100, 100); // Red color for mic
201
+ noStroke();
202
+ let indicatorWidth = 200;
203
+ let indicatorHeight = 20;
204
+ let micFillWidth = micLevel * indicatorWidth;
205
+
206
+ // Background
207
+ fill(100, 100, 100);
208
+ rect(width / 2 - indicatorWidth / 2, startY + 170, indicatorWidth, indicatorHeight, 10);
209
+
210
+ // Fill
211
+ fill(255, 100, 100);
212
+ rect(width / 2 - indicatorWidth / 2, startY + 170, micFillWidth, indicatorHeight, 10);
213
+ }
214
+
215
+ function updateMicLevel() {
216
+ if (window.micEnabled && mic) {
217
+ let rawLevel = mic.getLevel();
218
+ micLevel = constrain(rawLevel * 5, 0, 1); // Amplify and constrain
219
+ }
220
+ }
221
+
222
+ // Slider helper functions
223
+ function updateSliderPosition() {
224
+ slider = {
225
+ x: currentOrientation === 'landscape' ? 30 : (width - sliderWidth) / 2,
226
+ y: 70,
227
+ width: sliderWidth,
228
+ height: sliderHeight
229
+ };
230
+ }
231
+
232
+ function isSliderPressed(x, y) {
233
+ return (x >= slider.x && x <= slider.x + slider.width &&
234
+ y >= slider.y && y <= slider.y + slider.height);
235
+ }
236
+
237
+ function updateSliderValue(x) {
238
+ let normalizedX = (x - slider.x) / slider.width;
239
+ normalizedX = constrain(normalizedX, 0, 1);
240
+
241
+ sliderValue = map(normalizedX, 0, 1, sliderMin, sliderMax);
242
+ sliderValue = constrain(sliderValue, sliderMin, sliderMax);
243
+ }
244
+
245
+ // Handle touch interaction for mobile
246
+ function touchStarted() {
247
+ // Check slider for touch in top section
248
+ if (touches && touches.length >= 1) {
249
+ for (let touch of touches) {
250
+ if (touch && touch.y < dividerY) {
251
+ if (isSliderPressed(touch.x, touch.y)) {
252
+ isDraggingSlider = true;
253
+ updateSliderValue(touch.x);
254
+ return false; // Only prevent default if we actually handled the slider
255
+ }
256
+ }
257
+ }
258
+ }
259
+ // Don't prevent default if we didn't handle the touch - this allows overlay clicks to work
260
+ }
261
+
262
+ function touchMoved() {
263
+ // Update slider if dragging
264
+ if (isDraggingSlider && touches && touches.length >= 1) {
265
+ for (let touch of touches) {
266
+ if (touch && touch.y < dividerY) {
267
+ updateSliderValue(touch.x);
268
+ return false; // Only prevent default when actively dragging
269
+ }
270
+ }
271
+ }
272
+ // Don't prevent default if we're not dragging
273
+ }
274
+
275
+ function touchEnded() {
276
+ // Check if any touches remain in slider area
277
+ if (isDraggingSlider) {
278
+ let sliderTouchExists = false;
279
+ if (touches && touches.length > 0) {
280
+ for (let touch of touches) {
281
+ if (touch && touch.y < dividerY && isSliderPressed(touch.x, touch.y)) {
282
+ sliderTouchExists = true;
283
+ break;
284
+ }
285
+ }
286
+ }
287
+ if (!sliderTouchExists) {
288
+ isDraggingSlider = false;
289
+ }
290
+ }
291
+ // Don't prevent default - allow other handlers to process the event
292
+ }
293
+
294
+ // Handle mouse interaction for desktop testing
295
+ function mousePressed() {
296
+ if (mouseY < dividerY) {
297
+ if (isSliderPressed(mouseX, mouseY)) {
298
+ isDraggingSlider = true;
299
+ updateSliderValue(mouseX);
300
+ return false;
301
+ }
302
+ }
303
+ }
304
+
305
+ function mouseDragged() {
306
+ if (isDraggingSlider) {
307
+ updateSliderValue(mouseX);
308
+ return false;
309
+ }
310
+ }
311
+
312
+ function mouseReleased() {
313
+ isDraggingSlider = false;
314
+ }
315
+
316
+ function updateOrientation() {
317
+ currentOrientation = (width > height) ? 'landscape' : 'portrait';
318
+ }
319
+
320
+ function updateLayout() {
321
+ topSectionHeight = height * 0.5;
322
+ bottomSectionHeight = height * 0.5;
323
+ dividerY = height * 0.5;
324
+
325
+ updateSliderPosition();
326
+ }
327
+
328
+ function windowResized() {
329
+ resizeCanvas(windowWidth, windowHeight);
330
+ updateLayout();
331
+ }
332
+
333
+ // Called when permissions are ready
334
+ function userSetupComplete() {
335
+ console.log('Microphone enabled! You can now speak into the device.');
336
+ }
@@ -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>Slider vs Touches - 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>