-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColor.pde
More file actions
99 lines (85 loc) · 2.63 KB
/
Copy pathColor.pde
File metadata and controls
99 lines (85 loc) · 2.63 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
public class PaletteManager
{
public int LIGHT = #ff96f1;
public int MEDIUM = #6971d0;
public int DARK = #1164b6;
public int DARKER = #2e3192;
public int BRIGHT = #ed145b;
PImage palette;
int totalFrames;
int column; // 0-4
float fade;
public PaletteManager(PImage p_in) {
palette = p_in;
totalFrames = 0;
column = 0;
fade = 0;
}
public PaletteManager(PImage p_in, int f) {
palette = p_in;
totalFrames = f;
column = 0;
fade = 0;
}
public void evolve(int i) {
palette.loadPixels();
if (totalFrames > palette.width) {
//fade+= 1/320.; //1000
if (frameCount >= 50)
fade+= 1/330.; //1000
if (fade > 1) {
fade = 0;
column += 1;
}
if (column > palette.width-1) {
column = palette.width-1;
fade = 1;
}
//println(i + " " + fade + " " + column);
int thisLight = palette.pixels[column];
int thisMed = palette.pixels[column + palette.width];
int thisDark = palette.pixels[column + palette.width*2];
int thisDarkr = palette.pixels[column + palette.width*3];
int nextLight = thisLight;
int nextMed = thisMed;
int nextDark = thisDark;
int nextDarkr = thisDarkr;
if (column < palette.width-1) {
nextLight = palette.pixels[column+1];
nextMed =palette.pixels[column + 1 + palette.width];
nextDark = palette.pixels[column + 1 + palette.width*2];
nextDarkr = palette.pixels[column + 1 + palette.width*3];
}
LIGHT = lerpColor(thisLight, nextLight, fade);
MEDIUM = lerpColor(thisMed, nextMed , fade);
DARK = lerpColor(thisDark, nextDark, fade);
DARKER = lerpColor(thisDarkr, nextDarkr, fade);
} else {
LIGHT = palette.pixels[column];
MEDIUM = palette.pixels[column + palette.width];
DARK = palette.pixels[column+ palette.width*2];
DARKER = palette.pixels[column+ palette.width*3];
}
}
}
void setGradient(float x, float y, float w, float h, color c1, color c2, int axis ) {
setGradient(int(x), int(y), w, h, c1, c2, axis);
}
void setGradient(int x, int y, float w, float h, color c1, color c2, int axis ) {
noFill();
if (axis == Y_AXIS) { // Top to bottom gradient
for (int i = y; i <= y+h; i++) {
float inter = map(i, y, y+h, 0, 1);
color c = lerpColor(c1, c2, inter);
stroke(c);
line(x, i, x+w, i);
}
} else if (axis == X_AXIS) { // Left to right gradient
for (int i = x; i <= x+w; i++) {
float inter = map(i, x, x+w, 0, 1);
color c = lerpColor(c1, c2, inter);
stroke(c);
line(i, y, i, y+h);
}
}
}