How do I call fill() in a function?

So I have a function tied to rendering and I used fill in it like this:

public static int rd(int k){
  fill(#ff0000);
  line(0,0,0,k);
  return k;
}

It said something along the lines of you can’t call fill() in a static context. I tried removing the static keyword and I didn’t get an error but
fill() didn’t work, it just kept the old color. Can I fix this?

You can request the sketch’s PApplet object:

static public void rd(final PApplet p, final int k) {
  p.fill(0xffFF0000);
  p.line(0, 0, 0, k);
}

Or its PGraphics canvas object:

static public void rd(final PGraphics pg, final int k) {
  pg.fill(0xffFF0000);
  pg.line(0, 0, 0, k);
}
2 Likes

Yes, but when I call the function I need to provide a PApplet in the parameters.

static methods don’t have access to keyword this and therefore can only deal w/ arguments which are passed to it: :face_with_monocle:

Processing.org/reference/this.html

Yeah but I made my function non static