p5-phone 1.9.0 → 1.9.2

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 (102) hide show
  1. package/README.md +75 -28
  2. package/dist/p5-phone.js +271 -74
  3. package/dist/p5-phone.min.js +2 -2
  4. package/examples/Phone Sensor Examples/microphone/01_mic_level/index.html +4 -3
  5. package/examples/Phone Sensor Examples/microphone/02_speech_recognition/index.html +4 -3
  6. package/examples/Phone Sensor Examples/movement/01_orientation_basic/index.html +3 -3
  7. package/examples/Phone Sensor Examples/movement/02_rotational_velocity/index.html +3 -3
  8. package/examples/Phone Sensor Examples/movement/03_acceleration/index.html +3 -3
  9. package/examples/Phone Sensor Examples/movement/04_device_shaken/index.html +23 -0
  10. package/examples/Phone Sensor Examples/movement/04_device_shaken/sketch.js +146 -0
  11. package/examples/Phone Sensor Examples/movement/05_device_moved/index.html +23 -0
  12. package/examples/Phone Sensor Examples/movement/05_device_moved/sketch.js +175 -0
  13. package/examples/Phone Sensor Examples/movement/06_device_orientation/index.html +23 -0
  14. package/examples/Phone Sensor Examples/movement/06_device_orientation/sketch.js +120 -0
  15. package/examples/Phone Sensor Examples/nfc/01_nfc_read/index.html +5 -5
  16. package/examples/Phone Sensor Examples/nfc/01_nfc_read/sketch.js +252 -32
  17. package/examples/Phone Sensor Examples/nfc/02_two_tag_effects/index.html +25 -0
  18. package/examples/Phone Sensor Examples/nfc/02_two_tag_effects/sketch.js +208 -0
  19. package/examples/Phone Sensor Examples/sound/01_dual_audio/index.html +4 -4
  20. package/examples/Phone Sensor Examples/sound/01_dual_audio/sketch.js +54 -69
  21. package/examples/Phone Sensor Examples/sound/02_volume_touches/index.html +4 -4
  22. package/examples/Phone Sensor Examples/sound/02_volume_touches/sketch.js +67 -74
  23. package/examples/Phone Sensor Examples/sound/03_motion_synth/index.html +24 -0
  24. package/examples/Phone Sensor Examples/sound/03_motion_synth/sketch.js +172 -0
  25. package/examples/Phone Sensor Examples/touch/01_touch_basic/index.html +3 -3
  26. package/examples/Phone Sensor Examples/touch/02_touch_zones/index.html +3 -3
  27. package/examples/Phone Sensor Examples/touch/03_touch_count/index.html +3 -3
  28. package/examples/Phone Sensor Examples/touch/04_touch_distance/index.html +3 -3
  29. package/examples/Phone Sensor Examples/touch/05_touch_angle/index.html +3 -3
  30. package/examples/Phone Sensor Examples/vibration/01_haptic_feedback/index.html +3 -3
  31. package/examples/Phone Sensor Examples/vibration/01_haptic_feedback/sketch.js +72 -74
  32. package/examples/Phone Sensor Examples - Minimal/microphone/01_mic_level/index.html +4 -3
  33. package/examples/Phone Sensor Examples - Minimal/movement/01_orientation_basic/index.html +3 -2
  34. package/examples/Phone Sensor Examples - Minimal/movement/02_rotational_velocity/index.html +3 -2
  35. package/examples/Phone Sensor Examples - Minimal/movement/03_acceleration/index.html +3 -2
  36. package/examples/Phone Sensor Examples - Minimal/movement/04_device_shaken/index.html +19 -0
  37. package/examples/Phone Sensor Examples - Minimal/movement/04_device_shaken/sketch.js +46 -0
  38. package/examples/Phone Sensor Examples - Minimal/movement/05_device_moved/index.html +19 -0
  39. package/examples/Phone Sensor Examples - Minimal/movement/05_device_moved/sketch.js +46 -0
  40. package/examples/Phone Sensor Examples - Minimal/movement/06_device_orientation/index.html +19 -0
  41. package/examples/Phone Sensor Examples - Minimal/movement/06_device_orientation/sketch.js +40 -0
  42. package/examples/Phone Sensor Examples - Minimal/sound/01_sound_basic/index.html +4 -3
  43. package/examples/Phone Sensor Examples - Minimal/sound/01_sound_basic/sketch.js +20 -23
  44. package/examples/Phone Sensor Examples - Minimal/sound/02_sound_amplitude/index.html +4 -3
  45. package/examples/Phone Sensor Examples - Minimal/sound/02_sound_amplitude/sketch.js +27 -30
  46. package/examples/Phone Sensor Examples - Minimal/sound/03_motion_synth/index.html +20 -0
  47. package/examples/Phone Sensor Examples - Minimal/sound/03_motion_synth/sketch.js +63 -0
  48. package/examples/Phone Sensor Examples - Minimal/touch/01_touch_basic/index.html +3 -2
  49. package/examples/Phone Sensor Examples - Minimal/touch/02_touch_zones/index.html +3 -2
  50. package/examples/Phone Sensor Examples - Minimal/touch/03_touch_count/index.html +3 -2
  51. package/examples/Phone Sensor Examples - Minimal/touch/04_touch_distance/index.html +3 -2
  52. package/examples/Phone Sensor Examples - Minimal/touch/05_touch_angle/index.html +3 -2
  53. package/examples/Phone Sensor Examples - Minimal/vibration/01_haptic_feedback/index.html +3 -2
  54. package/examples/Phone Sensor Examples - Minimal/vibration/01_haptic_feedback/sketch.js +45 -44
  55. package/examples/Phone and Gif/collision/index.html +3 -2
  56. package/examples/Phone and Gif/collision/sketch.js +28 -31
  57. package/examples/Phone and Gif/fetch/index.html +3 -2
  58. package/examples/Phone and Gif/fetch/sketch.js +27 -30
  59. package/examples/Phone and Gif/fly/index.html +3 -2
  60. package/examples/Phone and Gif/fly/sketch.js +19 -22
  61. package/examples/Phone and Gif/roll/index.html +3 -2
  62. package/examples/Phone and Gif/roll/sketch.js +21 -24
  63. package/examples/UIStyles/banner-style/index.html +3 -3
  64. package/examples/UIStyles/canvas-style/index.html +3 -3
  65. package/examples/UIStyles/canvas-style/sketch.js +13 -13
  66. package/examples/UIStyles/custom-element/index.html +3 -3
  67. package/examples/UIStyles/custom-element/sketch.js +19 -20
  68. package/examples/UXcompare/button-vs-movement/index.html +3 -3
  69. package/examples/UXcompare/button-vs-orientation/index.html +3 -3
  70. package/examples/UXcompare/button-vs-shake/index.html +3 -3
  71. package/examples/UXcompare/gyroscope-demo/index.html +3 -3
  72. package/examples/UXcompare/microphone-demo/index.html +4 -4
  73. package/examples/UXcompare/slider-vs-angle/index.html +3 -3
  74. package/examples/UXcompare/slider-vs-distance/index.html +3 -3
  75. package/examples/UXcompare/slider-vs-microphone/index.html +4 -4
  76. package/examples/UXcompare/slider-vs-touches/index.html +3 -3
  77. package/examples/UXcompare/sliders-vs-acceleration/index.html +3 -3
  78. package/examples/UXcompare/sliders-vs-rotation/index.html +3 -3
  79. package/examples/blankTemplate/index.html +4 -4
  80. package/examples/homepage/index.html +244 -1416
  81. package/examples/homepage/scripts/api-data.js +129 -0
  82. package/examples/homepage/scripts/examples-data.js +463 -0
  83. package/examples/homepage/scripts/navigation.js +45 -0
  84. package/examples/homepage/scripts/render.js +264 -0
  85. package/examples/homepage/styles/main.css +133 -0
  86. package/examples/homepage-v1/index.html +1538 -0
  87. package/examples/homepage-v2/index.html +13 -0
  88. package/examples/ml5/Gaze_detector_class/GazeDetector.js +1 -1
  89. package/examples/ml5/Gaze_detector_class/README.md +1 -1
  90. package/examples/ml5/Gaze_detector_class/index.html +3 -3
  91. package/examples/ml5/PHONE_BodyPose_two_points/index.html +3 -3
  92. package/examples/ml5/PHONE_BodyPose_two_points/sketch.js +1 -1
  93. package/examples/ml5/PHONE_FaceMesh_two_points/index.html +3 -3
  94. package/examples/ml5/PHONE_FaceMesh_two_points/sketch.js +1 -1
  95. package/examples/ml5/PHONE_HandPose_two_points/index.html +3 -3
  96. package/examples/ml5/PHONE_HandPose_two_points/sketch.js +1 -1
  97. package/examples/ml5/PHONE_ObjectDetection/index.html +27 -0
  98. package/examples/ml5/PHONE_ObjectDetection/sketch.js +236 -0
  99. package/examples/ml5/THREE_FaceMesh_two_points/sketch.js +1 -1
  100. package/examples/ml5/THREE_HandPose_two_points/sketch.js +1 -1
  101. package/package.json +2 -2
  102. package/src/p5-phone.js +271 -74
