-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
44 lines (35 loc) · 996 Bytes
/
utils.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
function pointAt(x, y) {
let obj = points[pointsY * y + x];
return obj;
}
function textureUV(x, y) {
return {
u: x / (pointsX - 1),
v: y / (pointsY - 1)
};
}
function isInsidePicture(x, y) {
let insideX = x > points[0].x && x < points[pointsX-1].x;
let insideY = y > points[0].y && y < points[points.length-1].y;
return insideX && insideY;
}
function drawShape() {
push();
textureMode(NORMAL);
texture(img);
for (let y = 0; y < pointsY; y++) {
beginShape(TRIANGLE_STRIP);
for (let x = 0; x < pointsX; x++) {
if (0 < y) {
let point = pointAt(x, y - 1);
let texUV = textureUV(x, y - 1);
vertex(point.x, point.y, 0, texUV.u, texUV.v);
let point2 = pointAt(x, y);
let texUV2 = textureUV(x, y);
vertex(point2.x, point2.y, 0, texUV2.u, texUV2.v);
}
}
endShape();
}
pop();
}