We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › colorMode() problems
Page Index Toggle Pages: 1
colorMode() problems (Read 172 times)
colorMode() problems
Jun 13th, 2009, 3:59pm
 
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! Smiley
Re: colorMode() problems
Reply #1 - Jun 13th, 2009, 11:09pm
 
Errors aren't usually random, unless you're using Windows. (sorry couldn't resist Tongue )

Use the assign button to a new RectButton() inside setup() instead of globally. Since it is not static, the reference to your sketch (a PApplet) does not exist yet.

PS: I use Windows, so don't take my comment too seriously...
Page Index Toggle Pages: 1