package/README.md CHANGED
@@ -102,10 +102,10 @@ p5-phone automatically detects the p5.js version and adjusts its internal touch
102
102
 
103
103
  ```html
104
104
  <!-- Minified version (recommended) -->
105
- <script src="https://cdn.jsdelivr.net/npm/p5-phone@1.9.0/dist/p5-phone.min.js"></script>
105
+ <script src="https://cdn.jsdelivr.net/npm/p5-phone@1.9.1/dist/p5-phone.min.js"></script>
106
106
 
107
107
  <!-- Development version (larger, with comments) -->
108
- <!-- <script src="https://cdn.jsdelivr.net/npm/p5-phone@1.9.0/dist/p5-phone.js"></script> -->
108
+ <!-- <script src="https://cdn.jsdelivr.net/npm/p5-phone@1.9.1/dist/p5-phone.js"></script> -->
109
109
  ```
110
110
 
111
111
  ### Basic Setup
@@ -130,11 +130,11 @@ p5-phone automatically detects the p5.js version and adjusts its internal touch
130
130
  </style>
131
131
 
132
132
  <!-- Load p5.js library -->
133
- <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.10/p5.min.js"></script>
134
- <!-- For p5.js 2.0: <script src="https://cdn.jsdelivr.net/npm/p5@2/lib/p5.min.js"></script> -->
133
+ <script src="https://cdn.jsdelivr.net/npm/p5@2.2.3/lib/p5.js"></script>
134
+ <script src="https://cdn.jsdelivr.net/npm/p5.js-compatibility@0.2.0/src/preload.js"></script>
135
135
 
