-
Notifications
You must be signed in to change notification settings - Fork 0
/
qoi.pde
105 lines (87 loc) · 2.36 KB
/
qoi.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
98
99
100
101
102
103
104
105
color[] colors = {
#000000,
#ffffff,
#ff0000,
#00ff00,
#0000ff,
#ffff00,
#ff00ff,
#00ffff,
#000000,
#000000,
#000000,
#000000,
#000000,
#000000,
#000000,
#000000,
};
int currentColorIndex = 0;
int pixelWidth = 16;
int pixelHeight = 16;
int imageWidth = 64;
int imageHeight = 64;
void settings() {
size(imageWidth * pixelWidth, imageHeight * pixelHeight + 50);
}
void setup() {
background(255);
for (int i = 0; i < 8; i++) {
colors[i + 8] = color(random(0, 255), random(0, 255), random(0, 255));
}
updateColorSelect();
}
void draw() {
if (mousePressed && (mouseButton == LEFT)) {
if (mouseY < height - 50) {
fill(colors[currentColorIndex]);
rect(mouseX - (mouseX % pixelWidth), mouseY - (mouseY % pixelHeight), pixelWidth, pixelHeight);
}
}
}
void updateColorSelect() {
int boxWidth = (width / colors.length);
for (int i = 0; i < colors.length; i++) {
noStroke();
fill(colors[i]);
rect(i * boxWidth, height - 50, boxWidth, 50);
}
colorMode(HSB, 255, 255, 255);
color current = colors[currentColorIndex];
stroke(color((hue(current) + 128) % 256, saturation(current), (brightness(current) + 128) % 256));
strokeWeight(3);
noFill();
rect((currentColorIndex * boxWidth) + 1,(height - 50) + 1, boxWidth - 2, 48);
noStroke();
colorMode(RGB, 255, 255, 255);
}
void mouseWheel(MouseEvent event) {
currentColorIndex = (((currentColorIndex + event.getCount()) % colors.length) + colors.length) % colors.length;
updateColorSelect();
}
void mousePressed(MouseEvent event) {
if (event.getButton() == 39) {
println("This button is depricated because IT FUCKS. ME. UP.");
}
}
void keyPressed(KeyEvent event) {
switch(event.getKeyCode()) {
// Key S pressed => save
case 83:
save();
break;
case 81:
exit();
break;
case 82:
for (int i = 0; i < 8; i++) {
colors[i + 8] = color(random(0, 255), random(0, 255), random(0, 255));
}
background(255);
updateColorSelect();
break;
default:
println("Lmao this key doesn't do anything lol: " + event.getKeyCode());
break;
}
}