FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Bugs
   Bug Fixes, Implemented Suggestions
(Moderator: fry)
   color() method not working with setup()
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: color() method not working with setup()  (Read 336 times)
mKoser

WWW Email
color() method not working with setup()
« on: Aug 22nd, 2003, 7:37pm »

i just encountered a strange bug:
 
when i type in this:
Code:

color c1 = color(255, 0, 0);
noStroke();
fill(c1);
rect(25, 25, 50, 50);

 
...i get a red square.
 
when i type in this:
Code:

color c1 = color(255, 0, 0);
 
void setup(){
  size(100, 100);
  fill(c1);
  noStroke();
}
 
void draw(){
  rect(25, 25, 50, 50);
}

 
...i would expect the same red square to be drawn, but what i get instead is a NullPointerException
 
 
UPDATE
Duh! I was a bit to fast on this post. The reason must be, that I am using a native Processing command before the sketch is initiated, hence trying to call a color() method in native java, which causes an error (am I right on this one, I am expecting this is the same problem as trying to use native Processing language in an objects constrcutor class!)
 
anyway, this works:
 
Code:

color c1;
 
void setup(){
  size(100, 100);
  c1 = color(255, 0, 0);
  fill(c1);
  noStroke();
}
 
void draw(){
  rect(25, 25, 50, 50);
}

« Last Edit: Aug 22nd, 2003, 7:41pm by mKoser »  

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
fry


WWW
Re: color() method not working with setup()
« Reply #1 on: Aug 23rd, 2003, 1:00am »

nope, it's because that code gets run before setup, which means the colorMode() hasn't yet been set. color(x, y, z) scales the values by the current colorMode.  
 
so it's not actually a bug, but (i think this came up elsewhere) maybe a default colorMode has to be set before setup() so that things like this work.
 
( it's not the same as the 'no p5 inside constructors' bug.. that's been fixed in 57/58 )
« Last Edit: Aug 23rd, 2003, 1:01am by fry »  
mKoser

WWW Email
Re: color() method not working with setup()
« Reply #2 on: Aug 23rd, 2003, 1:26am »

woops... there I go jumping to conclusion!
yep, a default colorMode would be great!
 

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
fry


WWW
Re: color() method not working with setup()
« Reply #3 on: Sep 21st, 2003, 7:53pm »

fixed for rev 0060.
 
Pages: 1 

« Previous topic | Next topic »