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,139 @@
|
|
|
1
|
+
// Touch with GIF example
|
|
2
|
+
// Demonstrates GIF moving toward touch points with rotation
|
|
3
|
+
// Corgi fetches the ball wherever you touch
|
|
4
|
+
|
|
5
|
+
// Global variables
|
|
6
|
+
let corgiGif;
|
|
7
|
+
let corgiX;
|
|
8
|
+
let corgiY;
|
|
9
|
+
let targetX;
|
|
10
|
+
let targetY;
|
|
11
|
+
let moveSpeed = 0.05; // Speed multiplier for movement (0.0 - 1.0)
|
|
12
|
+
let corgiRotation = 0;
|
|
13
|
+
let corgiScale = 1.2; // Size multiplier for corgi
|
|
14
|
+
let touchCounter = 0;
|
|
15
|
+
let backgroundColor;
|
|
16
|
+
|
|
17
|
+
function preload()
|
|
18
|
+
{
|
|
19
|
+
// Load the corgi swimming GIF
|
|
20
|
+
corgiGif = loadImage('gifs/corgiswimflip.gif');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function setup()
|
|
24
|
+
{
|
|
25
|
+
createCanvas(windowWidth, windowHeight);
|
|
26
|
+
backgroundColor = color(200, 255, 200);
|
|
27
|
+
|
|
28
|
+
// Lock mobile gestures to prevent browser interference
|
|
29
|
+
lockGestures();
|
|
30
|
+
|
|
31
|
+
textAlign(CENTER, CENTER);
|
|
32
|
+
|
|
33
|
+
// Start corgi at center
|
|
34
|
+
corgiX = width / 2;
|
|
35
|
+
corgiY = height / 2;
|
|
36
|
+
targetX = corgiX;
|
|
37
|
+
targetY = corgiY;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function draw()
|
|
41
|
+
{
|
|
42
|
+
background(backgroundColor);
|
|
43
|
+
|
|
44
|
+
// Calculate angle to target
|
|
45
|
+
let angleToTarget = atan2(targetY - corgiY, targetX - corgiX);
|
|
46
|
+
|
|
47
|
+
// Smoothly move corgi toward target position
|
|
48
|
+
corgiX = lerp(corgiX, targetX, moveSpeed);
|
|
49
|
+
corgiY = lerp(corgiY, targetY, moveSpeed);
|
|
50
|
+
|
|
51
|
+
// Smoothly rotate toward movement direction
|
|
52
|
+
corgiRotation = angleToTarget;
|
|
53
|
+
|
|
54
|
+
// Display GIF with rotation and scale
|
|
55
|
+
push();
|
|
56
|
+
translate(corgiX, corgiY);
|
|
57
|
+
rotate(corgiRotation);
|
|
58
|
+
imageMode(CENTER);
|
|
59
|
+
image(corgiGif, 0, 0, 200 * corgiScale, 200 * corgiScale);
|
|
60
|
+
pop();
|
|
61
|
+
|
|
62
|
+
// Draw ball (target point) when different from current position
|
|
63
|
+
let distance = dist(corgiX, corgiY, targetX, targetY);
|
|
64
|
+
if (distance > 5)
|
|
65
|
+
{
|
|
66
|
+
// Corgi is moving - play the GIF
|
|
67
|
+
corgiGif.play();
|
|
68
|
+
|
|
69
|
+
// Draw ball
|
|
70
|
+
fill(255, 200, 50);
|
|
71
|
+
stroke(200, 150, 0);
|
|
72
|
+
strokeWeight(3);
|
|
73
|
+
circle(targetX, targetY, 30);
|
|
74
|
+
|
|
75
|
+
// Add shine to ball
|
|
76
|
+
fill(255, 255, 200, 150);
|
|
77
|
+
noStroke();
|
|
78
|
+
circle(targetX - 5, targetY - 5, 12);
|
|
79
|
+
}
|
|
80
|
+
else
|
|
81
|
+
{
|
|
82
|
+
// Ball caught! Pause the GIF and show celebration
|
|
83
|
+
corgiGif.pause();
|
|
84
|
+
|
|
85
|
+
fill(100, 255, 100);
|
|
86
|
+
noStroke();
|
|
87
|
+
textSize(32);
|
|
88
|
+
text("BALL CAUGHT!", width/2, 100);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Display information
|
|
92
|
+
fill(50);
|
|
93
|
+
textSize(24);
|
|
94
|
+
text("Fetches: " + touchCounter, width/2, 40);
|
|
95
|
+
|
|
96
|
+
// Instructions
|
|
97
|
+
textSize(20);
|
|
98
|
+
fill(100);
|
|
99
|
+
text("Touch to throw the ball!", width/2, height - 30);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function touchStarted()
|
|
103
|
+
{
|
|
104
|
+
touchCounter = touchCounter + 1;
|
|
105
|
+
|
|
106
|
+
// Set new target position
|
|
107
|
+
if (touches.length > 0)
|
|
108
|
+
{
|
|
109
|
+
targetX = touches[0].x;
|
|
110
|
+
targetY = touches[0].y;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Start playing the GIF when new target is set
|
|
114
|
+
corgiGif.play();
|
|
115
|
+
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function touchMoved()
|
|
120
|
+
{
|
|
121
|
+
// Update target as touch moves
|
|
122
|
+
if (touches.length > 0)
|
|
123
|
+
{
|
|
124
|
+
targetX = touches[0].x;
|
|
125
|
+
targetY = touches[0].y;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function touchEnded()
|
|
132
|
+
{
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function windowResized()
|
|
137
|
+
{
|
|
138
|
+
resizeCanvas(windowWidth, windowHeight);
|
|
139
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>P5.js Mobile - Fly Control</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,103 @@
|
|
|
1
|
+
// Fly control example
|
|
2
|
+
// Demonstrates using device acceleration (accelerationY) to control GIF playback speed
|
|
3
|
+
// Move phone up/down to simulate airplane motion and control cloud speed
|
|
4
|
+
|
|
5
|
+
// Global variables
|
|
6
|
+
let airplaneGif;
|
|
7
|
+
let playbackSpeed = 1.0; // Speed multiplier for GIF playback
|
|
8
|
+
let backgroundColor;
|
|
9
|
+
|
|
10
|
+
// Mapping variables - easy to adjust
|
|
11
|
+
let speedMultiplier = 3.0; // How much speed per unit of acceleration
|
|
12
|
+
let maxSpeed = 270.0; // Maximum playback speed
|
|
13
|
+
let minSpeedToPlay = 0.25; // Minimum speed before pausing
|
|
14
|
+
let movementThreshold = 0.1; // Minimum acceleration needed to play (below this = paused)
|
|
15
|
+
|
|
16
|
+
function preload()
|
|
17
|
+
{
|
|
18
|
+
// Load the airplane window GIF
|
|
19
|
+
airplaneGif = loadImage('gifs/comparison.gif');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function setup()
|
|
23
|
+
{
|
|
24
|
+
createCanvas(windowWidth, windowHeight);
|
|
25
|
+
backgroundColor = color(200, 220, 255);
|
|
26
|
+
|
|
27
|
+
// Lock mobile gestures to prevent browser interference
|
|
28
|
+
lockGestures();
|
|
29
|
+
|
|
30
|
+
textAlign(CENTER, CENTER);
|
|
31
|
+
|
|
32
|
+
// Request permission for motion sensors on iOS
|
|
33
|
+
enableGyroTap();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function draw()
|
|
37
|
+
{
|
|
38
|
+
background(backgroundColor);
|
|
39
|
+
|
|
40
|
+
// Check if motion sensors are available
|
|
41
|
+
if (window.sensorsEnabled)
|
|
42
|
+
{
|
|
43
|
+
// Map absolute value of accelerationY to playback speed
|
|
44
|
+
// When still (accelerationY = 0), speed is low/paused
|
|
45
|
+
// As you move phone up/down, speed increases
|
|
46
|
+
let moveAmount = abs(accelerationY);
|
|
47
|
+
|
|
48
|
+
// Check if movement is below threshold
|
|
49
|
+
if (moveAmount < movementThreshold)
|
|
50
|
+
{
|
|
51
|
+
// Below threshold - pause the GIF
|
|
52
|
+
airplaneGif.pause();
|
|
53
|
+
playbackSpeed = 0;
|
|
54
|
+
}
|
|
55
|
+
else
|
|
56
|
+
{
|
|
57
|
+
// Above threshold - calculate and set playback speed
|
|
58
|
+
playbackSpeed = moveAmount * speedMultiplier;
|
|
59
|
+
|
|
60
|
+
// Constrain to max speed
|
|
61
|
+
playbackSpeed = constrain(playbackSpeed, 0.0, maxSpeed);
|
|
62
|
+
|
|
63
|
+
airplaneGif.play();
|
|
64
|
+
airplaneGif.delay(int(100 / playbackSpeed));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Display GIF rotated 90 degrees for portrait mode, filling the canvas
|
|
68
|
+
push();
|
|
69
|
+
translate(width/2, height/2);
|
|
70
|
+
rotate(HALF_PI); // Rotate 90 degrees
|
|
71
|
+
imageMode(CENTER);
|
|
72
|
+
// After rotation, width becomes height and height becomes width
|
|
73
|
+
image(airplaneGif, 0, 0, height, width);
|
|
74
|
+
pop();
|
|
75
|
+
|
|
76
|
+
// Display acceleration value over the image
|
|
77
|
+
fill(255, 150, 0); // Orange
|
|
78
|
+
stroke(0);
|
|
79
|
+
strokeWeight(4);
|
|
80
|
+
textSize(64);
|
|
81
|
+
// text("Accel Y: " + nf(accelerationY, 1, 2), width/2, 80);
|
|
82
|
+
|
|
83
|
+
// Instructions
|
|
84
|
+
// textSize(18);
|
|
85
|
+
// fill(100);
|
|
86
|
+
// noStroke();
|
|
87
|
+
// text("Move phone up/down to control flight speed", width/2, height - 50);
|
|
88
|
+
// text("Still = paused, more movement = faster", width/2, height - 25);
|
|
89
|
+
}
|
|
90
|
+
else
|
|
91
|
+
{
|
|
92
|
+
// Motion sensors not available or permission not granted
|
|
93
|
+
fill(255, 100, 100);
|
|
94
|
+
text("Motion sensors not available", width/2, height/2);
|
|
95
|
+
text("On iOS: Tap to request motion permission", width/2, height/2 + 30);
|
|
96
|
+
text("Check device compatibility", width/2, height/2 + 60);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function windowResized()
|
|
101
|
+
{
|
|
102
|
+
resizeCanvas(windowWidth, windowHeight);
|
|
103
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>P5.js Mobile - Roll Control</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,121 @@
|
|
|
1
|
+
// Roll control example
|
|
2
|
+
// Demonstrates using device rotation (rotationX) to control GIF playback speed
|
|
3
|
+
// Tilt phone forward/backward to speed up or slow down the animation
|
|
4
|
+
|
|
5
|
+
// Global variables
|
|
6
|
+
let pencilGif;
|
|
7
|
+
let playbackSpeed = 1.0; // Speed multiplier for GIF playback
|
|
8
|
+
let backgroundColor;
|
|
9
|
+
|
|
10
|
+
// Mapping variables - easy to adjust
|
|
11
|
+
let speedMultiplier = 3.0; // How much speed per degree of tilt (1° = 3x speed)
|
|
12
|
+
let maxSpeed = 270.0; // Maximum playback speed
|
|
13
|
+
let minSpeedToPlay = 0.1; // Minimum speed before pausing
|
|
14
|
+
|
|
15
|
+
function preload()
|
|
16
|
+
{
|
|
17
|
+
// Load the pencil making GIF
|
|
18
|
+
pencilGif = loadImage('gifs/how-penciles-are-made.gif');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function setup()
|
|
22
|
+
{
|
|
23
|
+
createCanvas(windowWidth, windowHeight);
|
|
24
|
+
backgroundColor = color(200, 255, 200);
|
|
25
|
+
|
|
26
|
+
// Lock mobile gestures to prevent browser interference
|
|
27
|
+
lockGestures();
|
|
28
|
+
|
|
29
|
+
textAlign(CENTER, CENTER);
|
|
30
|
+
|
|
31
|
+
// Request permission for motion sensors on iOS
|
|
32
|
+
enableGyroTap();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function draw()
|
|
36
|
+
{
|
|
37
|
+
background(backgroundColor);
|
|
38
|
+
|
|
39
|
+
// Check if motion sensors are available
|
|
40
|
+
if (window.sensorsEnabled)
|
|
41
|
+
{
|
|
42
|
+
// Map absolute value of rotationX to playback speed
|
|
43
|
+
// When flat (rotationX = 0), speed is 0 (paused)
|
|
44
|
+
let tiltAmount = abs(rotationX);
|
|
45
|
+
playbackSpeed = tiltAmount * speedMultiplier;
|
|
46
|
+
|
|
47
|
+
// Constrain to max speed
|
|
48
|
+
playbackSpeed = constrain(playbackSpeed, 0.0, maxSpeed);
|
|
49
|
+
|
|
50
|
+
// Set the GIF playback speed (pause if speed is very low)
|
|
51
|
+
if (playbackSpeed < minSpeedToPlay)
|
|
52
|
+
{
|
|
53
|
+
pencilGif.pause();
|
|
54
|
+
}
|
|
55
|
+
else
|
|
56
|
+
{
|
|
57
|
+
pencilGif.play();
|
|
58
|
+
pencilGif.delay(int(100 / playbackSpeed));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Display GIF rotated 90 degrees for portrait mode, filling the canvas
|
|
62
|
+
push();
|
|
63
|
+
translate(width/2, height/2);
|
|
64
|
+
rotate(HALF_PI); // Rotate 90 degrees
|
|
65
|
+
imageMode(CENTER);
|
|
66
|
+
// After rotation, width becomes height and height becomes width
|
|
67
|
+
image(pencilGif, 0, 0, height, width);
|
|
68
|
+
pop();
|
|
69
|
+
|
|
70
|
+
// Display rotation and speed information
|
|
71
|
+
// fill(50);
|
|
72
|
+
// textSize(24);
|
|
73
|
+
// text("Device Tilt (X): " + nf(rotationX, 1, 1) + "°", width/2, height/6);
|
|
74
|
+
// text("Playback Speed: " + nf(playbackSpeed, 1, 2) + "x", width/2, height/6 + 40);
|
|
75
|
+
|
|
76
|
+
// Visual speed indicator bar
|
|
77
|
+
// let barWidth = map(playbackSpeed, 0, 3, 0, width - 80);
|
|
78
|
+
// fill(100, 200, 255);
|
|
79
|
+
// noStroke();
|
|
80
|
+
// rect(40, height - 100, barWidth, 30);
|
|
81
|
+
|
|
82
|
+
// Bar outline
|
|
83
|
+
// noFill();
|
|
84
|
+
// stroke(50);
|
|
85
|
+
// strokeWeight(2);
|
|
86
|
+
// rect(40, height - 100, width - 80, 30);
|
|
87
|
+
|
|
88
|
+
// Instructions
|
|
89
|
+
// textSize(18);
|
|
90
|
+
// fill(100);
|
|
91
|
+
// noStroke();
|
|
92
|
+
// text("Tilt phone to make pencils roll", width/2, height - 50);
|
|
93
|
+
// text("Flat = paused, more tilt = faster", width/2, height - 25);
|
|
94
|
+
}
|
|
95
|
+
else
|
|
96
|
+
{
|
|
97
|
+
// Motion sensors not available or permission not granted
|
|
98
|
+
fill(255, 100, 100);
|
|
99
|
+
text("Motion sensors not available", width/2, height/2);
|
|
100
|
+
text("On iOS: Tap to request motion permission", width/2, height/2 + 30);
|
|
101
|
+
text("Check device compatibility", width/2, height/2 + 60);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ==============================================
|
|
106
|
+
// TOUCH EVENT FUNCTIONS
|
|
107
|
+
// ==============================================
|
|
108
|
+
|
|
109
|
+
// This function runs when a new touch begins
|
|
110
|
+
function touchStarted()
|
|
111
|
+
{
|
|
112
|
+
// Touch positions will be updated in draw() function
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// This function runs when a touch ends
|
|
117
|
+
function touchEnded()
|
|
118
|
+
{
|
|
119
|
+
// Touch positions will be updated in draw() function
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
|
|
6
|
+
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
7
|
+
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
|
8
|
+
<title>Button vs Movement Comparison</title>
|
|
9
|
+
|
|
10
|
+
<style>
|
|
11
|
+
* {
|
|
12
|
+
margin: 0;
|
|
13
|
+
padding: 0;
|
|
14
|
+
box-sizing: border-box;
|
|
15
|
+
-webkit-user-select: none;
|
|
16
|
+
user-select: none;
|
|
17
|
+
-webkit-tap-highlight-color: transparent;
|
|
18
|
+
-webkit-touch-callout: none;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
html, body {
|
|
22
|
+
width: 100%;
|
|
23
|
+
height: 100%;
|
|
24
|
+
overflow: hidden;
|
|
25
|
+
position: fixed;
|
|
26
|
+
touch-action: none;
|
|
27
|
+
background: #000;
|
|
28
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
canvas {
|
|
32
|
+
display: block;
|
|
33
|
+
position: fixed;
|
|
34
|
+
left: 0;
|
|
35
|
+
top: 0;
|
|
36
|
+
}
|
|
37
|
+
</style>
|
|
38
|
+
|
|
39
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.7.0/p5.min.js"></script>
|
|
40
|
+
<script src="https://cdn.jsdelivr.net/npm/mobile-p5-permissions@1.4.4/dist/p5.mobile-permissions.min.js"></script>
|
|
41
|
+
</head>
|
|
42
|
+
<body>
|
|
43
|
+
<script src="sketch.js"></script>
|
|
44
|
+
</body>
|
|
45
|
+
</html>
|