|
Author |
Topic: color declaration before setup() (Read 253 times) |
|
heliodrop Guest
|
color declaration before setup()
« on: Jul 17th, 2003, 4:52pm » |
|
Hello. I have a little question. I dont understand why this code works: // Color Test : OK void setup() { size(200, 200); } void loop() { color black = color(0, 0, 0); color white = color(255, 255, 255); setPixel(10, 10, black); setPixel(20, 20, white); } // End and why this one doesn't: // Color Test : NullPointerException color black = color(0, 0, 0); color white = color(255, 255, 255); void setup() { size(200, 200); } void loop() { setPixel(10, 10, black); setPixel(20, 20, white); } // End I have a NullPointerException (when I run the 2nd sketch), and I don't understand why. Because all other type of variables (int, float, etc...) can be defined before the setup() function. (the revision number 0056 i'm using win98 Does anyone can explain me that ? thanks!
|
|
|
|
benelek
|
Re: color declaration before setup()
« Reply #1 on: Jul 18th, 2003, 3:52am » |
|
it's part of the much bigger issue Processing currently has, where you cannot use any p5-specific functions / data types before setup(). and the data type color is a custom p5 job. you should also notice that you can't use random(), etc before setup(). however, you're allowed to define p5 variables before setup() as long as you don't init them: Code:color black; void setup() { size(200,200); black=color(0,0,0); } void loop() { } |
| if any more explanation is needed, just ask. btw, a question to Fry: out of curiosity, would this issue be related to why you can't currently use p5-specific stuff before/in the constructor of a custom class?
|
|
|
|
heliodrop
|
Re: color declaration before setup()
« Reply #2 on: Jul 18th, 2003, 1:04pm » |
|
Ok, that's a p5 specific type (I'm not a java expert). sure, that's better than declaring constants into the loop(). thanks.
|
|
|
|
fry
|
Re: color declaration before setup()
« Reply #3 on: Jul 18th, 2003, 6:06pm » |
|
oh, actually this one is different.. it's because color() is a function, which has to be called inside of another function (like setup or loop), unless you're in 'draw' mode, where you aren't using draw/loop/setup at all. the following would work, however: color black = #000000; color white = #ffffff; if you want to have that outside of setup.
|
|
|
|
heliodrop
|
Re: color declaration before setup()
« Reply #4 on: Jul 19th, 2003, 1:37am » |
|
right, it's a function i understand now thanks
|
|
|
|
|