-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdata.js
More file actions
110 lines (101 loc) · 2.65 KB
/
data.js
File metadata and controls
110 lines (101 loc) · 2.65 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
class Data {
constructor(x, y) {
this.num = floor(random(10));
this.homeX = x;
this.homeY = y;
this.x = x;
this.y = y;
this.color = palette.FG; //TODO: pass this in as arg rather than global variable?
this.alpha = 255;
this.sz = baseSize;
this.refined = false;
this.binIt = false;
this.bin = undefined;
this.binPauseTime = 8;
this.binPause = this.binPauseTime;
}
refine(bin) {
this.binIt = true;
this.bin = bin;
}
goBin() {
// This is a band-aid
if (this.bin) {
this.bin.open();
if (this.binPause <= 0) {
const dx = this.bin.x - this.x;
const dy = this.bin.y - this.y;
let easing = map(abs(dy), this.bin.y, 0, 0.02, 0.1);
this.x += dx * easing;
this.y += max(dy * easing, -20);
this.alpha = map(this.y, this.homeY, this.bin.y, 255, 5);
this.bin.lastRefinedTime = millis();
} else {
this.binPause--;
}
if (dist(this.x, this.y, this.bin.x, this.bin.y) < 2) {
this.bin.addNumber();
this.num = floor(random(10));
this.x = this.homeX;
this.y = this.homeY;
this.refined = false;
this.binIt = false;
this.bin = undefined;
this.color = palette.FG;
this.alpha = 255;
this.binPause = this.binPauseTime;
}
}
}
goHome() {
this.x = lerp(this.x, this.homeX, 0.1);
this.y = lerp(this.y, this.homeY, 0.1);
this.sz = lerp(this.sz, baseSize, 0.1);
}
size(sz) {
this.sz = sz;
}
turn(newColor) {
this.color = newColor;
}
inside(x1, y1, x2, y2) {
return (
this.x > min(x1, x2) &&
this.x < max(x1, x2) &&
this.y > min(y1, y2) &&
this.y < max(y1, y2)
);
}
show() {
g.textFont('Courier');
const digitSize = this.binIt ? lerp(this.sz, baseSize * 2.5, map(this.binPause, this.binPauseTime, 0, 0, 1)) : this.sz;
g.textSize(digitSize);
g.textAlign(CENTER, CENTER);
if (typeof rainbowMode !== 'undefined' && rainbowMode) {
g.colorMode(HSB, 360, 100, 100, 255);
const hue = (frameCount * 3 + this.homeX + this.homeY) % 360;
const col = g.color(hue, 80, 100, this.alpha);
g.fill(col);
g.stroke(col);
} else {
const col = color(this.color);
col.setAlpha(this.alpha);
g.fill(col);
g.stroke(col);
}
if (g.width < 500) {
g.strokeWeight(0.8);
}
g.text(this.num, this.x, this.y);
if (g.width < 500) {
g.strokeWeight(1);
}
if (typeof rainbowMode !== 'undefined' && rainbowMode) {
g.colorMode(RGB);
}
}
resize(newX, newY) {
this.homeX = newX;
this.homeY = newY;
}
}