-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
66 lines (60 loc) · 1.81 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
57
58
59
60
61
62
63
64
65
66
// We make these global because multiple states need access to them
let camera;
let canvas;
let homography;
// These are global because they're used by both setup() and draw() below
let stateMachine;
let stateHandlers;
// p5.js runs this function once before calling draw(), below
async function setup() {
// future: it would be nice to automatically re-init the app when the window
// is resized instead of requiring the user to refresh the page
canvas = createCanvas(windowWidth, windowHeight);
stateHandlers = new Map([
["calibrating", drawCalibratingScreen],
[
"waitingForCalibrationAcceptance",
drawWaitingForCalibrationAcceptanceScreen,
],
["modelingPhysics", drawModelingPhysicsScreen],
]);
stateMachine = new StateMachine({
init: "calibrating",
transitions: [
{
name: "waitForCalibrationAcceptance",
from: "calibrating",
to: "waitingForCalibrationAcceptance",
},
{
name: "modelPhysics",
from: "waitingForCalibrationAcceptance",
to: "modelingPhysics",
},
{
name: "skipToModelingPhysics",
from: "calibrating",
to: "modelingPhysics",
},
],
methods: {
onWaitForCalibrationAcceptance: function () {
console.log("Transitioned to waitingForCalibrationAcceptance.");
},
onModelPhysics: function () {
console.log("Transitioned to modelingPhysics.");
},
onSkipToModelingPhysics: function () {
console.log("Transitioned to modelingPhysics");
},
},
});
}
// After setup() is run, p5.js calls this 60 times per second
async function draw() {
if (!stateMachine) {
return;
}
// Run the draw function for the particular state we're in
await stateHandlers.get(stateMachine.state)(stateMachine, window.p5.instance);
}