p5-phone 1.5.0 → 1.6.1
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.
- package/README.md +149 -3
- package/dist/p5-phone.js +526 -1
- package/dist/p5-phone.min.js +2 -2
- package/examples/Phone Sensor Examples/microphone/01_mic_level/index.html +1 -1
- package/examples/Phone Sensor Examples/movement/01_orientation_basic/index.html +1 -1
- package/examples/Phone Sensor Examples/movement/02_rotational_velocity/index.html +1 -1
- package/examples/Phone Sensor Examples/movement/03_acceleration/index.html +1 -1
- package/examples/Phone Sensor Examples/sound/01_dual_audio/index.html +1 -1
- package/examples/Phone Sensor Examples/sound/02_volume_touches/index.html +1 -1
- package/examples/Phone Sensor Examples/touch/01_touch_basic/index.html +1 -1
- package/examples/Phone Sensor Examples/touch/02_touch_zones/index.html +1 -1
- package/examples/Phone Sensor Examples/touch/03_touch_count/index.html +1 -1
- package/examples/Phone Sensor Examples/touch/04_touch_distance/index.html +1 -1
- package/examples/Phone Sensor Examples/touch/05_touch_angle/index.html +1 -1
- package/examples/Phone Sensor Examples/vibration/01_haptic_feedback/index.html +1 -1
- package/examples/Phone Sensor Examples - Minimal/microphone/01_mic_level/index.html +1 -1
- package/examples/Phone Sensor Examples - Minimal/movement/01_orientation_basic/index.html +1 -1
- package/examples/Phone Sensor Examples - Minimal/movement/02_rotational_velocity/index.html +1 -1
- package/examples/Phone Sensor Examples - Minimal/movement/03_acceleration/index.html +1 -1
- package/examples/Phone Sensor Examples - Minimal/sound/01_sound_basic/index.html +1 -1
- package/examples/Phone Sensor Examples - Minimal/sound/02_sound_amplitude/index.html +1 -1
- package/examples/Phone Sensor Examples - Minimal/touch/01_touch_basic/index.html +1 -1
- package/examples/Phone Sensor Examples - Minimal/touch/02_touch_zones/index.html +1 -1
- package/examples/Phone Sensor Examples - Minimal/touch/03_touch_count/index.html +1 -1
- package/examples/Phone Sensor Examples - Minimal/touch/04_touch_distance/index.html +1 -1
- package/examples/Phone Sensor Examples - Minimal/touch/05_touch_angle/index.html +1 -1
- package/examples/Phone Sensor Examples - Minimal/vibration/01_haptic_feedback/index.html +18 -0
- package/examples/Phone Sensor Examples - Minimal/vibration/01_haptic_feedback/sketch.js +87 -0
- package/examples/Phone and Gif/collision/index.html +1 -1
- package/examples/Phone and Gif/fetch/index.html +1 -1
- package/examples/Phone and Gif/fly/index.html +1 -1
- package/examples/Phone and Gif/roll/index.html +1 -1
- package/examples/UXcompare/button-vs-movement/index.html +1 -1
- package/examples/UXcompare/button-vs-orientation/index.html +1 -1
- package/examples/UXcompare/button-vs-shake/index.html +1 -1
- package/examples/UXcompare/gyroscope-demo/index.html +1 -1
- package/examples/UXcompare/microphone-demo/index.html +1 -1
- package/examples/UXcompare/slider-vs-angle/index.html +1 -1
- package/examples/UXcompare/slider-vs-distance/index.html +1 -1
- package/examples/UXcompare/slider-vs-microphone/index.html +1 -1
- package/examples/UXcompare/slider-vs-touches/index.html +1 -1
- package/examples/UXcompare/sliders-vs-acceleration/index.html +1 -1
- package/examples/UXcompare/sliders-vs-rotation/index.html +1 -1
- package/examples/blankTemplate/index.html +1 -1
- package/examples/homepage/index.html +24 -5
- package/examples/workArea/01_camera-selector/README.md +119 -0
- package/examples/workArea/01_camera-selector/index.html +28 -0
- package/examples/workArea/01_camera-selector/sketch.js +239 -0
- package/examples/workArea/03_facemesh-nose/index.html +34 -0
- package/examples/workArea/03_facemesh-nose/sketch.js +247 -0
- package/examples/workArea/03_facemesh-nose-preload/index.html +34 -0
- package/examples/workArea/03_facemesh-nose-preload/sketch.js +173 -0
- package/examples/workArea/04_facemesh-FINAL/README.md +85 -0
- package/examples/workArea/04_facemesh-FINAL/index.html +31 -0
- package/examples/workArea/04_facemesh-FINAL/sketch.js +240 -0
- package/examples/workArea/04_facemesh-simplified_temp/README.md +93 -0
- package/examples/workArea/04_facemesh-simplified_temp/index.html +31 -0
- package/examples/workArea/04_facemesh-simplified_temp/sketch.js +259 -0
- package/examples/workArea/05_handpose/extra.js +0 -0
- package/examples/workArea/05_handpose/index.html +31 -0
- package/examples/workArea/05_handpose/sketch.js +362 -0
- package/examples/workArea/05_handpose-preload/index.html +31 -0
- package/examples/workArea/05_handpose-preload/sketch.js +362 -0
- package/examples/workArea/06_bodypose-FINAL/index.html +31 -0
- package/examples/workArea/06_bodypose-FINAL/sketch.js +360 -0
- package/package.json +1 -1
- package/src/p5-phone.js +526 -1
package/README.md
CHANGED
|
@@ -67,10 +67,10 @@ This library simplifies access to the following p5.js mobile sensor and audio co
|
|
|
67
67
|
|
|
68
68
|
```html
|
|
69
69
|
<!-- Minified version (recommended) -->
|
|
70
|
-
<script src="https://cdn.jsdelivr.net/npm/p5-phone@1.
|
|
70
|
+
<script src="https://cdn.jsdelivr.net/npm/p5-phone@1.5.0/dist/p5-phone.min.js"></script>
|
|
71
71
|
|
|
72
72
|
<!-- Development version (larger, with comments) -->
|
|
73
|
-
<!-- <script src="https://cdn.jsdelivr.net/npm/p5-phone@1.
|
|
73
|
+
<!-- <script src="https://cdn.jsdelivr.net/npm/p5-phone@1.5.0/dist/p5-phone.js"></script> -->
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
### Basic Setup
|
|
@@ -98,7 +98,7 @@ This library simplifies access to the following p5.js mobile sensor and audio co
|
|
|
98
98
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.10/p5.min.js"></script>
|
|
99
99
|
|
|
100
100
|
<!-- Load p5-phone library -->
|
|
101
|
-
<script src="https://cdn.jsdelivr.net/npm/p5-phone@1.
|
|
101
|
+
<script src="https://cdn.jsdelivr.net/npm/p5-phone@1.5.0/dist/p5-phone.min.js"></script>
|
|
102
102
|
|
|
103
103
|
</head>
|
|
104
104
|
<body>
|
|
@@ -570,6 +570,152 @@ function gameOver() {
|
|
|
570
570
|
- Don't overuse - vibration can quickly drain battery
|
|
571
571
|
- Test on Android devices as iOS doesn't support vibration
|
|
572
572
|
|
|
573
|
+
### PhoneCamera (ML5 Integration)
|
|
574
|
+
|
|
575
|
+
**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.
|
|
576
|
+
|
|
577
|
+
**Key Features:**
|
|
578
|
+
- **Automatic Coordinate Mapping** - ML5 keypoints automatically mapped to canvas coordinates
|
|
579
|
+
- **Mirror Support** - Handles front camera mirroring for natural interaction
|
|
580
|
+
- **Display Modes** - Multiple video sizing options (fitHeight, cover, contain, fixed)
|
|
581
|
+
- **ML5 Optimized** - Direct integration with ML5 v1.x models
|
|
582
|
+
- **Auto-initialization** - Camera starts automatically when permissions are granted
|
|
583
|
+
|
|
584
|
+
**Commands:**
|
|
585
|
+
|
|
586
|
+
| Function | Purpose | Parameters |
|
|
587
|
+
|----------|---------|------------|
|
|
588
|
+
| `createPhoneCamera(active, mirror, mode)` | Create new camera instance | active: 'user' or 'environment'<br>mirror: true/false<br>mode: 'fitHeight', 'cover', 'contain', 'fixed' |
|
|
589
|
+
| `enableCameraTap(message)` | Tap to enable camera | Optional message string |
|
|
590
|
+
| `cam.onReady(callback)` | Execute code when camera ready | Callback function |
|
|
591
|
+
| `cam.mapKeypoint(keypoint)` | Map single ML5 keypoint to screen | ML5 keypoint object |
|
|
592
|
+
| `cam.mapKeypoints(keypoints)` | Map array of ML5 keypoints | Array of ML5 keypoints |
|
|
593
|
+
|
|
594
|
+
**Properties:**
|
|
595
|
+
|
|
596
|
+
| Property | Description | Type |
|
|
597
|
+
|----------|-------------|------|
|
|
598
|
+
| `cam.ready` | Camera initialization status | Boolean |
|
|
599
|
+
| `cam.video` | p5.js video element | p5.Element |
|
|
600
|
+
| `cam.active` | Current camera ('user'/'environment') | String |
|
|
601
|
+
| `cam.mirror` | Mirror state | Boolean |
|
|
602
|
+
| `cam.mode` | Display mode | String |
|
|
603
|
+
| `cam.width` | Video width | Number |
|
|
604
|
+
| `cam.height` | Video height | Number |
|
|
605
|
+
|
|
606
|
+
**Basic Setup:**
|
|
607
|
+
```javascript
|
|
608
|
+
let cam;
|
|
609
|
+
let facemesh;
|
|
610
|
+
let faces = [];
|
|
611
|
+
|
|
612
|
+
function setup() {
|
|
613
|
+
createCanvas(windowWidth, windowHeight);
|
|
614
|
+
|
|
615
|
+
// Create camera: front camera, mirrored, fit to canvas height
|
|
616
|
+
cam = createPhoneCamera('user', true, 'fitHeight');
|
|
617
|
+
|
|
618
|
+
// Enable camera (auto-starts if permission granted)
|
|
619
|
+
enableCameraTap();
|
|
620
|
+
|
|
621
|
+
// Start ML5 when camera is ready
|
|
622
|
+
cam.onReady(() => {
|
|
623
|
+
let options = {
|
|
624
|
+
maxFaces: 1,
|
|
625
|
+
refineLandmarks: false,
|
|
626
|
+
flipHorizontal: false // cam.mapKeypoint() handles mirroring
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
facemesh = ml5.faceMesh(options, modelLoaded);
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
function modelLoaded() {
|
|
634
|
+
// Start detection - use cam.videoElement for ML5
|
|
635
|
+
facemesh.detectStart(cam.videoElement, (results) => {
|
|
636
|
+
faces = results;
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
function draw() {
|
|
641
|
+
background(220);
|
|
642
|
+
|
|
643
|
+
// Draw camera feed
|
|
644
|
+
if (cam.ready) {
|
|
645
|
+
image(cam, 0, 0); // PhoneCamera handles positioning automatically
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// Draw tracked face keypoints
|
|
649
|
+
if (faces.length > 0) {
|
|
650
|
+
let face = faces[0];
|
|
651
|
+
|
|
652
|
+
// Map nose tip keypoint (index 1) to screen coordinates
|
|
653
|
+
let nose = cam.mapKeypoint(face.keypoints[1]);
|
|
654
|
+
|
|
655
|
+
// Use coordinates for interaction
|
|
656
|
+
fill(255, 0, 0);
|
|
657
|
+
circle(nose.x, nose.y, 30);
|
|
658
|
+
|
|
659
|
+
// Map all keypoints at once
|
|
660
|
+
let allPoints = cam.mapKeypoints(face.keypoints);
|
|
661
|
+
for (let point of allPoints) {
|
|
662
|
+
circle(point.x, point.y, 3);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
**Display Modes:**
|
|
669
|
+
|
|
670
|
+
| Mode | Behavior |
|
|
671
|
+
|------|----------|
|
|
672
|
+
| `'fitHeight'` | Scale video to canvas height (default, recommended) |
|
|
673
|
+
| `'cover'` | Fill entire canvas (may crop video) |
|
|
674
|
+
| `'contain'` | Fit entire video in canvas (may show letterboxing) |
|
|
675
|
+
| `'fixed'` | Fixed size (set with `cam.fixedWidth`, `cam.fixedHeight`) |
|
|
676
|
+
|
|
677
|
+
**Coordinate Mapping:**
|
|
678
|
+
|
|
679
|
+
The `mapKeypoint()` and `mapKeypoints()` functions automatically handle:
|
|
680
|
+
- Video-to-canvas scaling
|
|
681
|
+
- Mirror transformation (for front camera)
|
|
682
|
+
- Offset positioning (for different display modes)
|
|
683
|
+
- 3D coordinates (preserves z-depth from BlazePose)
|
|
684
|
+
|
|
685
|
+
```javascript
|
|
686
|
+
// Single keypoint
|
|
687
|
+
let nose = cam.mapKeypoint(face.keypoints[1]);
|
|
688
|
+
console.log(nose.x, nose.y, nose.z); // Screen coordinates + depth
|
|
689
|
+
|
|
690
|
+
// Multiple keypoints
|
|
691
|
+
let hands = cam.mapKeypoints(hand.keypoints);
|
|
692
|
+
hands.forEach(point => {
|
|
693
|
+
circle(point.x, point.y, 5);
|
|
694
|
+
});
|
|
695
|
+
```
|
|
696
|
+
|
|
697
|
+
**ML5 Model Examples:**
|
|
698
|
+
|
|
699
|
+
```javascript
|
|
700
|
+
// FaceMesh (468 keypoints)
|
|
701
|
+
let options = { maxFaces: 1, refineLandmarks: false, flipHorizontal: false };
|
|
702
|
+
facemesh = ml5.faceMesh(options, modelLoaded);
|
|
703
|
+
|
|
704
|
+
// HandPose (21 keypoints per hand)
|
|
705
|
+
let options = { maxHands: 2, runtime: 'mediapipe', flipHorizontal: false };
|
|
706
|
+
handpose = ml5.handPose(options, modelLoaded);
|
|
707
|
+
|
|
708
|
+
// BodyPose (33 keypoints with 3D)
|
|
709
|
+
let options = { modelType: 'MULTIPOSE_LIGHTNING', flipped: false };
|
|
710
|
+
bodypose = ml5.bodyPose('BlazePose', options, modelLoaded);
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
**Important Notes:**
|
|
714
|
+
- Always set `flipHorizontal: false` in ML5 options (PhoneCamera handles mirroring)
|
|
715
|
+
- Use `cam.videoElement` (native HTML video element) when passing to ML5's `detectStart()`
|
|
716
|
+
- Check `cam.ready` before using video or drawing keypoints
|
|
717
|
+
- Call `enableCameraTap()` to handle camera permissions automatically
|
|
718
|
+
|
|
573
719
|
### Debug System
|
|
574
720
|
|
|
575
721
|
**Purpose:** Essential on-screen debugging system for mobile development where traditional browser dev tools aren't accessible. Provides automatic error catching, timestamped logging, and color-coded messages.
|