136
136
  <!-- Load p5-phone library -->
137
- <script src="https://cdn.jsdelivr.net/npm/p5-phone@1.9.0/dist/p5-phone.min.js"></script>
137
+ <script src="https://cdn.jsdelivr.net/npm/p5-phone@1.9.1/dist/p5-phone.min.js"></script>
138
138
 
139
139
  </head>
140
140
  <body>
@@ -305,6 +305,8 @@ this.enableGyroTap('Tap to start');
305
305
  - `window.speechEnabled` - Boolean indicating if speech recognition is active
306
306
  - `window.vibrationEnabled` - Boolean indicating if vibration is available (Android only)
307
307
  - `window.nfcEnabled` - Boolean indicating if NFC scanning is active (Android only)
308
+ - `window.lastNfcSerialNumber` - Serial number string for the most recently read NFC tag
309
+ - `window.lastNfcAlias` - Alias string for the most recently read NFC tag, if one has been set
308
310
 
309
311
  **Usage:**
310
312
  ```javascript
@@ -337,11 +339,10 @@ function draw() {
337
339
  }
338
340
 
339
341
  // You can also use them for conditional UI
340
- function setup() {
341
- enableGyroTap('Tap to enable motion');
342
-
343
- // Show different instructions based on status
344
- if (!window.sensorsEnabled) {
342
+ function draw() {
343
+ if (window.sensorsEnabled) {
344
+ debug("Motion sensors enabled");
345
+ } else {
345
346
  debug("Motion sensors not yet enabled");
346
347
  }
347
348
  }
@@ -432,7 +433,7 @@ function draw() {
432
433
 
433
434
  **Important:** Microphone examples require the p5.sound library. Add this script tag to your HTML:
434
435
  ```html
