constrain
in
Programming Questions
•
1 year ago
Hi everyone,
I only have a minor problem that is most likely very easy to fix. I made a very basic color selector to ease the process of finding the right rgb color, here is the most essential part of the code (it contains some controlP5 interfacing but thats redundant here so i left it out). The problem i am experiencing is that the r, g and b ints always grow bigger that 255 although i constrained them... im sure the answer is super easy but i didnt find it ... so thanks in advance for your help
(btw i should also work on the thing that nobody could possibly click fast enough to increase a value by just one, but thats a different story)
//////
int r = constrain(1,0,255);
int g = constrain(1,0,255);
int b = constrain(1,0,255);
void setup() {
size(600, 600);
}
void draw() {
color c = color(r, g, b);
background(c);
if (keyPressed) {
if (key == 'u') {
r =r+1;
}
if (key == 'i') {
g++;
}
if (key == 'o') {
b++;
}
if (key == 'j') {
r -=1;
}
if (key == 'k') {
g-=1;
}
if (key == 'l') {
b-=1;
}
println(r);
println(g);
println(b);
}
}
I only have a minor problem that is most likely very easy to fix. I made a very basic color selector to ease the process of finding the right rgb color, here is the most essential part of the code (it contains some controlP5 interfacing but thats redundant here so i left it out). The problem i am experiencing is that the r, g and b ints always grow bigger that 255 although i constrained them... im sure the answer is super easy but i didnt find it ... so thanks in advance for your help
(btw i should also work on the thing that nobody could possibly click fast enough to increase a value by just one, but thats a different story)
//////
int r = constrain(1,0,255);
int g = constrain(1,0,255);
int b = constrain(1,0,255);
void setup() {
size(600, 600);
}
void draw() {
color c = color(r, g, b);
background(c);
if (keyPressed) {
if (key == 'u') {
r =r+1;
}
if (key == 'i') {
g++;
}
if (key == 'o') {
b++;
}
if (key == 'j') {
r -=1;
}
if (key == 'k') {
g-=1;
}
if (key == 'l') {
b-=1;
}
println(r);
println(g);
println(b);
}
}
1