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,361 @@
|
|
|
1
|
+
// Sliders vs Device Acceleration Comparison
|
|
2
|
+
// Shows traditional RGB sliders vs device acceleration control
|
|
3
|
+
|
|
4
|
+
// Color scheme
|
|
5
|
+
let backgroundColor;
|
|
6
|
+
|
|
7
|
+
// Slider properties
|
|
8
|
+
let sliderValues = [0.5, 0.5, 0.5]; // RGB values (0.0-1.0)
|
|
9
|
+
let sliderLabels = ['Red', 'Green', 'Blue'];
|
|
10
|
+
let sliderColors = [];
|
|
11
|
+
let sliderMin = 0.0;
|
|
12
|
+
let sliderMax = 1.0;
|
|
13
|
+
let sliders = [];
|
|
14
|
+
let isDraggingSlider = -1; // -1 = none, 0-2 = slider index
|
|
15
|
+
|
|
16
|
+
// Acceleration values
|
|
17
|
+
let accelerationValues = [0.0, 0.0, 0.0]; // X, Y, Z acceleration
|
|
18
|
+
let normalizedAcceleration = [0.5, 0.5, 0.5]; // Normalized to 0.0-1.0
|
|
19
|
+
|
|
20
|
+
// Layout properties
|
|
21
|
+
let currentOrientation = 'portrait';
|
|
22
|
+
let topSectionHeight;
|
|
23
|
+
let bottomSectionHeight;
|
|
24
|
+
let dividerY;
|
|
25
|
+
|
|
26
|
+
// Slider dimensions
|
|
27
|
+
let sliderWidth = 250;
|
|
28
|
+
let sliderHeight = 30;
|
|
29
|
+
let sliderSpacing = 60;
|
|
30
|
+
|
|
31
|
+
function setup() {
|
|
32
|
+
createCanvas(windowWidth, windowHeight);
|
|
33
|
+
|
|
34
|
+
// Initialize colors
|
|
35
|
+
backgroundColor = color(44, 62, 80); // Dark blue-gray
|
|
36
|
+
sliderColors = [
|
|
37
|
+
color(231, 76, 60), // Red
|
|
38
|
+
color(46, 204, 113), // Green
|
|
39
|
+
color(52, 152, 219) // Blue
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
// Enable gesture locking and motion sensors
|
|
43
|
+
lockGestures();
|
|
44
|
+
enableGyroTap('Tap to enable device acceleration detection');
|
|
45
|
+
|
|
46
|
+
// Calculate layout
|
|
47
|
+
updateLayout();
|
|
48
|
+
|
|
49
|
+
// Initialize slider positions
|
|
50
|
+
updateSliderPositions();
|
|
51
|
+
|
|
52
|
+
console.log('Sliders vs Acceleration ready!');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function draw() {
|
|
56
|
+
// Update acceleration values
|
|
57
|
+
updateAccelerationValues();
|
|
58
|
+
|
|
59
|
+
// Update orientation
|
|
60
|
+
updateOrientation();
|
|
61
|
+
|
|
62
|
+
// Set background based on current mode
|
|
63
|
+
if (window.sensorsEnabled) {
|
|
64
|
+
// Use acceleration for background color
|
|
65
|
+
backgroundColor = color(
|
|
66
|
+
normalizedAcceleration[0] * 255, // Red from acceleration X
|
|
67
|
+
normalizedAcceleration[1] * 255, // Green from acceleration Y
|
|
68
|
+
normalizedAcceleration[2] * 255 // Blue from acceleration Z
|
|
69
|
+
);
|
|
70
|
+
} else {
|
|
71
|
+
// Use sliders for background color
|
|
72
|
+
backgroundColor = color(
|
|
73
|
+
sliderValues[0] * 255, // Red
|
|
74
|
+
sliderValues[1] * 255, // Green
|
|
75
|
+
sliderValues[2] * 255 // Blue
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
background(backgroundColor);
|
|
80
|
+
|
|
81
|
+
// Draw top section - sliders
|
|
82
|
+
drawTopSection();
|
|
83
|
+
|
|
84
|
+
// Draw divider
|
|
85
|
+
drawDivider();
|
|
86
|
+
|
|
87
|
+
// Draw bottom section - acceleration
|
|
88
|
+
drawBottomSection();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function drawTopSection() {
|
|
92
|
+
// Section title
|
|
93
|
+
fill(255, 255, 255);
|
|
94
|
+
textSize(20);
|
|
95
|
+
if (currentOrientation === 'landscape') {
|
|
96
|
+
textAlign(LEFT, CENTER);
|
|
97
|
+
text('TRADITIONAL UI', 30, 30);
|
|
98
|
+
} else {
|
|
99
|
+
textAlign(CENTER, CENTER);
|
|
100
|
+
text('TRADITIONAL UI', width / 2, 30);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Draw all three sliders
|
|
104
|
+
for (let i = 0; i < 3; i++) {
|
|
105
|
+
drawSlider(i);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Draw color preview rectangle
|
|
109
|
+
let previewColor = color(
|
|
110
|
+
sliderValues[0] * 255,
|
|
111
|
+
sliderValues[1] * 255,
|
|
112
|
+
sliderValues[2] * 255
|
|
113
|
+
);
|
|
114
|
+
fill(previewColor);
|
|
115
|
+
noStroke();
|
|
116
|
+
if (currentOrientation === 'landscape') {
|
|
117
|
+
rect(30, topSectionHeight - 60, 200, 40);
|
|
118
|
+
} else {
|
|
119
|
+
rect(width / 2 - 100, topSectionHeight - 60, 200, 40);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function drawBottomSection() {
|
|
124
|
+
// Section title
|
|
125
|
+
fill(255, 255, 255);
|
|
126
|
+
textSize(20);
|
|
127
|
+
if (currentOrientation === 'landscape') {
|
|
128
|
+
textAlign(LEFT, CENTER);
|
|
129
|
+
text('MOBILE INTERACTION', 30, dividerY + 30);
|
|
130
|
+
} else {
|
|
131
|
+
textAlign(CENTER, CENTER);
|
|
132
|
+
text('MOBILE INTERACTION', width / 2, dividerY + 30);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Instructions or acceleration values
|
|
136
|
+
if (window.sensorsEnabled) {
|
|
137
|
+
drawAccelerationDisplay();
|
|
138
|
+
} else {
|
|
139
|
+
fill(255, 255, 255, 200);
|
|
140
|
+
textSize(16);
|
|
141
|
+
textAlign(CENTER, CENTER);
|
|
142
|
+
text('Tap to enable device acceleration!', width / 2, dividerY + 80);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function drawDivider() {
|
|
147
|
+
// Draw divider line
|
|
148
|
+
stroke(255, 255, 255, 100);
|
|
149
|
+
strokeWeight(2);
|
|
150
|
+
line(0, dividerY, width, dividerY);
|
|
151
|
+
noStroke();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function drawSlider(index) {
|
|
155
|
+
let slider = sliders[index];
|
|
156
|
+
if (!slider) return;
|
|
157
|
+
|
|
158
|
+
// Slider track
|
|
159
|
+
fill(100, 100, 100);
|
|
160
|
+
noStroke();
|
|
161
|
+
rect(slider.x, slider.y, sliderWidth, sliderHeight, 15);
|
|
162
|
+
|
|
163
|
+
// Slider fill
|
|
164
|
+
fill(sliderColors[index]);
|
|
165
|
+
let fillWidth = sliderValues[index] * sliderWidth;
|
|
166
|
+
rect(slider.x, slider.y, fillWidth, sliderHeight, 15);
|
|
167
|
+
|
|
168
|
+
// Slider handle
|
|
169
|
+
fill(255, 255, 255);
|
|
170
|
+
let handleX = slider.x + (sliderValues[index] * sliderWidth);
|
|
171
|
+
circle(handleX, slider.y + sliderHeight / 2, sliderHeight + 10);
|
|
172
|
+
|
|
173
|
+
// Label
|
|
174
|
+
fill(255, 255, 255);
|
|
175
|
+
textAlign(LEFT, CENTER);
|
|
176
|
+
textSize(16);
|
|
177
|
+
text(sliderLabels[index], slider.x, slider.y - 20);
|
|
178
|
+
|
|
179
|
+
// Value
|
|
180
|
+
textAlign(RIGHT, CENTER);
|
|
181
|
+
textSize(14);
|
|
182
|
+
text((sliderValues[index] * 255).toFixed(0), slider.x + sliderWidth, slider.y - 20);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function drawAccelerationDisplay() {
|
|
186
|
+
fill(255, 255, 255);
|
|
187
|
+
textAlign(CENTER, CENTER);
|
|
188
|
+
textSize(18);
|
|
189
|
+
|
|
190
|
+
let startY = dividerY + 80;
|
|
191
|
+
|
|
192
|
+
text('Move or shake your device!', width / 2, startY);
|
|
193
|
+
|
|
194
|
+
textSize(20);
|
|
195
|
+
text('X: ' + accelerationValues[0].toFixed(1), width / 2, startY + 40);
|
|
196
|
+
text('Y: ' + accelerationValues[1].toFixed(1), width / 2, startY + 70);
|
|
197
|
+
text('Z: ' + accelerationValues[2].toFixed(1), width / 2, startY + 100);
|
|
198
|
+
|
|
199
|
+
// Draw color preview from acceleration
|
|
200
|
+
let accelerationColor = color(
|
|
201
|
+
normalizedAcceleration[0] * 255,
|
|
202
|
+
normalizedAcceleration[1] * 255,
|
|
203
|
+
normalizedAcceleration[2] * 255
|
|
204
|
+
);
|
|
205
|
+
fill(accelerationColor);
|
|
206
|
+
noStroke();
|
|
207
|
+
rect(width / 2 - 100, startY + 130, 200, 40);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function updateAccelerationValues() {
|
|
211
|
+
if (window.sensorsEnabled) {
|
|
212
|
+
// Get acceleration values from p5.js
|
|
213
|
+
accelerationValues[0] = accelerationX || 0;
|
|
214
|
+
accelerationValues[1] = accelerationY || 0;
|
|
215
|
+
accelerationValues[2] = accelerationZ || 0;
|
|
216
|
+
|
|
217
|
+
// Normalize acceleration values to 0.0-1.0 range
|
|
218
|
+
// Acceleration values typically range from -10 to +10 (in m/s²)
|
|
219
|
+
// Map from -10 to +10 to 0.0 to 1.0
|
|
220
|
+
normalizedAcceleration[0] = map(accelerationValues[0], -10, 10, 0.0, 1.0);
|
|
221
|
+
normalizedAcceleration[1] = map(accelerationValues[1], -10, 10, 0.0, 1.0);
|
|
222
|
+
normalizedAcceleration[2] = map(accelerationValues[2], -10, 10, 0.0, 1.0);
|
|
223
|
+
|
|
224
|
+
// Constrain to 0.0-1.0 range
|
|
225
|
+
normalizedAcceleration[0] = constrain(normalizedAcceleration[0], 0.0, 1.0);
|
|
226
|
+
normalizedAcceleration[1] = constrain(normalizedAcceleration[1], 0.0, 1.0);
|
|
227
|
+
normalizedAcceleration[2] = constrain(normalizedAcceleration[2], 0.0, 1.0);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Slider helper functions
|
|
232
|
+
function updateSliderPositions() {
|
|
233
|
+
sliders = [];
|
|
234
|
+
let startY = 70;
|
|
235
|
+
|
|
236
|
+
for (let i = 0; i < 3; i++) {
|
|
237
|
+
let slider = {
|
|
238
|
+
x: currentOrientation === 'landscape' ? 30 : (width - sliderWidth) / 2,
|
|
239
|
+
y: startY + (i * sliderSpacing),
|
|
240
|
+
width: sliderWidth,
|
|
241
|
+
height: sliderHeight
|
|
242
|
+
};
|
|
243
|
+
sliders.push(slider);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function isSliderPressed(sliderIndex, x, y) {
|
|
248
|
+
let slider = sliders[sliderIndex];
|
|
249
|
+
if (!slider) return false;
|
|
250
|
+
|
|
251
|
+
return (x >= slider.x && x <= slider.x + slider.width &&
|
|
252
|
+
y >= slider.y && y <= slider.y + slider.height);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function updateSliderValue(sliderIndex, x) {
|
|
256
|
+
let slider = sliders[sliderIndex];
|
|
257
|
+
if (!slider) return;
|
|
258
|
+
|
|
259
|
+
let normalizedX = (x - slider.x) / slider.width;
|
|
260
|
+
normalizedX = constrain(normalizedX, 0, 1);
|
|
261
|
+
|
|
262
|
+
sliderValues[sliderIndex] = map(normalizedX, 0, 1, sliderMin, sliderMax);
|
|
263
|
+
sliderValues[sliderIndex] = constrain(sliderValues[sliderIndex], sliderMin, sliderMax);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Handle touch interaction for mobile
|
|
267
|
+
function touchStarted() {
|
|
268
|
+
// Check all sliders for touch in top section
|
|
269
|
+
if (touches && touches.length >= 1) {
|
|
270
|
+
for (let touch of touches) {
|
|
271
|
+
if (touch && touch.y < dividerY) {
|
|
272
|
+
for (let i = 0; i < 3; i++) {
|
|
273
|
+
if (isSliderPressed(i, touch.x, touch.y)) {
|
|
274
|
+
isDraggingSlider = i;
|
|
275
|
+
updateSliderValue(i, touch.x);
|
|
276
|
+
return false; // Only prevent default if we actually handled a slider
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
// Don't prevent default if we didn't handle the touch - this allows overlay clicks to work
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function touchMoved() {
|
|
286
|
+
// Update slider if dragging
|
|
287
|
+
if (isDraggingSlider !== -1 && touches && touches.length >= 1) {
|
|
288
|
+
for (let touch of touches) {
|
|
289
|
+
if (touch && touch.y < dividerY) {
|
|
290
|
+
updateSliderValue(isDraggingSlider, touch.x);
|
|
291
|
+
return false; // Only prevent default when actively dragging
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
// Don't prevent default if we're not dragging
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function touchEnded() {
|
|
299
|
+
// Check if any touches remain in slider area
|
|
300
|
+
if (isDraggingSlider !== -1) {
|
|
301
|
+
let sliderTouchExists = false;
|
|
302
|
+
if (touches && touches.length > 0) {
|
|
303
|
+
for (let touch of touches) {
|
|
304
|
+
if (touch && touch.y < dividerY && isSliderPressed(isDraggingSlider, touch.x, touch.y)) {
|
|
305
|
+
sliderTouchExists = true;
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (!sliderTouchExists) {
|
|
311
|
+
isDraggingSlider = -1;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
// Don't prevent default - allow other handlers to process the event
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Handle mouse interaction for desktop testing
|
|
318
|
+
function mousePressed() {
|
|
319
|
+
if (mouseY < dividerY) {
|
|
320
|
+
for (let i = 0; i < 3; i++) {
|
|
321
|
+
if (isSliderPressed(i, mouseX, mouseY)) {
|
|
322
|
+
isDraggingSlider = i;
|
|
323
|
+
updateSliderValue(i, mouseX);
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function mouseDragged() {
|
|
331
|
+
if (isDraggingSlider !== -1) {
|
|
332
|
+
updateSliderValue(isDraggingSlider, mouseX);
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function mouseReleased() {
|
|
338
|
+
isDraggingSlider = -1;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function updateOrientation() {
|
|
342
|
+
currentOrientation = (width > height) ? 'landscape' : 'portrait';
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function updateLayout() {
|
|
346
|
+
topSectionHeight = height * 0.5;
|
|
347
|
+
bottomSectionHeight = height * 0.5;
|
|
348
|
+
dividerY = height * 0.5;
|
|
349
|
+
|
|
350
|
+
updateSliderPositions();
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function windowResized() {
|
|
354
|
+
resizeCanvas(windowWidth, windowHeight);
|
|
355
|
+
updateLayout();
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Called when permissions are ready
|
|
359
|
+
function userSetupComplete() {
|
|
360
|
+
console.log('Motion sensors enabled! You can now move or shake the device.');
|
|
361
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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>Device Rotation Values - 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://cdn.jsdelivr.net/npm/mobile-p5-permissions@1.4.4/dist/p5.mobile-permissions.min.js"></script>
|
|
23
|
+
<script src="sketch.js"></script>
|
|
24
|
+
</body>
|
|
25
|
+
</html>
|