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,401 @@
|
|
|
1
|
+
// Slider vs Touch Distance Comparison
|
|
2
|
+
// Shows traditional float slider UI vs two-touch distance measurement
|
|
3
|
+
|
|
4
|
+
// Color scheme - using proper p5.js colors
|
|
5
|
+
let backgroundColor, sliderColor, touchColor;
|
|
6
|
+
|
|
7
|
+
// Slider properties
|
|
8
|
+
let sliderValue = 0.5; // Current slider value (0.0-1.0)
|
|
9
|
+
let sliderMin = 0.0;
|
|
10
|
+
let sliderMax = 1.0;
|
|
11
|
+
let sliderX, sliderY;
|
|
12
|
+
let sliderWidth = 300;
|
|
13
|
+
let sliderHeight = 40;
|
|
14
|
+
let isDraggingSlider = false;
|
|
15
|
+
|
|
16
|
+
// Touch distance measurement
|
|
17
|
+
let touchDistance = 0.0;
|
|
18
|
+
let normalizedDistance = 0.0;
|
|
19
|
+
let maxDistance = 300; // Maximum expected distance for normalization
|
|
20
|
+
let minDistance = 50; // Minimum distance to register
|
|
21
|
+
|
|
22
|
+
// Layout properties
|
|
23
|
+
let topSectionHeight;
|
|
24
|
+
let bottomSectionHeight;
|
|
25
|
+
let dividerY;
|
|
26
|
+
let currentOrientation = 'portrait';
|
|
27
|
+
|
|
28
|
+
function setup() {
|
|
29
|
+
createCanvas(windowWidth, windowHeight);
|
|
30
|
+
|
|
31
|
+
// Initialize colors properly
|
|
32
|
+
backgroundColor = color(44, 62, 80); // Dark blue-gray
|
|
33
|
+
sliderColor = color(52, 152, 219); // Blue
|
|
34
|
+
touchColor = color(231, 76, 60); // Red
|
|
35
|
+
|
|
36
|
+
// Only call lockGestures if it exists
|
|
37
|
+
if (typeof lockGestures === 'function') {
|
|
38
|
+
lockGestures();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Calculate layout
|
|
42
|
+
updateLayout();
|
|
43
|
+
|
|
44
|
+
textAlign(CENTER, CENTER);
|
|
45
|
+
noStroke();
|
|
46
|
+
|
|
47
|
+
console.log('Slider vs Distance ready!');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function draw() {
|
|
51
|
+
background(backgroundColor);
|
|
52
|
+
|
|
53
|
+
// Update orientation
|
|
54
|
+
currentOrientation = (width > height) ? 'landscape' : 'portrait';
|
|
55
|
+
|
|
56
|
+
// Calculate touch distance for bottom section
|
|
57
|
+
calculateTouchDistance();
|
|
58
|
+
|
|
59
|
+
// Draw divider line
|
|
60
|
+
stroke(255, 255, 255, 100);
|
|
61
|
+
strokeWeight(2);
|
|
62
|
+
line(0, dividerY, width, dividerY);
|
|
63
|
+
noStroke();
|
|
64
|
+
|
|
65
|
+
// Draw top section - Traditional Float Slider UI
|
|
66
|
+
drawTopSection();
|
|
67
|
+
|
|
68
|
+
// Draw bottom section - Touch Distance Interaction
|
|
69
|
+
drawBottomSection();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function drawTopSection() {
|
|
73
|
+
// Section title
|
|
74
|
+
fill(255, 255, 255);
|
|
75
|
+
textSize(24);
|
|
76
|
+
if (currentOrientation === 'landscape') {
|
|
77
|
+
textAlign(LEFT, CENTER);
|
|
78
|
+
text('TRADITIONAL UI', 30, 40);
|
|
79
|
+
} else {
|
|
80
|
+
textAlign(CENTER, CENTER);
|
|
81
|
+
text('TRADITIONAL UI', width / 2, 40);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Draw slider
|
|
85
|
+
drawSlider();
|
|
86
|
+
|
|
87
|
+
// Draw value bar visualization
|
|
88
|
+
drawValueBar(sliderValue, topSectionHeight / 2 + 80, sliderColor);
|
|
89
|
+
|
|
90
|
+
// Draw slider value text
|
|
91
|
+
fill(255, 255, 255);
|
|
92
|
+
textSize(20);
|
|
93
|
+
let valueText = 'Slider value: ' + sliderValue.toFixed(2);
|
|
94
|
+
if (currentOrientation === 'landscape') {
|
|
95
|
+
textAlign(LEFT, CENTER);
|
|
96
|
+
text(valueText, 30, topSectionHeight - 40);
|
|
97
|
+
} else {
|
|
98
|
+
textAlign(CENTER, CENTER);
|
|
99
|
+
text(valueText, width / 2, topSectionHeight - 40);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function drawBottomSection() {
|
|
104
|
+
// Section title
|
|
105
|
+
fill(255, 255, 255);
|
|
106
|
+
textSize(24);
|
|
107
|
+
if (currentOrientation === 'landscape') {
|
|
108
|
+
textAlign(LEFT, CENTER);
|
|
109
|
+
text('MOBILE INTERACTION', 30, dividerY + 40);
|
|
110
|
+
} else {
|
|
111
|
+
textAlign(CENTER, CENTER);
|
|
112
|
+
text('MOBILE INTERACTION', width / 2, dividerY + 40);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Instructions
|
|
116
|
+
fill(255, 255, 255, 200);
|
|
117
|
+
textSize(18);
|
|
118
|
+
let instructionText = getTouchInstructions();
|
|
119
|
+
if (currentOrientation === 'landscape') {
|
|
120
|
+
textAlign(LEFT, CENTER);
|
|
121
|
+
text(instructionText, 30, dividerY + 80);
|
|
122
|
+
} else {
|
|
123
|
+
textAlign(CENTER, CENTER);
|
|
124
|
+
text(instructionText, width / 2, dividerY + 80);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Draw value bar for distance
|
|
128
|
+
drawValueBar(normalizedDistance, dividerY + (bottomSectionHeight / 2) + 40, touchColor);
|
|
129
|
+
|
|
130
|
+
// Draw touch distance visualization
|
|
131
|
+
drawTouchDistanceVisualization();
|
|
132
|
+
|
|
133
|
+
// Draw distance value text
|
|
134
|
+
fill(255, 255, 255);
|
|
135
|
+
textSize(20);
|
|
136
|
+
let distanceText = 'Distance value: ' + normalizedDistance.toFixed(2);
|
|
137
|
+
if (currentOrientation === 'landscape') {
|
|
138
|
+
textAlign(LEFT, CENTER);
|
|
139
|
+
text(distanceText, 30, height - 40);
|
|
140
|
+
} else {
|
|
141
|
+
textAlign(CENTER, CENTER);
|
|
142
|
+
text(distanceText, width / 2, height - 40);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function getTouchInstructions() {
|
|
147
|
+
let bottomTouches = getBottomTouches();
|
|
148
|
+
if (bottomTouches.length === 0) {
|
|
149
|
+
return 'Place two fingers to measure distance!';
|
|
150
|
+
} else if (bottomTouches.length === 1) {
|
|
151
|
+
return 'Add a second finger!';
|
|
152
|
+
} else if (bottomTouches.length === 2) {
|
|
153
|
+
return 'Move fingers apart/together!';
|
|
154
|
+
} else {
|
|
155
|
+
return 'Too many fingers - use only 2!';
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function drawSlider() {
|
|
160
|
+
// Position slider in center of top section
|
|
161
|
+
sliderY = topSectionHeight / 2 - sliderHeight / 2;
|
|
162
|
+
|
|
163
|
+
if (currentOrientation === 'landscape') {
|
|
164
|
+
sliderX = width / 2 - sliderWidth / 2 + 50; // Offset right to avoid left text
|
|
165
|
+
} else {
|
|
166
|
+
sliderX = width / 2 - sliderWidth / 2;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Slider track (background)
|
|
170
|
+
fill(255, 255, 255, 100);
|
|
171
|
+
rect(sliderX, sliderY, sliderWidth, sliderHeight, sliderHeight / 2);
|
|
172
|
+
|
|
173
|
+
// Calculate slider handle position
|
|
174
|
+
let handleX = map(sliderValue, sliderMin, sliderMax, sliderX + 20, sliderX + sliderWidth - 20);
|
|
175
|
+
|
|
176
|
+
// Slider fill (shows progress)
|
|
177
|
+
fill(sliderColor);
|
|
178
|
+
rect(sliderX, sliderY, handleX - sliderX + 20, sliderHeight, sliderHeight / 2);
|
|
179
|
+
|
|
180
|
+
// Slider handle shadow
|
|
181
|
+
fill(0, 0, 0, 50);
|
|
182
|
+
circle(handleX + 2, sliderY + sliderHeight / 2 + 2, 35);
|
|
183
|
+
|
|
184
|
+
// Slider handle
|
|
185
|
+
fill(255, 255, 255);
|
|
186
|
+
if (isDraggingSlider) {
|
|
187
|
+
fill(255, 255, 0); // Yellow when dragging
|
|
188
|
+
}
|
|
189
|
+
circle(handleX, sliderY + sliderHeight / 2, 35);
|
|
190
|
+
|
|
191
|
+
// Handle indicator
|
|
192
|
+
fill(sliderColor);
|
|
193
|
+
circle(handleX, sliderY + sliderHeight / 2, 15);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function drawValueBar(value, yPos, barColor) {
|
|
197
|
+
// Draw a horizontal bar representing the value (0.0-1.0)
|
|
198
|
+
let barWidth = min(300, width - 120);
|
|
199
|
+
let barHeight = 30;
|
|
200
|
+
let barX = width / 2 - barWidth / 2;
|
|
201
|
+
|
|
202
|
+
if (currentOrientation === 'landscape') {
|
|
203
|
+
barX = width / 2 - barWidth / 2 + 25; // Slight offset for landscape
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Background bar
|
|
207
|
+
fill(255, 255, 255, 100);
|
|
208
|
+
rect(barX, yPos - barHeight / 2, barWidth, barHeight, barHeight / 2);
|
|
209
|
+
|
|
210
|
+
// Value fill
|
|
211
|
+
let fillWidth = value * barWidth;
|
|
212
|
+
fill(barColor);
|
|
213
|
+
rect(barX, yPos - barHeight / 2, fillWidth, barHeight, barHeight / 2);
|
|
214
|
+
|
|
215
|
+
// Value text on bar
|
|
216
|
+
fill(255, 255, 255);
|
|
217
|
+
textAlign(CENTER, CENTER);
|
|
218
|
+
textSize(16);
|
|
219
|
+
text((value * 100).toFixed(0) + '%', barX + barWidth / 2, yPos);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function drawTouchDistanceVisualization() {
|
|
223
|
+
let bottomTouches = getBottomTouches();
|
|
224
|
+
|
|
225
|
+
if (bottomTouches.length >= 2) {
|
|
226
|
+
// Draw line between first two touches
|
|
227
|
+
let touch1 = bottomTouches[0];
|
|
228
|
+
let touch2 = bottomTouches[1];
|
|
229
|
+
|
|
230
|
+
// Connection line
|
|
231
|
+
stroke(touchColor);
|
|
232
|
+
strokeWeight(3);
|
|
233
|
+
line(touch1.x, touch1.y, touch2.x, touch2.y);
|
|
234
|
+
|
|
235
|
+
// Touch points
|
|
236
|
+
fill(touchColor);
|
|
237
|
+
noStroke();
|
|
238
|
+
circle(touch1.x, touch1.y, 40);
|
|
239
|
+
circle(touch2.x, touch2.y, 40);
|
|
240
|
+
|
|
241
|
+
// Touch numbers
|
|
242
|
+
fill(255, 255, 255);
|
|
243
|
+
textAlign(CENTER, CENTER);
|
|
244
|
+
textSize(18);
|
|
245
|
+
text('1', touch1.x, touch1.y);
|
|
246
|
+
text('2', touch2.x, touch2.y);
|
|
247
|
+
|
|
248
|
+
// Distance text in middle
|
|
249
|
+
let midX = (touch1.x + touch2.x) / 2;
|
|
250
|
+
let midY = (touch1.y + touch2.y) / 2;
|
|
251
|
+
|
|
252
|
+
// Background for distance text
|
|
253
|
+
fill(0, 0, 0, 150);
|
|
254
|
+
let distanceText = Math.round(touchDistance) + 'px';
|
|
255
|
+
textSize(14);
|
|
256
|
+
let textW = textWidth(distanceText) + 10;
|
|
257
|
+
rect(midX - textW / 2, midY - 10, textW, 20, 5);
|
|
258
|
+
|
|
259
|
+
// Distance text
|
|
260
|
+
fill(255, 255, 255);
|
|
261
|
+
text(distanceText, midX, midY);
|
|
262
|
+
|
|
263
|
+
} else {
|
|
264
|
+
// Draw all touches in bottom section
|
|
265
|
+
for (let i = 0; i < bottomTouches.length; i++) {
|
|
266
|
+
let touch = bottomTouches[i];
|
|
267
|
+
fill(touchColor);
|
|
268
|
+
noStroke();
|
|
269
|
+
circle(touch.x, touch.y, 40);
|
|
270
|
+
|
|
271
|
+
fill(255, 255, 255);
|
|
272
|
+
textAlign(CENTER, CENTER);
|
|
273
|
+
textSize(18);
|
|
274
|
+
text(i + 1, touch.x, touch.y);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function getBottomTouches() {
|
|
280
|
+
let bottomTouches = [];
|
|
281
|
+
if (touches && touches.length > 0) {
|
|
282
|
+
for (let touch of touches) {
|
|
283
|
+
if (touch && typeof touch.x === 'number' && typeof touch.y === 'number' && touch.y > dividerY) {
|
|
284
|
+
bottomTouches.push(touch);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return bottomTouches;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function calculateTouchDistance() {
|
|
292
|
+
let bottomTouches = getBottomTouches();
|
|
293
|
+
|
|
294
|
+
if (bottomTouches.length >= 2) {
|
|
295
|
+
let touch1 = bottomTouches[0];
|
|
296
|
+
let touch2 = bottomTouches[1];
|
|
297
|
+
|
|
298
|
+
touchDistance = dist(touch1.x, touch1.y, touch2.x, touch2.y);
|
|
299
|
+
|
|
300
|
+
// Normalize distance to 0.0-1.0 range
|
|
301
|
+
normalizedDistance = map(touchDistance, minDistance, maxDistance, 0.0, 1.0);
|
|
302
|
+
normalizedDistance = constrain(normalizedDistance, 0.0, 1.0);
|
|
303
|
+
} else {
|
|
304
|
+
touchDistance = 0.0;
|
|
305
|
+
normalizedDistance = 0.0;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function isSliderPressed(x, y) {
|
|
310
|
+
return x >= sliderX &&
|
|
311
|
+
x <= sliderX + sliderWidth &&
|
|
312
|
+
y >= sliderY - 20 &&
|
|
313
|
+
y <= sliderY + sliderHeight + 20 &&
|
|
314
|
+
y < dividerY;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function updateSliderValueFromTouch(x) {
|
|
318
|
+
let newValue = map(x, sliderX, sliderX + sliderWidth, sliderMin, sliderMax);
|
|
319
|
+
newValue = constrain(newValue, sliderMin, sliderMax);
|
|
320
|
+
sliderValue = newValue;
|
|
321
|
+
|
|
322
|
+
console.log('Slider value:', sliderValue.toFixed(3));
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Handle touch interaction for mobile
|
|
326
|
+
function touchStarted() {
|
|
327
|
+
// Handle slider interaction only for touches in top section
|
|
328
|
+
if (touches && touches.length >= 1) {
|
|
329
|
+
for (let touch of touches) {
|
|
330
|
+
if (touch && touch.y < dividerY && isSliderPressed(touch.x, touch.y)) {
|
|
331
|
+
isDraggingSlider = true;
|
|
332
|
+
updateSliderValueFromTouch(touch.x);
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return false; // Always prevent default
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function touchMoved() {
|
|
341
|
+
// Update slider if dragging and touch is in top section
|
|
342
|
+
if (isDraggingSlider && touches && touches.length >= 1) {
|
|
343
|
+
for (let touch of touches) {
|
|
344
|
+
if (touch && touch.y < dividerY) {
|
|
345
|
+
updateSliderValueFromTouch(touch.x);
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return false; // Always prevent default
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function touchEnded() {
|
|
354
|
+
// Check if any touches remain in slider area
|
|
355
|
+
if (isDraggingSlider) {
|
|
356
|
+
let sliderTouchExists = false;
|
|
357
|
+
if (touches && touches.length > 0) {
|
|
358
|
+
for (let touch of touches) {
|
|
359
|
+
if (touch && touch.y < dividerY && isSliderPressed(touch.x, touch.y)) {
|
|
360
|
+
sliderTouchExists = true;
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (!sliderTouchExists) {
|
|
366
|
+
isDraggingSlider = false;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return false; // Always prevent default
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Handle mouse interaction for desktop testing
|
|
373
|
+
function mousePressed() {
|
|
374
|
+
if (isSliderPressed(mouseX, mouseY)) {
|
|
375
|
+
isDraggingSlider = true;
|
|
376
|
+
updateSliderValueFromTouch(mouseX);
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function mouseDragged() {
|
|
382
|
+
if (isDraggingSlider) {
|
|
383
|
+
updateSliderValueFromTouch(mouseX);
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function mouseReleased() {
|
|
389
|
+
isDraggingSlider = false;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function updateLayout() {
|
|
393
|
+
topSectionHeight = height * 0.5;
|
|
394
|
+
bottomSectionHeight = height * 0.5;
|
|
395
|
+
dividerY = height * 0.5;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function windowResized() {
|
|
399
|
+
resizeCanvas(windowWidth, windowHeight);
|
|
400
|
+
updateLayout();
|
|
401
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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 Microphone - 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://cdnjs.cloudflare.com/ajax/libs/p5.js/1.7.0/addons/p5.sound.min.js"></script>
|
|
23
|
+
<script src="https://cdn.jsdelivr.net/npm/mobile-p5-permissions@1.4.4/dist/p5.mobile-permissions.min.js"></script>
|
|
24
|
+
<script src="sketch.js"></script>
|
|
25
|
+
</body>
|
|
26
|
+
</html>
|