-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.js
More file actions
60 lines (40 loc) · 1.18 KB
/
models.js
File metadata and controls
60 lines (40 loc) · 1.18 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
class Blob {
constructor(x, y){
this.minx = x;
this.miny = y;
this.maxx = x;
this.maxy = y;
}
add(x, y){
this.minx = min(this.minx, x);
this.miny = min(this.miny, y);
this.maxx = max(this.maxx, x);
this.maxy = max(this.maxy, y);
}
isNear(x, y){
//clamp
let clampedx = max(min(x, this.maxx), this.minx)
let clampedy = max(min(y, this.maxy), this.miny);
let d = distance(clampedx, clampedy, x, y);
return d < Math.pow(distanceFromBlobThreshold, 2);
}
x(){
return (this.minx + this.maxx) / 2;
}
y(){
return (this.miny + this.maxy) / 2;
}
getSize(){
return (this.maxx - this.minx) * (this.maxy - this.miny);
}
showWithStaticSize(){
drawCircle(this.x(), this.y(), 25, false);
}
showWithDynamicSize(){
let radius = max(20, min(Math.sqrt(this.getSize())/2, 500));
drawCircle(this.x(), this.y(), radius, false);
}
showWithDynamicSizeRectangle(){
drawRect(this.minx, this.miny, this.maxx - this.minx, this.maxy - this.miny);
}
}