-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfield.js
More file actions
63 lines (48 loc) · 1.32 KB
/
Copy pathfield.js
File metadata and controls
63 lines (48 loc) · 1.32 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
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
class forceField{
constructor(resolution, globalX, globalY){
this.cols = width / resolution ;
this.rows = height / resolution;
this.res = resolution;
this.grid = [];
this.display = false;
this.warpDir = createVector(0,0);
for (let i = 0; i < this.cols; i++){
this.grid[i] = [];
for (let j = 0; j < this.rows; j++){
this.grid[i][j] = createVector(globalX, globalY);
}
}
}
show(){
stroke(255);
strokeWeight(1);
for (let i = 0; i < this.cols; i++){
stroke (127);
line(this.res * (i + 1), 0, this.res * (i+1), height);
for (let j = 0; j < this.rows; j++){
if(i == 0){
line(0, this.res * (j + 1), width, this.res * (j + 1));
}
point((i + 0.5) * this.res, (j + 0.5) * this.res);
line((i + 0.5) * this.res, (j + 0.5) * this.res, (i + 0.5) * this.res + this.grid[i][j].x, (j + 0.5) * this.res + this.grid[i][j].y);
}
}
}
warp(wx, wy, size, strength){
for (let i = 0; i < this.cols; i++){
for (let j = 0; j < this.rows; j++){
let warpVect = createVector(wx - (i + 0.5) * this.res, wy - (j + 0.5) * this.res);
if (warpVect.mag() < size){
this.grid[i][j] = warpVect.mult(strength / warpVect.mag() * 0.5);
}
}
}
}
reset(){
for (let i = 0; i < this.cols; i++){
for (let j = 0; j < this.rows; j++){
this.grid[i][j].mult(0);
}
}
}
}