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.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +509 -0
  3. package/dist/p5-phone.js +1062 -0
  4. package/dist/p5-phone.min.js +10 -0
  5. package/examples/Phone Sensor Examples/microphone/01_mic_level/index.html +19 -0
  6. package/examples/Phone Sensor Examples/microphone/01_mic_level/sketch.js +117 -0
  7. package/examples/Phone Sensor Examples/movement/01_orientation_basic/index.html +28 -0
  8. package/examples/Phone Sensor Examples/movement/01_orientation_basic/sketch.js +123 -0
  9. package/examples/Phone Sensor Examples/movement/02_rotational_velocity/index.html +28 -0
  10. package/examples/Phone Sensor Examples/movement/02_rotational_velocity/sketch.js +144 -0
  11. package/examples/Phone Sensor Examples/movement/03_acceleration/index.html +28 -0
  12. package/examples/Phone Sensor Examples/movement/03_acceleration/sketch.js +87 -0
  13. package/examples/Phone Sensor Examples/sound/01_dual_audio/index.html +31 -0
  14. package/examples/Phone Sensor Examples/sound/01_dual_audio/sketch.js +225 -0
  15. package/examples/Phone Sensor Examples/sound/01_dual_audio/tracks/audio1.mp3 +0 -0
  16. package/examples/Phone Sensor Examples/sound/01_dual_audio/tracks/audio2.mp3 +0 -0
  17. package/examples/Phone Sensor Examples/sound/02_volume_touches/index.html +31 -0
  18. package/examples/Phone Sensor Examples/sound/02_volume_touches/sketch.js +269 -0
  19. package/examples/Phone Sensor Examples/sound/02_volume_touches/tracks/audio1.mp3 +0 -0
  20. package/examples/Phone Sensor Examples/touch/01_touch_basic/index.html +28 -0
  21. package/examples/Phone Sensor Examples/touch/01_touch_basic/sketch.js +94 -0
  22. package/examples/Phone Sensor Examples/touch/02_touch_zones/index.html +28 -0
  23. package/examples/Phone Sensor Examples/touch/02_touch_zones/sketch.js +220 -0
  24. package/examples/Phone Sensor Examples/touch/03_touch_count/index.html +28 -0
  25. package/examples/Phone Sensor Examples/touch/03_touch_count/sketch.js +93 -0
  26. package/examples/Phone Sensor Examples/touch/04_touch_distance/index.html +28 -0
  27. package/examples/Phone Sensor Examples/touch/04_touch_distance/sketch.js +120 -0
  28. package/examples/Phone Sensor Examples/touch/05_touch_angle/index.html +28 -0
  29. package/examples/Phone Sensor Examples/touch/05_touch_angle/sketch.js +117 -0
  30. package/examples/Phone Sensor Examples - Minimal/microphone/01_mic_level/index.html +19 -0
  31. package/examples/Phone Sensor Examples - Minimal/microphone/01_mic_level/sketch.js +72 -0
  32. package/examples/Phone Sensor Examples - Minimal/movement/01_orientation_basic/index.html +18 -0
  33. package/examples/Phone Sensor Examples - Minimal/movement/01_orientation_basic/sketch.js +51 -0
  34. package/examples/Phone Sensor Examples - Minimal/movement/02_rotational_velocity/index.html +18 -0
  35. package/examples/Phone Sensor Examples - Minimal/movement/02_rotational_velocity/sketch.js +70 -0
  36. package/examples/Phone Sensor Examples - Minimal/movement/03_acceleration/index.html +18 -0
  37. package/examples/Phone Sensor Examples - Minimal/movement/03_acceleration/sketch.js +83 -0
  38. package/examples/Phone Sensor Examples - Minimal/sound/01_sound_basic/index.html +19 -0
  39. package/examples/Phone Sensor Examples - Minimal/sound/01_sound_basic/sketch.js +96 -0
  40. package/examples/Phone Sensor Examples - Minimal/sound/01_sound_basic/tracks/audio1.mp3 +0 -0
  41. package/examples/Phone Sensor Examples - Minimal/sound/02_sound_amplitude/index.html +19 -0
  42. package/examples/Phone Sensor Examples - Minimal/sound/02_sound_amplitude/sketch.js +118 -0
  43. package/examples/Phone Sensor Examples - Minimal/sound/02_sound_amplitude/tracks/audio1.mp3 +0 -0
  44. package/examples/Phone Sensor Examples - Minimal/touch/01_touch_basic/index.html +18 -0
  45. package/examples/Phone Sensor Examples - Minimal/touch/01_touch_basic/sketch.js +58 -0
  46. package/examples/Phone Sensor Examples - Minimal/touch/02_touch_zones/index.html +18 -0
  47. package/examples/Phone Sensor Examples - Minimal/touch/02_touch_zones/sketch.js +78 -0
  48. package/examples/Phone Sensor Examples - Minimal/touch/03_touch_count/index.html +18 -0
  49. package/examples/Phone Sensor Examples - Minimal/touch/03_touch_count/sketch.js +64 -0
  50. package/examples/Phone Sensor Examples - Minimal/touch/04_touch_distance/index.html +18 -0
  51. package/examples/Phone Sensor Examples - Minimal/touch/04_touch_distance/sketch.js +69 -0
  52. package/examples/Phone Sensor Examples - Minimal/touch/05_touch_angle/index.html +18 -0
  53. package/examples/Phone Sensor Examples - Minimal/touch/05_touch_angle/sketch.js +85 -0
  54. package/examples/Phone and Gif/collision/README.md +31 -0
  55. Gif/collision/gifs/spaceSuit2.png +0 -0
  56. package/examples/Phone and Gif/collision/index.html +19 -0
  57. package/examples/Phone and Gif/collision/sketch.js +226 -0
  58. Gif/fetch/gifs/corgiswimflip.gif +0 -0
  59. package/examples/Phone and Gif/fetch/index.html +18 -0
  60. package/examples/Phone and Gif/fetch/sketch.js +139 -0
  61. Gif/fly/gifs/comparison.gif +0 -0
  62. package/examples/Phone and Gif/fly/index.html +18 -0
  63. package/examples/Phone and Gif/fly/sketch.js +103 -0
  64. Gif/roll/gifs/how-penciles-are-made.gif +0 -0
  65. package/examples/Phone and Gif/roll/index.html +18 -0
  66. package/examples/Phone and Gif/roll/sketch.js +121 -0
  67. package/examples/UXcompare/button-vs-movement/index.html +45 -0
  68. package/examples/UXcompare/button-vs-movement/sketch.js +355 -0
  69. package/examples/UXcompare/button-vs-orientation/index.html +25 -0
  70. package/examples/UXcompare/button-vs-orientation/sketch.js +317 -0
  71. package/examples/UXcompare/button-vs-shake/index.html +45 -0
  72. package/examples/UXcompare/button-vs-shake/sketch.js +320 -0
  73. package/examples/UXcompare/gyroscope-demo/index.html +78 -0
  74. package/examples/UXcompare/gyroscope-demo/sketch.js +166 -0
  75. package/examples/UXcompare/index.html +419 -0
  76. package/examples/UXcompare/microphone-demo/index.html +79 -0
  77. package/examples/UXcompare/microphone-demo/sketch.js +210 -0
  78. package/examples/UXcompare/slider-vs-angle/index.html +25 -0
  79. package/examples/UXcompare/slider-vs-angle/sketch.js +429 -0
  80. package/examples/UXcompare/slider-vs-distance/index.html +25 -0
  81. package/examples/UXcompare/slider-vs-distance/sketch.js +401 -0
  82. package/examples/UXcompare/slider-vs-microphone/index.html +26 -0
  83. package/examples/UXcompare/slider-vs-microphone/sketch.js +336 -0
  84. package/examples/UXcompare/slider-vs-touches/index.html +25 -0
  85. package/examples/UXcompare/slider-vs-touches/sketch.js +376 -0
  86. package/examples/UXcompare/sliders-vs-acceleration/index.html +25 -0
  87. package/examples/UXcompare/sliders-vs-acceleration/sketch.js +361 -0
  88. package/examples/UXcompare/sliders-vs-rotation/index.html +25 -0
  89. package/examples/UXcompare/sliders-vs-rotation/sketch.js +375 -0
  90. package/examples/blankTemplate/index.html +31 -0
  91. package/examples/blankTemplate/sketch.js +55 -0
  92. package/examples/homepage/index.html +506 -0
  93. package/package.json +73 -0
  94. package/src/p5-phone.js +1062 -0
  95. package/src/permissionMic.js +240 -0
  96. package/src/permissionsGesture.js +213 -0
  97. package/src/permissionsGyro.js +246 -0