435
- <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.0/addons/p5.sound.min.js"></script>
436
+ <script src="https://cdn.jsdelivr.net/npm/p5.sound@0.3.0/dist/p5.sound.min.js"></script>
436
437
  ```
437
438
 
438
439
  **Commands:**
@@ -488,7 +489,7 @@ function draw() {
488
489
 
489
490
  **Important:** Sound examples require the p5.sound library. Add this script tag to your HTML:
490
491
  ```html
491
- <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.0/addons/p5.sound.min.js"></script>
492
+ <script src="https://cdn.jsdelivr.net/npm/p5.sound@0.3.0/dist/p5.sound.min.js"></script>
492
493
  ```
493
494
 
494
495
  **Commands:**
@@ -661,11 +662,23 @@ function gameOver() {
661
662
  - `enableNfcTap(message)` - Tap anywhere on screen to enable NFC scanning
662
663
  - `enableNfcButton(text)` - Creates a button with custom text to enable NFC
663
664
  - `stopNfc()` - Stop NFC scanning
665
+ - `setNfcTagAlias(serialNumber, alias)` - Give a tag ID a human-friendly name
666
+ - `getNfcTagAlias(serialNumber)` - Get a saved alias for a tag ID
667
+ - `isNfcTag(aliasOrSerialNumber)` - Check whether the most recently read tag matches an alias or ID
664
668
 
665
669
  **Status Variables:**
666
670
  - `window.nfcEnabled` - Boolean indicating if NFC scanning is active
671
+ - `window.nfcStatus` - String describing NFC startup/read status
672
+ - `window.nfcError` - String containing the latest NFC startup/read error
673
+ - `window.nfcTagAliases` - Object mapping tag IDs to aliases
667
674
  - `window.lastNfcMessage` - Object containing the most recently read tag's data
668
675
  - `window.lastNfcSerialNumber` - Serial number string of the most recently read tag
676
+ - `window.lastNfcAlias` - Alias string for the most recently read tag, if one has been set
677
+
678
+ **Two-step workflow:**
679
+
680
+ 1. Open the NFC identifier example, scan each physical tag, type an alias, then download the tag list.
681
+ 2. Paste the generated `setNfcTagAlias()` lines into your sketch and use `isNfcTag()` in conditionals.
669
682
 
670
683
  **User Callback:**
671
684
 
@@ -674,6 +687,7 @@ Define an `nfcRead()` function in your sketch to receive tag data when a tag is
674
687
  ```javascript
