-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
56 lines (48 loc) · 1.27 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
let front;
let back;
let usingSensor = false;
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
front = loadImage("veta.jpg");
back = loadImage("back.jpg");
// Check if running on a mobile device
if (navigator.userAgent.match(/Android|iPhone|iPad|iPod/i)) {
usingSensor = true;
// Set fullscreen on mobile devices
let canvas = document.querySelector('canvas');
canvas.requestFullscreen();
}
}
function draw() {
background(0);
imageMode(CENTER);
rotateY(QUARTER_PI);
if (usingSensor) {
rotateX(radians(touchRotationY));
rotateY(radians(touchRotationX));
} else {
rotateX(radians(mouseY));
rotateY(radians(mouseX));
}
image(front, 0, 0);
translate(0, 0, 1);
image(back, 0, 0);
}
// Phone orientation event listener and variables
let touchRotationX = 0;
let touchRotationY = 0;
let touchStartX = 0;
let touchStartY = 0;
function touchStarted() {
touchStartX = touches[0].x;
touchStartY = touches[0].y;
}
function touchMoved() {
const dx = touches[0].x - touchStartX;
const dy = touches[0].y - touchStartY;
touchRotationX += map(dx, 0, width, 0, 360);
touchRotationY += map(dy, 0, height, 0, 360);
touchStartX = touches[0].x;
touchStartY = touches[0].y;
return false; // Prevent default touch behavior
}