-
Notifications
You must be signed in to change notification settings - Fork 0
/
Palettable.pde
97 lines (81 loc) · 2.16 KB
/
Palettable.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
int rootH = 50;
int rootS = 65;
int rootV = 65;
color root;
color temp = root;
int rootX = 10;
int rootY = 10;
int swatchesS = 2;
int swatchesV = 2;
int varianceS = 20;
int varianceV = 20;
int swatchWidth = 50;
int swatchGap = swatchWidth/10;
boolean isOverRoot = false;
int curve = 15;
void setup()
{
size(800, 600);
colorMode(HSB, 360, 100, 100);
frameRate(30);
root = color(rootH, rootS, rootV);
//Menu background
fill(25);
rect(0, 0, width/3, height);
//Palette background
fill(0);
//Why do I have to subtract an extra 1 here?
rect(width - 1 - 2*(width/3), 0, 2*width/3, height);
}
void draw() {
update(mouseX, mouseY);
fill(root);
if(isOverRoot) {
strokeWeight(2);
stroke(255);
rectMode(CORNER);
fill(root);
rect(rootX, rootY, swatchWidth, swatchWidth, curve);
} else {
strokeWeight(2);
stroke(0);
rectMode(CORNER);
fill(root);
rect(rootX, rootY, swatchWidth, swatchWidth, curve);
}
}
void update(int x, int y) {
//Root check
if (overSwatch(rootX, rootY, swatchWidth) ) {
isOverRoot = true;
} else {
isOverRoot = false;
}
}
boolean overSwatch(int x, int y, int h) {
if (mouseX >= x && mouseX <= x+h &&
mouseY >= y && mouseY <= y+h) {
return true;
} else {
return false;
}
}
void mousePressed() {
if (isOverRoot) {
rectMode(CENTER);
fill(root);
rect(2*width/3, height/2, swatchWidth, swatchWidth, curve);
for(int i = 1; i <= swatchesS; i++) {
fill(color(rootH, rootS + (i * varianceS), rootV));
rect(2*width/3 + (i * (swatchWidth + swatchGap)), height/2, swatchWidth, swatchWidth, curve);
fill(color(rootH, rootS - (i * varianceS), rootV));
rect(2*width/3 - (i * (swatchWidth + swatchGap)), height/2, swatchWidth, swatchWidth, curve);
}
for(int i = 1; i <= swatchesV; i++) {
fill(color(rootH, rootS, rootV + (i * varianceV)));
rect(2*width/3, height/2 - (i * (swatchWidth + swatchGap)), swatchWidth, swatchWidth, curve);
fill(color(rootH, rootS, rootV - (i * varianceV)));
rect(2*width/3, height/2 + (i * (swatchWidth + swatchGap)), swatchWidth, swatchWidth, curve);
}
}
}