675
688
  function nfcRead(message, serialNumber) {
676
689
  // message.serialNumber — tag serial number
690
+ // message.alias — saved alias, or '' if unnamed
677
691
  // message.records — array of NDEF records, each with:
678
692
  // .recordType — 'text', 'url', 'mime', etc.
679
693
  // .data — decoded content (string for text/url, object for JSON, raw for others)
@@ -690,6 +704,11 @@ let tagText = 'No tag scanned yet';
690
704
  function setup() {
691
705
  createCanvas(windowWidth, windowHeight);
692
706
  lockGestures();
707
+
708
+ // Paste IDs from the NFC identifier example.
709
+ setNfcTagAlias('04:85:2a:1b:9f:61:80', 'paintbrush');
710
+ setNfcTagAlias('04:42:18:3c:9f:61:80', 'desk');
711
+
693
712
  enableNfcTap('Tap to enable NFC');
694
713
  }
695
714
 
@@ -698,16 +717,29 @@ function draw() {
698
717
  textAlign(CENTER, CENTER);
699
718
  textSize(20);
700
719
 
701
- if (!window.nfcEnabled) {
702
- text('NFC not active', width / 2, height / 2);
720
+ if (window.nfcEnabled) {
721
+ if (isNfcTag('paintbrush')) {
722
+ background(120, 220, 160);
723
+ text('Paintbrush tag read', width / 2, height / 2);
724
+ } else if (isNfcTag('desk')) {
725
+ background(140, 180, 240);
726
+ text('Desk tag read', width / 2, height / 2);
727
+ } else {
728
+ text(tagText, width / 2, height / 2);
729
+ text('Hold an NFC tag near your phone', width / 2, height / 2 + 40);
730
+ }
703
731
  } else {
704
- text(tagText, width / 2, height / 2);
705
- text('Hold an NFC tag near your phone', width / 2, height / 2 + 40);
732
+ text('NFC not active', width / 2, height / 2);
706
733
  }
707
734
  }
708
735
 
709
736
  function nfcRead(message, serialNumber) {
710
- tagText = 'Tag: ' + serialNumber;
737
+ tagText = 'Tag: ' + (message.alias || serialNumber);
738
+
739
+ if (isNfcTag('paintbrush', serialNumber)) {
740
+ // This runs once when the paintbrush tag is scanned.
741
+ }
742
+
711
743
  for (let record of message.records) {
712
744
  if (record.recordType === 'text' || record.recordType === 'url') {
713
745
  tagText += '\n' + record.data;
@@ -730,6 +762,7 @@ NFC tags contain NDEF records. The most common types are:
730
762
  **Best Practices:**
731
763
  - Always check `window.nfcEnabled` before relying on NFC features
732
764
  - Use the `nfcRead()` callback for real-time tag processing
765
+ - Use `setNfcTagAlias()` and `isNfcTag()` when a sketch should respond to named physical objects
733
766
  - Use `window.lastNfcMessage` in `draw()` for displaying the most recent tag
734
767
  - Test on Android devices with Chrome — NFC is not available on iOS or desktop browsers
735
768
  - Tags must be NDEF-formatted to be read by the Web NFC API
@@ -810,10 +843,10 @@ function draw() {
810
843
 
811
844
  ### PhoneCamera (ML5 Integration)
812
845
 
813
- **Purpose:** Simplified camera access optimized for ML5.js machine learning models (FaceMesh, HandPose, BodyPose, etc.). Handles camera initialization, coordinate mapping, mirroring, and display modes automatically.
846
+ **Purpose:** Simplified camera access optimized for ML5.js machine learning models (FaceMesh, HandPose, BodyPose, ObjectDetection, etc.). Handles camera initialization, coordinate mapping, mirroring, and display modes automatically.
814
847
 
815
848
  **Key Features:**
816
- - **Automatic Coordinate Mapping** - ML5 keypoints automatically mapped to canvas coordinates
849
+ - **Automatic Coordinate Mapping** - ML5 keypoints and bounding boxes automatically mapped to canvas coordinates
817
850
  - **Mirror Support** - Handles front camera mirroring for natural interaction
818
851
  - **Display Modes** - Multiple video sizing options (fitHeight, cover, contain, fixed)
819
852
  - **ML5 Optimized** - Direct integration with ML5 v1.x models
@@ -828,6 +861,8 @@ function draw() {
828
861
  | `cam.onReady(callback)` | Execute code when camera ready | Callback function |
829
862
  | `cam.mapKeypoint(keypoint)` | Map single ML5 keypoint to screen | ML5 keypoint object |
830
863
  | `cam.mapKeypoints(keypoints)` | Map array of ML5 keypoints | Array of ML5 keypoints |
864
+ | `cam.mapBox(box)` | Map single ML5 bounding box to screen | ML5 detection object with x, y, width, height |
865
+ | `cam.mapBoxes(boxes)` | Map array of ML5 bounding boxes | Array of ML5 detection objects |
831
866
 
832
867
  **Properties:**
833
868
 
@@ -861,7 +896,7 @@ function setup() {
861
896
  let options = {
862
897
  maxFaces: 1,
863
898
  refineLandmarks: false,
864
- flipHorizontal: false // cam.mapKeypoint() handles mirroring
899
+ flipped: false // cam.mapKeypoint() handles mirroring
865
900
  };
866
901
 
867
902
  facemesh = ml5.faceMesh(options, modelLoaded);
@@ -914,7 +949,7 @@ function draw() {
914
949
 
915
950
  **Coordinate Mapping:**
916
951
 
917
- The `mapKeypoint()` and `mapKeypoints()` functions automatically handle:
952
+ The `mapKeypoint()`, `mapKeypoints()`, `mapBox()`, and `mapBoxes()` functions automatically handle:
918
953
  - Video-to-canvas scaling
919
954
  - Mirror transformation (for front camera)
920
955
  - Offset positioning (for different display modes)
@@ -930,26 +965,34 @@ let hands = cam.mapKeypoints(hand.keypoints);
930
965
  hands.forEach(point => {
931
966
  circle(point.x, point.y, 5);
932
967
  });
968
+
969
+ // Object detection bounding box
970
+ let mappedObject = cam.mapBox(detection);
971
+ rect(mappedObject.x, mappedObject.y, mappedObject.width, mappedObject.height);
933
972
  ```
934
973
 
935
974
  **ML5 Model Examples:**
936
975
 
937
976
  ```javascript
938
977
  // FaceMesh (468 keypoints)
939
- let options = { maxFaces: 1, refineLandmarks: false, flipHorizontal: false };
978
+ let options = { maxFaces: 1, refineLandmarks: false, flipped: false };
940
979
  facemesh = ml5.faceMesh(options, modelLoaded);
941
980
 
942
981
  // HandPose (21 keypoints per hand)
943
- let options = { maxHands: 2, runtime: 'mediapipe', flipHorizontal: false };
982
+ let options = { maxHands: 2, runtime: 'mediapipe', flipped: false };
944
983
  handpose = ml5.handPose(options, modelLoaded);
945
984
 
946
985
  // BodyPose (33 keypoints with 3D)
947
986
  let options = { modelType: 'MULTIPOSE_LIGHTNING', flipped: false };
948
987
  bodypose = ml5.bodyPose('BlazePose', options, modelLoaded);
988
+
989
+ // ObjectDetection (bounding boxes)
990
+ objectDetector = await ml5.objectDetection('cocossd');
991
+ objectDetector.detectStart(cam.videoElement, gotDetections);
949
992
  ```
950
993
 
951
994
  **Important Notes:**
952
- - Always set `flipHorizontal: false` in ML5 options (PhoneCamera handles mirroring)
995
+ - Always set `flipped: false` in ML5 options when available (PhoneCamera handles mirroring)
953
996
  - Use `cam.videoElement` (native HTML video element) when passing to ML5's `detectStart()`
954
997
  - Check `cam.ready` before using video or drawing keypoints
955
998
  - Call `enableCameraTap()` to handle camera permissions automatically
@@ -1033,9 +1076,11 @@ function setup() {
1033
1076
  }
1034
1077
 
1035
1078
  function draw() {
1036
- if (!window.sensorsEnabled) return;
1037
1079
  background(220);
1038
- circle(width/2 + rotationY * 3, height/2 + rotationX * 3, 50);
1080
+
1081
+ if (window.sensorsEnabled) {
1082
+ circle(width/2 + rotationY * 3, height/2 + rotationX * 3, 50);
1083
+ }
1039
1084
  }
1040
1085
  ```
1041
1086
 
@@ -1095,9 +1140,11 @@ function setup() {
1095
1140
  }
1096
1141
 
1097
1142
  function draw() {
1098
- if (!window.sensorsEnabled) return;
1099
1143
  background(220);
1100
- circle(width/2 + rotationY * 3, height/2 + rotationX * 3, 50);
1144
+
1145
+ if (window.sensorsEnabled) {
1146
+ circle(width/2 + rotationY * 3, height/2 + rotationX * 3, 50);
1147
+ }
1101
1148
  }
1102
1149
  ```
1103
1150