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.
- package/LICENSE +21 -0
- package/README.md +509 -0
- package/dist/p5-phone.js +1062 -0
- package/dist/p5-phone.min.js +10 -0
- package/examples/Phone Sensor Examples/microphone/01_mic_level/index.html +19 -0
- package/examples/Phone Sensor Examples/microphone/01_mic_level/sketch.js +117 -0
- package/examples/Phone Sensor Examples/movement/01_orientation_basic/index.html +28 -0
- package/examples/Phone Sensor Examples/movement/01_orientation_basic/sketch.js +123 -0
- package/examples/Phone Sensor Examples/movement/02_rotational_velocity/index.html +28 -0
- package/examples/Phone Sensor Examples/movement/02_rotational_velocity/sketch.js +144 -0
- package/examples/Phone Sensor Examples/movement/03_acceleration/index.html +28 -0
- package/examples/Phone Sensor Examples/movement/03_acceleration/sketch.js +87 -0
- package/examples/Phone Sensor Examples/sound/01_dual_audio/index.html +31 -0
- package/examples/Phone Sensor Examples/sound/01_dual_audio/sketch.js +225 -0
- package/examples/Phone Sensor Examples/sound/01_dual_audio/tracks/audio1.mp3 +0 -0
- package/examples/Phone Sensor Examples/sound/01_dual_audio/tracks/audio2.mp3 +0 -0
- package/examples/Phone Sensor Examples/sound/02_volume_touches/index.html +31 -0
- package/examples/Phone Sensor Examples/sound/02_volume_touches/sketch.js +269 -0
- package/examples/Phone Sensor Examples/sound/02_volume_touches/tracks/audio1.mp3 +0 -0
- package/examples/Phone Sensor Examples/touch/01_touch_basic/index.html +28 -0
- package/examples/Phone Sensor Examples/touch/01_touch_basic/sketch.js +94 -0
- package/examples/Phone Sensor Examples/touch/02_touch_zones/index.html +28 -0
- package/examples/Phone Sensor Examples/touch/02_touch_zones/sketch.js +220 -0
- package/examples/Phone Sensor Examples/touch/03_touch_count/index.html +28 -0
- package/examples/Phone Sensor Examples/touch/03_touch_count/sketch.js +93 -0
- package/examples/Phone Sensor Examples/touch/04_touch_distance/index.html +28 -0
- package/examples/Phone Sensor Examples/touch/04_touch_distance/sketch.js +120 -0
- package/examples/Phone Sensor Examples/touch/05_touch_angle/index.html +28 -0
- package/examples/Phone Sensor Examples/touch/05_touch_angle/sketch.js +117 -0
- package/examples/Phone Sensor Examples - Minimal/microphone/01_mic_level/index.html +19 -0
- package/examples/Phone Sensor Examples - Minimal/microphone/01_mic_level/sketch.js +72 -0
- package/examples/Phone Sensor Examples - Minimal/movement/01_orientation_basic/index.html +18 -0
- package/examples/Phone Sensor Examples - Minimal/movement/01_orientation_basic/sketch.js +51 -0
- package/examples/Phone Sensor Examples - Minimal/movement/02_rotational_velocity/index.html +18 -0
- package/examples/Phone Sensor Examples - Minimal/movement/02_rotational_velocity/sketch.js +70 -0
- package/examples/Phone Sensor Examples - Minimal/movement/03_acceleration/index.html +18 -0
- package/examples/Phone Sensor Examples - Minimal/movement/03_acceleration/sketch.js +83 -0
- package/examples/Phone Sensor Examples - Minimal/sound/01_sound_basic/index.html +19 -0
- package/examples/Phone Sensor Examples - Minimal/sound/01_sound_basic/sketch.js +96 -0
- package/examples/Phone Sensor Examples - Minimal/sound/01_sound_basic/tracks/audio1.mp3 +0 -0
- package/examples/Phone Sensor Examples - Minimal/sound/02_sound_amplitude/index.html +19 -0
- package/examples/Phone Sensor Examples - Minimal/sound/02_sound_amplitude/sketch.js +118 -0
- package/examples/Phone Sensor Examples - Minimal/sound/02_sound_amplitude/tracks/audio1.mp3 +0 -0
- package/examples/Phone Sensor Examples - Minimal/touch/01_touch_basic/index.html +18 -0
- package/examples/Phone Sensor Examples - Minimal/touch/01_touch_basic/sketch.js +58 -0
- package/examples/Phone Sensor Examples - Minimal/touch/02_touch_zones/index.html +18 -0
- package/examples/Phone Sensor Examples - Minimal/touch/02_touch_zones/sketch.js +78 -0
- package/examples/Phone Sensor Examples - Minimal/touch/03_touch_count/index.html +18 -0
- package/examples/Phone Sensor Examples - Minimal/touch/03_touch_count/sketch.js +64 -0
- package/examples/Phone Sensor Examples - Minimal/touch/04_touch_distance/index.html +18 -0
- package/examples/Phone Sensor Examples - Minimal/touch/04_touch_distance/sketch.js +69 -0
- package/examples/Phone Sensor Examples - Minimal/touch/05_touch_angle/index.html +18 -0
- package/examples/Phone Sensor Examples - Minimal/touch/05_touch_angle/sketch.js +85 -0
- package/examples/Phone and Gif/collision/README.md +31 -0
- Gif/collision/gifs/spaceSuit2.png +0 -0
- package/examples/Phone and Gif/collision/index.html +19 -0
- package/examples/Phone and Gif/collision/sketch.js +226 -0
- Gif/fetch/gifs/corgiswimflip.gif +0 -0
- package/examples/Phone and Gif/fetch/index.html +18 -0
- package/examples/Phone and Gif/fetch/sketch.js +139 -0
- Gif/fly/gifs/comparison.gif +0 -0
- package/examples/Phone and Gif/fly/index.html +18 -0
- package/examples/Phone and Gif/fly/sketch.js +103 -0
- Gif/roll/gifs/how-penciles-are-made.gif +0 -0
- package/examples/Phone and Gif/roll/index.html +18 -0
- package/examples/Phone and Gif/roll/sketch.js +121 -0
- package/examples/UXcompare/button-vs-movement/index.html +45 -0
- package/examples/UXcompare/button-vs-movement/sketch.js +355 -0
- package/examples/UXcompare/button-vs-orientation/index.html +25 -0
- package/examples/UXcompare/button-vs-orientation/sketch.js +317 -0
- package/examples/UXcompare/button-vs-shake/index.html +45 -0
- package/examples/UXcompare/button-vs-shake/sketch.js +320 -0
- package/examples/UXcompare/gyroscope-demo/index.html +78 -0
- package/examples/UXcompare/gyroscope-demo/sketch.js +166 -0
- package/examples/UXcompare/index.html +419 -0
- package/examples/UXcompare/microphone-demo/index.html +79 -0
- package/examples/UXcompare/microphone-demo/sketch.js +210 -0
- package/examples/UXcompare/slider-vs-angle/index.html +25 -0
- package/examples/UXcompare/slider-vs-angle/sketch.js +429 -0
- package/examples/UXcompare/slider-vs-distance/index.html +25 -0
- package/examples/UXcompare/slider-vs-distance/sketch.js +401 -0
- package/examples/UXcompare/slider-vs-microphone/index.html +26 -0
- package/examples/UXcompare/slider-vs-microphone/sketch.js +336 -0
- package/examples/UXcompare/slider-vs-touches/index.html +25 -0
- package/examples/UXcompare/slider-vs-touches/sketch.js +376 -0
- package/examples/UXcompare/sliders-vs-acceleration/index.html +25 -0
- package/examples/UXcompare/sliders-vs-acceleration/sketch.js +361 -0
- package/examples/UXcompare/sliders-vs-rotation/index.html +25 -0
- package/examples/UXcompare/sliders-vs-rotation/sketch.js +375 -0
- package/examples/blankTemplate/index.html +31 -0
- package/examples/blankTemplate/sketch.js +55 -0
- package/examples/homepage/index.html +506 -0
- package/package.json +73 -0
- package/src/p5-phone.js +1062 -0
- package/src/permissionMic.js +240 -0
- package/src/permissionsGesture.js +213 -0
- package/src/permissionsGyro.js +246 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// MINIMAL VERSION - Mic Level
|
|
2
|
+
// No visual feedback - data displayed in debug panel only
|
|
3
|
+
// Demonstrates: Reading microphone input level with threshold detection
|
|
4
|
+
|
|
5
|
+
// Global variables for microphone
|
|
6
|
+
let mic;
|
|
7
|
+
let micLevel = 0;
|
|
8
|
+
let micMultiplier = 3; // Increase sensitivity
|
|
9
|
+
let threshold = 0.3; // Threshold for loud sound detection
|
|
10
|
+
|
|
11
|
+
function setup()
|
|
12
|
+
{
|
|
13
|
+
createCanvas(windowWidth, windowHeight);
|
|
14
|
+
|
|
15
|
+
// Show debug panel FIRST
|
|
16
|
+
showDebug();
|
|
17
|
+
|
|
18
|
+
// Enable microphone with tap permission
|
|
19
|
+
enableMicTap();
|
|
20
|
+
|
|
21
|
+
// Lock mobile gestures
|
|
22
|
+
lockGestures();
|
|
23
|
+
|
|
24
|
+
debug("Mic Level - Minimal Version");
|
|
25
|
+
debug("Tap to enable microphone");
|
|
26
|
+
debug("Threshold: " + threshold);
|
|
27
|
+
debug("Waiting for microphone...");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function draw()
|
|
31
|
+
{
|
|
32
|
+
// No visual feedback in minimal version
|
|
33
|
+
|
|
34
|
+
// Check if microphone is enabled
|
|
35
|
+
if (mic && mic.enabled)
|
|
36
|
+
{
|
|
37
|
+
// Get current microphone level (0.0 to 1.0)
|
|
38
|
+
micLevel = mic.getLevel() * micMultiplier;
|
|
39
|
+
|
|
40
|
+
// Constrain to 0-1 range
|
|
41
|
+
micLevel = constrain(micLevel, 0, 1);
|
|
42
|
+
|
|
43
|
+
// Output to debug panel
|
|
44
|
+
debug("--- Microphone Level ---");
|
|
45
|
+
debug("Raw Level: " + nf(micLevel, 1, 3));
|
|
46
|
+
debug("Percentage: " + int(micLevel * 100) + "%");
|
|
47
|
+
|
|
48
|
+
// Check against threshold
|
|
49
|
+
if (micLevel > threshold)
|
|
50
|
+
{
|
|
51
|
+
debug("STATUS: LOUD! (Above threshold)");
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
{
|
|
55
|
+
debug("STATUS: Quiet (Below threshold)");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Add visual bar representation using text
|
|
59
|
+
let barLength = int(micLevel * 20);
|
|
60
|
+
let bar = "";
|
|
61
|
+
for (let i = 0; i < barLength; i++)
|
|
62
|
+
{
|
|
63
|
+
bar = bar + "▮";
|
|
64
|
+
}
|
|
65
|
+
debug("Level: " + bar);
|
|
66
|
+
}
|
|
67
|
+
else
|
|
68
|
+
{
|
|
69
|
+
debug("Waiting for microphone permissions...");
|
|
70
|
+
debug("Tap the screen to enable microphone");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>P5.js Mobile - Orientation Basic (Minimal)</title>
|
|
5
|
+
<script src="https://cdn.jsdelivr.net/npm/p5@1.11.0/lib/p5.min.js"></script>
|
|
6
|
+
<script src="https://cdn.jsdelivr.net/npm/mobile-p5-permissions@1.4.4/dist/p5.mobile-permissions.min.js"></script>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
}
|
|
13
|
+
</style>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<script src="sketch.js"></script>
|
|
17
|
+
</body>
|
|
18
|
+
</html>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// MINIMAL VERSION - Orientation Basic
|
|
2
|
+
// No visual feedback - data displayed in debug panel only
|
|
3
|
+
// Demonstrates: Reading device orientation (rotationX, rotationY, rotationZ)
|
|
4
|
+
|
|
5
|
+
function setup()
|
|
6
|
+
{
|
|
7
|
+
createCanvas(windowWidth, windowHeight);
|
|
8
|
+
|
|
9
|
+
// Show debug panel FIRST
|
|
10
|
+
showDebug();
|
|
11
|
+
|
|
12
|
+
// Enable motion sensors with tap permission (iOS)
|
|
13
|
+
enableGyroTap();
|
|
14
|
+
|
|
15
|
+
// Lock mobile gestures
|
|
16
|
+
lockGestures();
|
|
17
|
+
|
|
18
|
+
// Set to show in Degrees
|
|
19
|
+
angleMode(DEGREES);
|
|
20
|
+
|
|
21
|
+
debug("Orientation Basic - Minimal Version");
|
|
22
|
+
debug("Tilt your device to see orientation values");
|
|
23
|
+
debug("Waiting for sensor data...");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function draw()
|
|
27
|
+
{
|
|
28
|
+
// No visual feedback in minimal version
|
|
29
|
+
|
|
30
|
+
// Check if motion sensors are enabled
|
|
31
|
+
if (window.sensorsEnabled)
|
|
32
|
+
{
|
|
33
|
+
// Get current orientation values
|
|
34
|
+
let rx = rotationX;
|
|
35
|
+
let ry = rotationY;
|
|
36
|
+
let rz = rotationZ;
|
|
37
|
+
|
|
38
|
+
// Output to debug panel
|
|
39
|
+
debug("--- Device Orientation ---");
|
|
40
|
+
debug("Rotation X (Tilt Forward/Back): " + int(rx) + "°");
|
|
41
|
+
debug("Rotation Y (Tilt Left/Right): " + int(ry) + "°");
|
|
42
|
+
debug("Rotation Z (Turn/Compass): " + int(rz) + "°");
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
{
|
|
48
|
+
debug("Waiting for sensor permissions...");
|
|
49
|
+
debug("Tap the screen to enable sensors");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>P5.js Mobile - Rotational Velocity (Minimal)</title>
|
|
5
|
+
<script src="https://cdn.jsdelivr.net/npm/p5@1.11.0/lib/p5.min.js"></script>
|
|
6
|
+
<script src="https://cdn.jsdelivr.net/npm/mobile-p5-permissions@1.4.4/dist/p5.mobile-permissions.min.js"></script>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
}
|
|
13
|
+
</style>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<script src="sketch.js"></script>
|
|
17
|
+
</body>
|
|
18
|
+
</html>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// MINIMAL VERSION - Rotational Velocity
|
|
2
|
+
// No visual feedback - data displayed in debug panel only
|
|
3
|
+
// Demonstrates: Calculating velocity of rotation by comparing current and previous rotation values
|
|
4
|
+
|
|
5
|
+
// Global variables for tracking previous rotation
|
|
6
|
+
let prevRotationX = 0;
|
|
7
|
+
let prevRotationY = 0;
|
|
8
|
+
let prevRotationZ = 0;
|
|
9
|
+
|
|
10
|
+
function setup()
|
|
11
|
+
{
|
|
12
|
+
createCanvas(windowWidth, windowHeight);
|
|
13
|
+
|
|
14
|
+
// Show debug panel FIRST
|
|
15
|
+
showDebug();
|
|
16
|
+
|
|
17
|
+
// Enable motion sensors with tap permission (iOS)
|
|
18
|
+
enableGyroTap();
|
|
19
|
+
|
|
20
|
+
// Lock mobile gestures
|
|
21
|
+
lockGestures();
|
|
22
|
+
|
|
23
|
+
// Set to show in Degrees
|
|
24
|
+
angleMode(DEGREES);
|
|
25
|
+
|
|
26
|
+
debug("Rotational Velocity - Minimal Version");
|
|
27
|
+
debug("Move your device quickly to see velocity");
|
|
28
|
+
debug("Waiting for sensor data...");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function draw()
|
|
32
|
+
{
|
|
33
|
+
// No visual feedback in minimal version
|
|
34
|
+
|
|
35
|
+
// Check if motion sensors are enabled
|
|
36
|
+
if (window.sensorsEnabled)
|
|
37
|
+
{
|
|
38
|
+
// Get current rotation values
|
|
39
|
+
let currentX = rotationX;
|
|
40
|
+
let currentY = rotationY;
|
|
41
|
+
let currentZ = rotationZ;
|
|
42
|
+
|
|
43
|
+
// Calculate velocity (change since last frame)
|
|
44
|
+
let velocityX = currentX - prevRotationX;
|
|
45
|
+
let velocityY = currentY - prevRotationY;
|
|
46
|
+
let velocityZ = currentZ - prevRotationZ;
|
|
47
|
+
|
|
48
|
+
// Calculate total velocity magnitude
|
|
49
|
+
let totalVelocity = sqrt(velocityX * velocityX + velocityY * velocityY + velocityZ * velocityZ);
|
|
50
|
+
|
|
51
|
+
// Output to debug panel
|
|
52
|
+
debug("--- Rotational Velocity ---");
|
|
53
|
+
debug("Velocity X: " + nf(velocityX, 1, 2) + "°/frame");
|
|
54
|
+
debug("Velocity Y: " + nf(velocityY, 1, 2) + "°/frame");
|
|
55
|
+
debug("Velocity Z: " + nf(velocityZ, 1, 2) + "°/frame");
|
|
56
|
+
debug("Total Velocity: " + nf(totalVelocity, 1, 2) + "°/frame");
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
// Store current rotation for next frame
|
|
61
|
+
prevRotationX = currentX;
|
|
62
|
+
prevRotationY = currentY;
|
|
63
|
+
prevRotationZ = currentZ;
|
|
64
|
+
}
|
|
65
|
+
else
|
|
66
|
+
{
|
|
67
|
+
debug("Waiting for sensor permissions...");
|
|
68
|
+
debug("Tap the screen to enable sensors");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>P5.js Mobile - Acceleration (Minimal)</title>
|
|
5
|
+
<script src="https://cdn.jsdelivr.net/npm/p5@1.11.0/lib/p5.min.js"></script>
|
|
6
|
+
<script src="https://cdn.jsdelivr.net/npm/mobile-p5-permissions@1.4.4/dist/p5.mobile-permissions.min.js"></script>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
}
|
|
13
|
+
</style>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<script src="sketch.js"></script>
|
|
17
|
+
</body>
|
|
18
|
+
</html>
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// MINIMAL VERSION - Acceleration
|
|
2
|
+
// No visual feedback - data displayed in debug panel only
|
|
3
|
+
// Demonstrates: Reading device acceleration (accelerationX, accelerationY, accelerationZ)
|
|
4
|
+
|
|
5
|
+
function setup()
|
|
6
|
+
{
|
|
7
|
+
createCanvas(windowWidth, windowHeight);
|
|
8
|
+
|
|
9
|
+
// Show debug panel FIRST
|
|
10
|
+
showDebug();
|
|
11
|
+
|
|
12
|
+
// Enable motion sensors with tap permission (iOS)
|
|
13
|
+
enableGyroTap();
|
|
14
|
+
|
|
15
|
+
// Lock mobile gestures
|
|
16
|
+
lockGestures();
|
|
17
|
+
|
|
18
|
+
debug("Acceleration - Minimal Version");
|
|
19
|
+
debug("Move your device to see acceleration values");
|
|
20
|
+
debug("Waiting for sensor data...");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function draw()
|
|
24
|
+
{
|
|
25
|
+
// No visual feedback in minimal version
|
|
26
|
+
|
|
27
|
+
// Check if motion sensors are enabled
|
|
28
|
+
if (window.sensorsEnabled)
|
|
29
|
+
{
|
|
30
|
+
// Get current acceleration values
|
|
31
|
+
let ax = accelerationX;
|
|
32
|
+
let ay = accelerationY;
|
|
33
|
+
let az = accelerationZ;
|
|
34
|
+
|
|
35
|
+
// Calculate total acceleration magnitude
|
|
36
|
+
let totalAccel = sqrt(ax * ax + ay * ay + az * az);
|
|
37
|
+
|
|
38
|
+
// Output to debug panel
|
|
39
|
+
debug("--- Device Acceleration ---");
|
|
40
|
+
debug("Acceleration X: " + nf(ax, 1, 2));
|
|
41
|
+
debug("Acceleration Y: " + nf(ay, 1, 2));
|
|
42
|
+
debug("Acceleration Z: " + nf(az, 1, 2));
|
|
43
|
+
debug("Total Magnitude: " + nf(totalAccel, 1, 2));
|
|
44
|
+
|
|
45
|
+
// Add movement indicators
|
|
46
|
+
if (totalAccel > 5)
|
|
47
|
+
{
|
|
48
|
+
debug("MOVING FAST!");
|
|
49
|
+
}
|
|
50
|
+
else if (totalAccel > 2)
|
|
51
|
+
{
|
|
52
|
+
debug("Moving moderately");
|
|
53
|
+
}
|
|
54
|
+
else if (totalAccel > 0.5)
|
|
55
|
+
{
|
|
56
|
+
debug("Gentle movement");
|
|
57
|
+
}
|
|
58
|
+
else
|
|
59
|
+
{
|
|
60
|
+
debug("Still or very slow");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Show dominant direction
|
|
64
|
+
let maxVal = max(abs(ax), abs(ay), abs(az));
|
|
65
|
+
if (maxVal === abs(ax))
|
|
66
|
+
{
|
|
67
|
+
debug("Dominant axis: X " + (ax > 0 ? "(Right)" : "(Left)"));
|
|
68
|
+
}
|
|
69
|
+
else if (maxVal === abs(ay))
|
|
70
|
+
{
|
|
71
|
+
debug("Dominant axis: Y " + (ay > 0 ? "(Forward)" : "(Backward)"));
|
|
72
|
+
}
|
|
73
|
+
else
|
|
74
|
+
{
|
|
75
|
+
debug("Dominant axis: Z " + (az > 0 ? "(Up)" : "(Down)"));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else
|
|
79
|
+
{
|
|
80
|
+
debug("Waiting for sensor permissions...");
|
|
81
|
+
debug("Tap the screen to enable sensors");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>P5.js Mobile - Sound Basic (Minimal)</title>
|
|
5
|
+
<script src="https://cdn.jsdelivr.net/npm/p5@1.11.0/lib/p5.min.js"></script>
|
|
6
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.0/addons/p5.sound.min.js"></script>
|
|
7
|
+
<script src="https://cdn.jsdelivr.net/npm/mobile-p5-permissions@1.4.4/dist/p5.mobile-permissions.min.js"></script>
|
|
8
|
+
<style>
|
|
9
|
+
body {
|
|
10
|
+
margin: 0;
|
|
11
|
+
padding: 0;
|
|
12
|
+
overflow: hidden;
|
|
13
|
+
}
|
|
14
|
+
</style>
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<script src="sketch.js"></script>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// MINIMAL VERSION - Sound Basic
|
|
2
|
+
// No visual feedback - data displayed in debug panel only
|
|
3
|
+
// Demonstrates: Loading and playing audio, touch to play/pause control
|
|
4
|
+
|
|
5
|
+
// Global variables for audio
|
|
6
|
+
let audioTrack;
|
|
7
|
+
let isPlaying = false;
|
|
8
|
+
let playCount = 0;
|
|
9
|
+
|
|
10
|
+
function preload()
|
|
11
|
+
{
|
|
12
|
+
// Load audio file
|
|
13
|
+
audioTrack = loadSound('tracks/audio1.mp3');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function setup()
|
|
17
|
+
{
|
|
18
|
+
createCanvas(windowWidth, windowHeight);
|
|
19
|
+
|
|
20
|
+
// Show debug panel FIRST
|
|
21
|
+
showDebug();
|
|
22
|
+
|
|
23
|
+
// Enable sound with tap permission
|
|
24
|
+
enableSoundTap();
|
|
25
|
+
|
|
26
|
+
// Lock mobile gestures
|
|
27
|
+
lockGestures();
|
|
28
|
+
|
|
29
|
+
// Set audio to loop
|
|
30
|
+
audioTrack.loop();
|
|
31
|
+
audioTrack.pause();
|
|
32
|
+
|
|
33
|
+
debug("Sound Basic - Minimal Version");
|
|
34
|
+
debug("Touch to play/pause audio");
|
|
35
|
+
debug("Waiting for audio permissions...");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function draw()
|
|
39
|
+
{
|
|
40
|
+
// Check if sound system is enabled
|
|
41
|
+
if (window.soundEnabled)
|
|
42
|
+
{
|
|
43
|
+
// Output audio state to debug panel
|
|
44
|
+
debug("--- Audio Status ---");
|
|
45
|
+
debug("Is Playing: " + audioTrack.isPlaying());
|
|
46
|
+
debug("Play Count: " + playCount);
|
|
47
|
+
debug("Current Time: " + audioTrack.currentTime().toFixed(2) + "s");
|
|
48
|
+
debug("Duration: " + audioTrack.duration().toFixed(2) + "s");
|
|
49
|
+
debug("Volume: " + int(audioTrack.getVolume() * 100) + "%");
|
|
50
|
+
|
|
51
|
+
if (audioTrack.isPlaying())
|
|
52
|
+
{
|
|
53
|
+
debug("STATUS: PLAYING ▶");
|
|
54
|
+
}
|
|
55
|
+
else
|
|
56
|
+
{
|
|
57
|
+
debug("STATUS: PAUSED ⏸");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
debug("Touch anywhere to toggle play/pause");
|
|
61
|
+
}
|
|
62
|
+
else
|
|
63
|
+
{
|
|
64
|
+
debug("Waiting for audio permissions...");
|
|
65
|
+
debug("Touch the screen to enable audio");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Toggle play/pause on touch
|
|
70
|
+
function touchStarted()
|
|
71
|
+
{
|
|
72
|
+
if (window.soundEnabled)
|
|
73
|
+
{
|
|
74
|
+
if (audioTrack.isPlaying())
|
|
75
|
+
{
|
|
76
|
+
audioTrack.pause();
|
|
77
|
+
isPlaying = false;
|
|
78
|
+
debug("--- Touch: PAUSED ---");
|
|
79
|
+
}
|
|
80
|
+
else
|
|
81
|
+
{
|
|
82
|
+
audioTrack.play();
|
|
83
|
+
isPlaying = true;
|
|
84
|
+
playCount = playCount + 1;
|
|
85
|
+
debug("--- Touch: PLAYING ---");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return false; // Prevents default behavior
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Prevent default touch behavior
|
|
93
|
+
function touchEnded()
|
|
94
|
+
{
|
|
95
|
+
return false; // Prevents default behavior
|
|
96
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>P5.js Mobile - Sound Amplitude (Minimal)</title>
|
|
5
|
+
<script src="https://cdn.jsdelivr.net/npm/p5@1.11.0/lib/p5.min.js"></script>
|
|
6
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.0/addons/p5.sound.min.js"></script>
|
|
7
|
+
<script src="https://cdn.jsdelivr.net/npm/mobile-p5-permissions@1.4.4/dist/p5.mobile-permissions.min.js"></script>
|
|
8
|
+
<style>
|
|
9
|
+
body {
|
|
10
|
+
margin: 0;
|
|
11
|
+
padding: 0;
|
|
12
|
+
overflow: hidden;
|
|
13
|
+
}
|
|
14
|
+
</style>
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<script src="sketch.js"></script>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// MINIMAL VERSION - Sound Amplitude
|
|
2
|
+
// No visual feedback - data displayed in debug panel only
|
|
3
|
+
// Demonstrates: Reading audio amplitude levels in real-time with p5.Amplitude
|
|
4
|
+
|
|
5
|
+
// Global variables for audio
|
|
6
|
+
let audioTrack;
|
|
7
|
+
let amplitude;
|
|
8
|
+
let currentLevel = 0;
|
|
9
|
+
let peakLevel = 0;
|
|
10
|
+
let threshold = 0.2; // Threshold for "loud" detection
|
|
11
|
+
|
|
12
|
+
function preload()
|
|
13
|
+
{
|
|
14
|
+
// Load audio file
|
|
15
|
+
audioTrack = loadSound('tracks/audio1.mp3');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function setup()
|
|
19
|
+
{
|
|
20
|
+
createCanvas(windowWidth, windowHeight);
|
|
21
|
+
|
|
22
|
+
// Show debug panel FIRST
|
|
23
|
+
showDebug();
|
|
24
|
+
|
|
25
|
+
// Enable sound with tap permission
|
|
26
|
+
enableSoundTap();
|
|
27
|
+
|
|
28
|
+
// Lock mobile gestures
|
|
29
|
+
lockGestures();
|
|
30
|
+
|
|
31
|
+
// Create amplitude analyzer
|
|
32
|
+
amplitude = new p5.Amplitude();
|
|
33
|
+
amplitude.setInput(audioTrack);
|
|
34
|
+
|
|
35
|
+
// Set audio to loop
|
|
36
|
+
audioTrack.loop();
|
|
37
|
+
audioTrack.pause();
|
|
38
|
+
|
|
39
|
+
debug("Sound Amplitude - Minimal Version");
|
|
40
|
+
debug("Touch & hold to play and analyze audio");
|
|
41
|
+
debug("Amplitude Threshold: " + threshold);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function draw()
|
|
45
|
+
{
|
|
46
|
+
// Check if sound system is enabled
|
|
47
|
+
if (window.soundEnabled)
|
|
48
|
+
{
|
|
49
|
+
// Get current amplitude level
|
|
50
|
+
currentLevel = amplitude.getLevel();
|
|
51
|
+
|
|
52
|
+
// Track peak level
|
|
53
|
+
if (currentLevel > peakLevel)
|
|
54
|
+
{
|
|
55
|
+
peakLevel = currentLevel;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Output amplitude data to debug panel
|
|
59
|
+
debug("--- Audio Amplitude ---");
|
|
60
|
+
debug("Is Playing: " + audioTrack.isPlaying());
|
|
61
|
+
debug("Current Level: " + nf(currentLevel, 1, 3));
|
|
62
|
+
debug("Peak Level: " + nf(peakLevel, 1, 3));
|
|
63
|
+
debug("Percentage: " + int(currentLevel * 100) + "%");
|
|
64
|
+
|
|
65
|
+
// Check against threshold
|
|
66
|
+
if (currentLevel > threshold)
|
|
67
|
+
{
|
|
68
|
+
debug("STATUS: LOUD! (Above threshold)");
|
|
69
|
+
}
|
|
70
|
+
else
|
|
71
|
+
{
|
|
72
|
+
debug("STATUS: Quiet (Below threshold)");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Add visual bar representation using text
|
|
76
|
+
let barLength = int(currentLevel * 30);
|
|
77
|
+
let bar = "";
|
|
78
|
+
for (let i = 0; i < barLength; i++)
|
|
79
|
+
{
|
|
80
|
+
bar = bar + "▮";
|
|
81
|
+
}
|
|
82
|
+
debug("Level: " + bar);
|
|
83
|
+
|
|
84
|
+
debug("Touch & hold to play audio");
|
|
85
|
+
}
|
|
86
|
+
else
|
|
87
|
+
{
|
|
88
|
+
debug("Waiting for audio permissions...");
|
|
89
|
+
debug("Touch the screen to enable audio");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Play audio when touched
|
|
94
|
+
function touchStarted()
|
|
95
|
+
{
|
|
96
|
+
if (window.soundEnabled)
|
|
97
|
+
{
|
|
98
|
+
if (!audioTrack.isPlaying())
|
|
99
|
+
{
|
|
100
|
+
audioTrack.play();
|
|
101
|
+
debug("--- Touch: PLAYING ---");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return false; // Prevents default behavior
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Pause audio when touch ends
|
|
109
|
+
function touchEnded()
|
|
110
|
+
{
|
|
111
|
+
if (window.soundEnabled)
|
|
112
|
+
{
|
|
113
|
+
audioTrack.pause();
|
|
114
|
+
debug("--- Touch: PAUSED ---");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return false; // Prevents default behavior
|
|
118
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>P5.js Mobile - Touch Basic (Minimal)</title>
|
|
5
|
+
<script src="https://cdn.jsdelivr.net/npm/p5@1.11.0/lib/p5.min.js"></script>
|
|
6
|
+
<script src="https://cdn.jsdelivr.net/npm/mobile-p5-permissions@1.4.4/dist/p5.mobile-permissions.min.js"></script>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
}
|
|
13
|
+
</style>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<script src="sketch.js"></script>
|
|
17
|
+
</body>
|
|
18
|
+
</html>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// MINIMAL VERSION - Touch Basic
|
|
2
|
+
// No visual feedback - data displayed in debug panel only
|
|
3
|
+
// Demonstrates: Basic touch detection, duration tracking, and touch counting
|
|
4
|
+
|
|
5
|
+
// Global variables for touch state
|
|
6
|
+
let isCurrentlyTouching = false; // Track if screen is being touched
|
|
7
|
+
let touchCounter = 0; // Count total number of touches
|
|
8
|
+
let touchStartTime = 0; // When current touch started (milliseconds)
|
|
9
|
+
let touchDuration = 0; // How long current touch has been active (seconds)
|
|
10
|
+
|
|
11
|
+
function setup()
|
|
12
|
+
{
|
|
13
|
+
createCanvas(windowWidth, windowHeight);
|
|
14
|
+
|
|
15
|
+
// Show debug panel FIRST to display all touch data
|
|
16
|
+
showDebug();
|
|
17
|
+
|
|
18
|
+
// Lock mobile gestures to prevent browser interference
|
|
19
|
+
lockGestures();
|
|
20
|
+
|
|
21
|
+
debug("Touch Basic - Minimal Version");
|
|
22
|
+
debug("Touch the screen to see data in this panel");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function draw()
|
|
26
|
+
{
|
|
27
|
+
// Update touch duration while touching
|
|
28
|
+
if (isCurrentlyTouching)
|
|
29
|
+
{
|
|
30
|
+
touchDuration = (millis() - touchStartTime) / 1000; // Convert to seconds
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Prevent default touch behavior and unwanted gestures
|
|
35
|
+
function touchStarted()
|
|
36
|
+
{
|
|
37
|
+
isCurrentlyTouching = true;
|
|
38
|
+
touchCounter = touchCounter + 1;
|
|
39
|
+
touchStartTime = millis();
|
|
40
|
+
|
|
41
|
+
// Output touch data to debug panel
|
|
42
|
+
debug("--- Touch Started ---");
|
|
43
|
+
debug("Touch Count: " + touchCounter);
|
|
44
|
+
|
|
45
|
+
return false; // Prevents default behavior
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Prevent default touch behavior and unwanted gestures
|
|
49
|
+
function touchEnded()
|
|
50
|
+
{
|
|
51
|
+
isCurrentlyTouching = false;
|
|
52
|
+
|
|
53
|
+
// Output final touch duration to debug panel
|
|
54
|
+
debug("Touch Duration: " + touchDuration.toFixed(2) + " seconds");
|
|
55
|
+
debug("--- Touch Ended ---");
|
|
56
|
+
|
|
57
|
+
return false; // Prevents default behavior
|
|
58
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>P5.js Mobile - Touch Zones (Minimal)</title>
|
|
5
|
+
<script src="https://cdn.jsdelivr.net/npm/p5@1.11.0/lib/p5.min.js"></script>
|
|
6
|
+
<script src="https://cdn.jsdelivr.net/npm/mobile-p5-permissions@1.4.4/dist/p5.mobile-permissions.min.js"></script>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
}
|
|
13
|
+
</style>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<script src="sketch.js"></script>
|
|
17
|
+
</body>
|
|
18
|
+
</html>
|