Hi, I've just started using Processing and am using it for basic data graphing and representation. I'm to the point where I'm tired of rewriting or copy/pasting/altering the same basic algorithms over and over, so I've started delving into library creation.
As a simple test, I did created the java class below. The original was much more complicated (and actually did something of use), but I've slimmed this down for simplicity.
The problem I'm seeing is that regardless of what values I use for red, green and blue, I always get the value 0 back in my sketch, where I call this class' method. Is there something I'm doing wrong here?
Here's the class:
import processing.core.PGraphics;
public class SimpleTest extends PGraphics {
public SimpleTest() {}
public int getColor(int red, int green, int blue) {
return color(red,green,blue);
}
}
Here's a Processing sketch that illustrates the problem. This also compares the external class use vs. an internal method use. If the above was working properly, there should be two sets of rectangles same-colored side-by-side.
import simpleGraph.*;
void setup() {
size(140,250);
background(0);
noLoop();
}
color localColor(int r, int g, int b) {
return color(r,g,b);
}
void draw() {
color cl = color(0,0,0);
// Using external class
SimpleTest st = new SimpleTest();
cl = st.getColor(255,255,255);
println("color 1: " + cl);
fill(cl);
rect(10,10,50,50);
cl = st.getColor(0,255,0);
println("color 2: " + cl);
fill(cl);
rect(10,70,50,50);
cl = st.getColor(255,0,0);
println("color 3: " + cl);
fill(cl);
rect(10,130,50,50);
cl = st.getColor(0,0,255);
println("color 4: " + cl);
fill(cl);
rect(10,190,50,50);
// using local method
cl = localColor(255,255,255);
println("color 5: " + cl);
fill(cl);
rect(70,10,50,50);
cl = localColor(0,255,0);
println("color 6: " + cl);
fill(cl);
rect(70,70,50,50);
cl = localColor(255,0,0);
println("color 7: " + cl);
fill(cl);
rect(70,130,50,50);
cl = localColor(0,0,255);
println("color 8: " + cl);
fill(cl);
rect(70,190,50,50);
}