@@ -0,0 +1,220 @@
1
+ // ==============================================
2
+ // TOUCH ZONES EXAMPLE
3
+ // ==============================================
4
+ // This example splits the screen into 4 zones
5
+ // Each zone detects touches and counts them separately
6
+ //
7
+ // CONCEPTS COVERED:
8
+ // - Touch position detection
9
+ // - Zone-based interaction
10
+ // - Multiple counters
11
+ // - Conditional logic for zones
12
+ // ==============================================
13
+
14
+ // Variables for each zone's state
15
+ let zone1Touched = false; // Top-left zone
16
+ let zone2Touched = false; // Top-right zone
17
+ let zone3Touched = false; // Bottom-left zone
18
+ let zone4Touched = false; // Bottom-right zone
19
+
20
+ // Counter for each zone
21
+ let zone1Counter = 0;
22
+ let zone2Counter = 0;
23
+ let zone3Counter = 0;
24
+ let zone4Counter = 0;
25
+
26
+ // ==============================================
27
+ // SETUP FUNCTION - Runs once when page loads
28
+ // ==============================================
29
+ function setup()
30
+ {
31
+ // Create a canvas that fills the entire screen
32
+ createCanvas(windowWidth, windowHeight);
33
+
34
+ // Lock mobile gestures to prevent scrolling, zooming, etc.
35
+ lockGestures();
36
+
37
+ // Set text properties
38
+ textAlign(CENTER, CENTER);
39
+ textSize(24);
40
+ }
41
+
42
+ // ==============================================
43
+ // DRAW FUNCTION - Runs continuously
44
+ // ==============================================
45
+ function draw()
46
+ {
47
+ background(240, 240, 240); // Light gray background
48
+
49
+ // Draw lines to divide screen into 4 zones
50
+ stroke(100, 100, 100); // Gray lines
51
+ strokeWeight(2);
52
+
53
+ // Vertical line (middle of screen)
54
+ line(width/2, 0, width/2, height);
55
+ // Horizontal line (middle of screen)
56
+ line(0, height/2, width, height/2);
57
+
58
+ // ==============================================
59
+ // ZONE 1 - TOP LEFT
60
+ // ==============================================
61
+ if (zone1Touched)
62
+ {
63
+ fill(200, 255, 200); // Light green when touched
64
+ rect(0, 0, width/2, height/2);
65
+ fill(0, 100, 0); // Dark green text
66
+ text("TOUCHED", width/4, height/4 - 20);
67
+ }
68
+ else
69
+ {
70
+ fill(255, 255, 255); // White when not touched
71
+ rect(0, 0, width/2, height/2);
72
+ fill(100, 100, 100); // Gray text
73
+ text("NOT TOUCHED", width/4, height/4 - 20);
74
+ }
75
+ fill(50, 50, 50); // Dark text for counter
76
+ text("Count: " + zone1Counter, width/4, height/4 + 20);
77
+
78
+ // ==============================================
79
+ // ZONE 2 - TOP RIGHT
80
+ // ==============================================
81
+ if (zone2Touched)
82
+ {
83
+ fill(255, 200, 200); // Light red when touched
84
+ rect(width/2, 0, width/2, height/2);
85
+ fill(150, 0, 0); // Dark red text
86
+ text("TOUCHED", width/2 + width/4, height/4 - 20);
87
+ }
88
+ else
89
+ {
90
+ fill(255, 255, 255); // White when not touched
91
+ rect(width/2, 0, width/2, height/2);
92
+ fill(100, 100, 100); // Gray text
93
+ text("NOT TOUCHED", width/2 + width/4, height/4 - 20);
94
+ }
95
+ fill(50, 50, 50); // Dark text for counter
96
+ text("Count: " + zone2Counter, width/2 + width/4, height/4 + 20);
97
+
98
+ // ==============================================
99
+ // ZONE 3 - BOTTOM LEFT
100
+ // ==============================================
101
+ if (zone3Touched)
102
+ {
103
+ fill(200, 200, 255); // Light blue when touched
104
+ rect(0, height/2, width/2, height/2);
105
+ fill(0, 0, 150); // Dark blue text
106
+ text("TOUCHED", width/4, height/2 + height/4 - 20);
107
+ }
108
+ else
109
+ {
110
+ fill(255, 255, 255); // White when not touched
111
+ rect(0, height/2, width/2, height/2);
112
+ fill(100, 100, 100); // Gray text
113
+ text("NOT TOUCHED", width/4, height/2 + height/4 - 20);
114
+ }
115
+ fill(50, 50, 50); // Dark text for counter
116
+ text("Count: " + zone3Counter, width/4, height/2 + height/4 + 20);
117
+
118
+ // ==============================================
119
+ // ZONE 4 - BOTTOM RIGHT
120
+ // ==============================================
121
+ if (zone4Touched)
122
+ {
123
+ fill(255, 255, 200); // Light yellow when touched
124
+ rect(width/2, height/2, width/2, height/2);
125
+ fill(150, 150, 0); // Dark yellow text
126
+ text("TOUCHED", width/2 + width/4, height/2 + height/4 - 20);
127
+ }
128
+ else
129
+ {
130
+ fill(255, 255, 255); // White when not touched
131
+ rect(width/2, height/2, width/2, height/2);
132
+ fill(100, 100, 100); // Gray text
133
+ text("NOT TOUCHED", width/2 + width/4, height/2 + height/4 - 20);
134
+ }
135
+ fill(50, 50, 50); // Dark text for counter
136
+ text("Count: " + zone4Counter, width/2 + width/4, height/2 + height/4 + 20);
137
+ }
138
+
139
+ // ==============================================
140
+ // HELPER FUNCTION - Which zone was touched?
141
+ // ==============================================
142
+ function getZone(x, y)
143
+ {
144
+ // This function takes an x and y position and figures out
145
+ // which of the 4 zones that position falls into
146
+
147
+ // Set the division points - these variables make it easy to change later
148
+ let xDivision = width / 2; // Where to split left/right (middle of screen)
149
+ let yDivision = height / 2; // Where to split top/bottom (middle of screen)
150
+
151
+ // We divide the screen into 4 equal rectangles:
152
+ // - Left half vs Right half (check if x < xDivision)
153
+ // - Top half vs Bottom half (check if y < yDivision)
154
+
155
+ // Check if touch is in the LEFT half of screen
156
+ if (x < xDivision && y < yDivision)
157
+ {
158
+ return 1; // Top-left zone
159
+ }
160
+ else if (x >= xDivision && y < yDivision)
161
+ {
162
+ return 2; // Top-right zone (x is >= middle, y is < middle)
163
+ }
164
+ else if (x < xDivision && y >= yDivision)
165
+ {
166
+ return 3; // Bottom-left zone (x is < middle, y is >= middle)
167
+ }
168
+ else
169
+ {
170
+ return 4; // Bottom-right zone (everything else)
171
+ }
172
+ }
173
+
174
+ // ==============================================
175
+ // TOUCH EVENT FUNCTIONS
176
+ // ==============================================
177
+
178
+ // This function runs when a touch begins
179
+ function touchStarted()
180
+ {
181
+ // Find out which zone was touched
182
+ let touchedZone = getZone(touches[0].x, touches[0].y);
183
+
184
+ // Update the correct zone
185
+ if (touchedZone == 1)
186
+ {
187
+ zone1Touched = true;
188
+ zone1Counter = zone1Counter + 1;
189
+ }
190
+ else if (touchedZone == 2)
191
+ {
192
+ zone2Touched = true;
193
+ zone2Counter = zone2Counter + 1;
194
+ }
195
+ else if (touchedZone == 3)
196
+ {
197
+ zone3Touched = true;
198
+ zone3Counter = zone3Counter + 1;
199
+ }
200
+ else if (touchedZone == 4)
201
+ {
202
+ zone4Touched = true;
203
+ zone4Counter = zone4Counter + 1;
204
+ }
205
+
206
+ return false; // Prevent default browser behavior
207
+ }
208
+
209
+ // This function runs when a touch ends
210
+ function touchEnded()
211
+ {
212
+ // Reset all zones to not touched
213
+ zone1Touched = false;
214
+ zone2Touched = false;
215
+ zone3Touched = false;
216
+ zone4Touched = false;
217
+
218
+ return false;
219
+ }
220
+
@@ -0,0 +1,28 @@
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">
6
+ <title>Touch Count - Mobile p5.js</title>
7
+
8
+ <!-- Basic CSS to remove browser defaults and align canvas -->
9
+ <style>
10
+ body {
11
+ margin: 0;
12
+ padding: 0;
13
+ overflow: hidden;
14
+ }
15
+ </style>
16
+
17
+ <!-- Load p5.js library -->
18
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.10/p5.min.js"></script>
19
+
20
+ <!-- Load the mobile p5.js permissions library -->
21
+ <script src="https://cdn.jsdelivr.net/npm/mobile-p5-permissions@1.4.4/dist/p5.mobile-permissions.min.js"></script>
22
+
23
+ </head>
24
+ <body>
25
+ <!-- Load the p5.js sketch -->
26
+ <script src="sketch.js"></script>
27
+ </body>
28
+ </html>
@@ -0,0 +1,93 @@
1
+ // ==============================================
2
+ // TOUCH COUNT EXAMPLE
3
+ // ==============================================
4
+ // This example counts how many fingers are
5
+ // currently touching the screen at the same time
6
+ //
7
+ // CONCEPTS COVERED:
8
+ // - Multi-touch detection
9
+ // - touches array
10
+ // - Real-time touch counting
11
+ // - Simple display of numbers
12
+ //
13
+ // HARDWARE LIMITATIONS:
14
+ // - iPhone: Usually max 5 simultaneous touches
15
+ // - iPad: Usually max 10-11 simultaneous touches
16
+ // - Android: Varies by device (typically 5-10)
17
+
18
+ // ==============================================
19
+
20
+ // Variables to store touch information
21
+ let currentTouchCount = 0; // How many fingers are touching right now
22
+ let previousTouchCount = 0; // Previous number of touches to detect changes
23
+ let backgroundColor = [255, 255, 255]; // Current background color [red, green, blue]
24
+
25
+ // ==============================================
26
+ // SETUP FUNCTION - Runs once when page loads
27
+ // ==============================================
28
+ function setup()
29
+ {
30
+ // Create a canvas that fills the entire screen
31
+ createCanvas(windowWidth, windowHeight);
32
+
33
+ // Lock mobile gestures to prevent scrolling, zooming, etc.
34
+ lockGestures();
35
+
36
+ // Set text properties
37
+ textAlign(CENTER, CENTER);
38
+ textSize(48);
39
+ }
40
+
41
+ // ==============================================
42
+ // DRAW FUNCTION - Runs continuously
43
+ // ==============================================
44
+ function draw()
45
+ {
46
+ // Always check the actual number of current touches for accuracy
47
+ currentTouchCount = touches.length;
48
+
49
+ // Check if the number of touches has changed
50
+ if (currentTouchCount != previousTouchCount)
51
+ {
52
+ // Generate a new random background color
53
+ backgroundColor[0] = random(150, 255); // Red component
54
+ backgroundColor[1] = random(150, 255); // Green component
55
+ backgroundColor[2] = random(150, 255); // Blue component
56
+
57
+ // Update previous count to current count
58
+ previousTouchCount = currentTouchCount;
59
+ }
60
+
61
+ // Use the stored background color
62
+ background(backgroundColor[0], backgroundColor[1], backgroundColor[2]);
63
+
64
+ // Display current touch count (big number in center)
65
+ fill(50, 50, 50);
66
+ textSize(120);
67
+ text(currentTouchCount, width/2, height/2);
68
+
69
+ // Display label
70
+ textSize(32);
71
+ text("Current Touches", width/2, height/2 + 100);
72
+
73
+
74
+ }
75
+
76
+ // ==============================================
77
+ // TOUCH EVENT FUNCTIONS
78
+ // ==============================================
79
+
80
+ // This function runs when a new touch begins
81
+ function touchStarted()
82
+ {
83
+ // Touch count will be updated in draw() function
84
+ return false;
85
+ }
86
+
87
+ // This function runs when a touch ends
88
+ function touchEnded()
89
+ {
90
+ // Touch count will be updated in draw() function
91
+ return false;
92
+ }
93
+
@@ -0,0 +1,28 @@
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">
6
+ <title>Touch Distance - Mobile p5.js</title>
7
+
8
+ <!-- Basic CSS to remove browser defaults and align canvas -->
9
+ <style>
10
+ body {
11
+ margin: 0;
12
+ padding: 0;
13
+ overflow: hidden;
14
+ }
15
+ </style>
16
+
17
+ <!-- Load p5.js library -->
18
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.10/p5.min.js"></script>
19
+
20
+ <!-- Load the mobile p5.js permissions library -->
21
+ <script src="https://cdn.jsdelivr.net/npm/mobile-p5-permissions@1.4.4/dist/p5.mobile-permissions.min.js"></script>
22
+
23
+ </head>
24
+ <body>
25
+ <!-- Load the p5.js sketch -->
26
+ <script src="sketch.js"></script>
27
+ </body>
28
+ </html>
@@ -0,0 +1,120 @@
1
+ // ==============================================
2
+ // TOUCH DISTANCE EXAMPLE
3
+ // ==============================================
4
+ // This example measures the distance between
5
+ // the first 2 touches and displays the line
6
+ // with coordinates and distance
7
+ //
8
+ // CONCEPTS COVERED:
9
+ // - Multi-touch detection
10
+ // - Distance calculation using dist() function
11
+ // - Drawing lines between points
12
+ // - Displaying coordinates
13
+ // - Math.round() for cleaner numbers
14
+ // ==============================================
15
+
16
+ // Variables to store touch information
17
+ let touch1X = 0; // X position of first touch
18
+ let touch1Y = 0; // Y position of first touch
19
+ let touch2X = 0; // X position of second touch
20
+ let touch2Y = 0; // Y position of second touch
21
+ let touchDistance = 0; // Distance between the two touches
22
+
23
+
24
+ // ==============================================
25
+ // SETUP FUNCTION - Runs once when page loads
26
+ // ==============================================
27
+ function setup()
28
+ {
29
+ // Create a canvas that fills the entire screen
30
+ createCanvas(windowWidth, windowHeight);
31
+
32
+ // Lock mobile gestures to prevent scrolling, zooming, etc.
33
+ lockGestures();
34
+
35
+ // Set text properties
36
+ textAlign(CENTER, CENTER);
37
+ textSize(24);
38
+ }
39
+
40
+ // ==============================================
41
+ // DRAW FUNCTION - Runs continuously
42
+ // ==============================================
43
+ function draw()
44
+ {
45
+ // Clear the screen
46
+ background(240, 240, 240);
47
+
48
+ // Check if we have at least 2 touches
49
+ if (touches.length >= 2)
50
+ {
51
+
52
+
53
+ // Get the positions of the first 2 touches
54
+ touch1X = touches[0].x;
55
+ touch1Y = touches[0].y;
56
+ touch2X = touches[1].x;
57
+ touch2Y = touches[1].y;
58
+
59
+ // Calculate distance between the two touches
60
+ touchDistance = dist(touch1X, touch1Y, touch2X, touch2Y);
61
+
62
+ // Draw a line between the two touches
63
+ stroke(100, 100, 100);
64
+ strokeWeight(3);
65
+ line(touch1X, touch1Y, touch2X, touch2Y);
66
+
67
+ // Draw circles at each touch point
68
+ fill(255, 0, 0); // Red circles
69
+ noStroke();
70
+ circle(touch1X, touch1Y, 30);
71
+ circle(touch2X, touch2Y, 30);
72
+
73
+ // Draw distance text in the middle of the line
74
+ let midX = (touch1X + touch2X) / 2;
75
+ let midY = (touch1Y + touch2Y) / 2;
76
+
77
+ fill(0, 0, 0); // Black text
78
+ textSize(20);
79
+ text(Math.round(touchDistance) + " pixels", midX, midY - 30);
80
+
81
+ // Display coordinates at the top of screen
82
+ textAlign(LEFT, TOP);
83
+ textSize(18);
84
+ text("Touch 1: (" + Math.round(touch1X) + ", " + Math.round(touch1Y) + ")", 20, 20);
85
+ text("Touch 2: (" + Math.round(touch2X) + ", " + Math.round(touch2Y) + ")", 20, 50);
86
+ text("Distance: " + Math.round(touchDistance) + " pixels", 20, 80);
87
+
88
+ }
89
+ else
90
+ {
91
+ hasTwoTouches = false;
92
+
93
+ // Instructions when not enough touches
94
+ textAlign(CENTER, CENTER);
95
+ textSize(32);
96
+ fill(100, 100, 100);
97
+ text("Touch 2 points on the screen", width/2, height/2);
98
+
99
+
100
+ }
101
+ }
102
+
103
+ // ==============================================
104
+ // TOUCH EVENT FUNCTIONS
105
+ // ==============================================
106
+
107
+ // This function runs when a new touch begins
108
+ function touchStarted()
109
+ {
110
+ // Touch positions will be updated in draw() function
111
+ return false;
112
+ }
113
+
114
+ // This function runs when a touch ends
115
+ function touchEnded()
116
+ {
117
+ // Touch positions will be updated in draw() function
118
+ return false;
119
+ }
120
+
@@ -0,0 +1,28 @@
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">
6
+ <title>Touch Angle - Mobile p5.js</title>
7
+
8
+ <!-- Basic CSS to remove browser defaults and align canvas -->
9
+ <style>
10
+ body {
11
+ margin: 0;
12
+ padding: 0;
13
+ overflow: hidden;
14
+ }
15
+ </style>
16
+
17
+ <!-- Load p5.js library -->
18
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.10/p5.min.js"></script>
19
+
20
+ <!-- Load the mobile p5.js permissions library -->
21
+ <script src="https://cdn.jsdelivr.net/npm/mobile-p5-permissions@1.4.4/dist/p5.mobile-permissions.min.js"></script>
22
+
23
+ </head>
24
+ <body>
25
+ <!-- Load the p5.js sketch -->
26
+ <script src="sketch.js"></script>
27
+ </body>
28
+ </html>
@@ -0,0 +1,117 @@
1
+ // ==============================================
2
+ // TOUCH ANGLE EXAMPLE
3
+ // ==============================================
4
+ // This example measures the angle between
5
+ // the first 2 touches and displays the line
6
+ // with coordinates and angle
7
+ //
8
+ // CONCEPTS COVERED:
9
+ // - Multi-touch detection
10
+ // - Angle calculation using atan2() function
11
+ // - Converting radians to degrees
12
+ // - Drawing lines between points
13
+ // - Displaying coordinates
14
+ // - Math.round() for cleaner numbers
15
+ // ==============================================
16
+
17
+ // Variables to store touch information
18
+ let touch1X = 0; // X position of first touch
19
+ let touch1Y = 0; // Y position of first touch
20
+ let touch2X = 0; // X position of second touch
21
+ let touch2Y = 0; // Y position of second touch
22
+ let touchAngle = 0; // Angle between the two touches (in degrees)
23
+
24
+ // ==============================================
25
+ // SETUP FUNCTION - Runs once when page loads
26
+ // ==============================================
27
+ function setup()
28
+ {
29
+ // Create a canvas that fills the entire screen
30
+ createCanvas(windowWidth, windowHeight);
31
+
32
+ // Lock mobile gestures to prevent scrolling, zooming, etc.
33
+ lockGestures();
34
+
35
+ // Set text properties
36
+ textAlign(CENTER, CENTER);
37
+ textSize(24);
38
+ }
39
+
40
+ // ==============================================
41
+ // DRAW FUNCTION - Runs continuously
42
+ // ==============================================
43
+ function draw()
44
+ {
45
+ // Clear the screen
46
+ background(240, 240, 240);
47
+
48
+ // Check if we have at least 2 touches
49
+ if (touches.length >= 2)
50
+ {
51
+ // Get the positions of the first 2 touches
52
+ touch1X = touches[0].x;
53
+ touch1Y = touches[0].y;
54
+ touch2X = touches[1].x;
55
+ touch2Y = touches[1].y;
56
+
57
+ // Calculate angle between the two touches
58
+ // atan2 gives us the angle in radians, so we convert to degrees
59
+ let angleInRadians = atan2(touch2Y - touch1Y, touch2X - touch1X);
60
+ touchAngle = degrees(angleInRadians); // Convert to degrees
61
+
62
+ // Draw a line between the two touches
63
+ stroke(100, 100, 100);
64
+ strokeWeight(3);
65
+ line(touch1X, touch1Y, touch2X, touch2Y);
66
+
67
+ // Draw circles at each touch point
68
+ fill(255, 0, 0); // Red circles
69
+ noStroke();
70
+ circle(touch1X, touch1Y, 30);
71
+ circle(touch2X, touch2Y, 30);
72
+
73
+ // Draw angle text in the middle of the line
74
+ let midX = (touch1X + touch2X) / 2;
75
+ let midY = (touch1Y + touch2Y) / 2;
76
+
77
+ fill(0, 0, 0); // Black text
78
+ textSize(20);
79
+ text(Math.round(touchAngle) + "°", midX, midY - 30);
80
+
81
+ // Display coordinates and angle at the top of screen
82
+ textAlign(LEFT, TOP);
83
+ textSize(18);
84
+ text("Touch 1: (" + Math.round(touch1X) + ", " + Math.round(touch1Y) + ")", 20, 20);
85
+ text("Touch 2: (" + Math.round(touch2X) + ", " + Math.round(touch2Y) + ")", 20, 50);
86
+ text("Angle: " + Math.round(touchAngle) + "° (degrees)", 20, 80);
87
+
88
+ }
89
+ else
90
+ {
91
+ // Instructions when not enough touches
92
+ textAlign(CENTER, CENTER);
93
+ textSize(32);
94
+ fill(100, 100, 100);
95
+ text("Touch 2 points on the screen", width/2, height/2);
96
+ }
97
+ }
98
+
99
+ // ==============================================
100
+ // TOUCH EVENT FUNCTIONS
101
+ // ==============================================
102
+
103
+ // This function runs when a new touch begins
104
+ function touchStarted()
105
+ {
106
+ // Touch positions will be updated in draw() function
107
+ return false;
108
+ }
109
+
110
+ // This function runs when a touch ends
111
+ function touchEnded()
112
+ {
113
+ // Touch positions will be updated in draw() function
114
+ return false;
115
+ }
116
+
117
+
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>P5.js Mobile - Mic Level (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>