-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path8.collectPoints.js
More file actions
34 lines (29 loc) · 1 KB
/
8.collectPoints.js
File metadata and controls
34 lines (29 loc) · 1 KB
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
/**
* In this example we start collecting X,Y point from the mouse clicks.
* We store them in global variables X,Y as normalised values, instead of (22,333) it will be something like (0.1212, 0.21212) with the max height as 1 and the max width as 1
*/
// This will store mouse x,y points that have been scaled from 0->1
let Xs = [];
let Ys = [];
// This scales a value from 0 to max to 0 to 1
const norm = (x, max) => map(x, 0, max, 0, 1);
const normX = x => norm(x, windowWidth);
const normY = x => norm(x, windowHeight);
// This scales a value from 0 to 1 to 0 to max
const denorm = (x, max) => map(x, 0, 1, 0, max);
const denormX = x => denorm(x, windowWidth);
const denormY = x => denorm(x, windowHeight);
function setup() {
createCanvas(windowWidth, windowHeight);
}
/*
This function is called every time a mouse is clicked.
*/
function mouseClicked() {
console.log("Clicked", `${mouseX}, ${mouseY}`);
const x = normX(mouseX);
const y = normY(mouseY);
Xs.push(x);
Ys.push(y);
console.log([Xs, Ys]);
}