-
Notifications
You must be signed in to change notification settings - Fork 12
/
PixelColor.pde
86 lines (66 loc) · 2.03 KB
/
PixelColor.pde
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
static class PixelColorScheme {
public static int[] R = {};
public static int[] G = {};
public static int[] B = {};
}
class PixelColor {
public int r;
public int g;
public int b;
PixelColor() {
this(0,0,0);
}
PixelColor(int r, int g, int b) {
set_color(r,g,b);
}
public PixelColor next_color() {
this.set_color_index(this.to_int()+1);
return this;
}
public PixelColor previous_color() {
this.set_color_index(this.to_int()-1);
return this;
}
public int numColors() {
return PixelColorScheme.R.length * PixelColorScheme.G.length * PixelColorScheme.B.length;
}
public boolean equal(PixelColor pc) {
if(pc == null) return true;
return this.r == pc.r && this.g == pc.g && this.b == pc.b;
}
public void set_color(PixelColor pc) {
if(pc == null) return;
this.r = pc.r;
this.g = pc.g;
this.b = pc.b;
}
public void set_color(int _r, int _g, int _b) {
this.r = _r;
this.g = _g;
this.b = _b;
}
public void set_color_index(int i) {
i = i % numColors();
if(i < 0) i += numColors();
this.r = i / (PixelColorScheme.G.length * PixelColorScheme.B.length);
this.g = (i / PixelColorScheme.B.length) - (this.r * PixelColorScheme.G.length) ;
this.b = (i - (this.r * PixelColorScheme.G.length + this.g) * PixelColorScheme.B.length);
}
public void set_color(color c) {
int l_index = PixelColorScheme.R.length - 1;
this.r = int(red(c) / PixelColorScheme.R[l_index] * l_index);
l_index = PixelColorScheme.G.length - 1;
this.g = int(green(c) / PixelColorScheme.G[l_index] * l_index);
l_index = PixelColorScheme.B.length - 1;
this.b = int(blue(c) / PixelColorScheme.B[l_index] * l_index);
}
public PixelColor clone() {
return new PixelColor(r,g,b);
}
public color get_color() {
return color(PixelColorScheme.R[this.r], PixelColorScheme.G[this.g], PixelColorScheme.B[this.b]);
}
public int to_int() {
return (this.r*(PixelColorScheme.G.length) + this.g)*(PixelColorScheme.B.length) + b;
}
}