I am writing my own class for the first time. In the past, I have always used colorMode(HSB, 360, 100, 100), declared in the setup() of the program. I did the same this time, but any shapes that my class drew were filled as if the colors were defined as RGB. When I drew a shape in the main draw() function, it was filled with the HSB colors I expected. I also tried calling colorMode(HSB, 360, 100, 100) in the constructor function of the class, but it just gave me a lot of nonsense red Java errors.
Is there anything I might be doing wrong here?
-------------------------------------------------
here's the code, in case that's helpful:
void setup(){
size(600, 300);
colorMode(HSB, 360, 100, 100);
smooth();
rectMode(CORNERS);
}
RectButton button = new RectButton();
void draw(){
background(0, 0, 99);
if(mousePressed == true){
if(button.getmade() == false){
button.prep();
}
}
button.update();
button.display();
}
void mousePressed(){
if (button.getmade() == true){
if(button.getover() == true){
button.pressed();
}
} else {
button.setv1();
button.setinvis();
}
}
void mouseReleased(){
if (button.getmade() == false){
button.setvis();
button.setv2();
}
}
class RectButton {
int x1, x2;
int y1, y2;
color color1;
boolean visible;
boolean made;
public RectButton(){
colorMode(HSB, 360, 100, 100);
visible = false;
made = false;
color1 = color(255, 255, 255);
}
public boolean getmade(){
return made;
}
public void setvis(){
visible = true;
}
public void setinvis(){
visible = false;
}
public void prep(){
rect(x1, y1, mouseX, mouseY);
}
public void update(){
}
public void display(){
if (made == true){
if (visible == true){
fill(color1);
rect(x1, y1, x2, y2);
}
}
}
public void setv1(){
x1 = mouseX;
y1 = mouseY;
}
public void setv2(){
x2 = mouseX;
y2 = mouseY;
if (dist(x1, y1, x2, y2) < 8 || dist(y1, x1, y2, x2) < 8){
made = false;
} else {
made = true;
}
}
public boolean getover(){
if (mouseX > x1 && mouseX < x2 && mouseY > y1 && mouseY < y2){
return true;
}
return false;
}
public void pressed(){
int r = 115;
color1 = color(r, 60, 86);
r--;
}
}
Thanks!