Handling color in eclipse with processing

Hi guys I’m hoping you can help please I’m a bit stuck.

When trying to convert my code to a library I ran into the following problem, color is not recognised as a data type.

I have found the following posts online asking about the same problem and most of them recommend using int instead of color, which I’m still a bit confused about because when I tried this it did not resolve the problem.

as you can see. Its likely I’m missing something obvious but I simply do not know what I’m looking to do. An int in my understanding is a datatype that only accepts one value not 2, 3 or 4 as color does. So how do I use int to handle the color type.

I have found an alternative which is the java.awt library which has a Color class, and has functions such as getRGB() etc to extract values, but I’m just wandering if this method has any problems as it means amending my library which at this point has quite a few instances of color.

here is a sketch using awt

import java.awt.*;

void setup(){
};

void draw(){
  Color c = Color(255, 0, 255);
  background(c.getRGB());
};

Many thanks guys

Hi,

You were on the right tracks but the error lies when you try to use the color() method which is undefined inside your class. It’s accessible from the PApplet class, that’s why you need to pass an instance of it in your constructor and store it as a property.

Try this :

int c = myParent.color(0, 0, 0, 0);

// Note that this is equivalent to myParent.color(0, 0);

oh completely forgot you could do that. Thank-you that was what I was looking for.

1 Like