# How do I call fill() in a function?

**URL:** <https://discourse.processing.org/t/how-do-i-call-fill-in-a-function/23043>\
**Category:** Beginners\
**Created:** [August 4, 2020, 9:57pm UTC](https://discourse.processing.org/t/how-do-i-call-fill-in-a-function/23043 "2020-08-04T21:57:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alkilum](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@alkilum](https://discourse.processing.org/u/alkilum)\
**Post date:** [August 4, 2020, 9:57pm UTC](https://discourse.processing.org/t/how-do-i-call-fill-in-a-function/23043/1 "2020-08-04T21:57:59Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 4, 2020, 10:16pm UTC](https://discourse.processing.org/t/how-do-i-call-fill-in-a-function/23043/2 "2020-08-04T22:16:26Z")

</div>

You can request the sketch’s PApplet object:

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

```

Or its PGraphics canvas object:

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

```

---

<div class="post-metadata">

**Author:** ![alkilum](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@alkilum](https://discourse.processing.org/u/alkilum)\
**Post date:** [August 5, 2020, 1:10am UTC](https://discourse.processing.org/t/how-do-i-call-fill-in-a-function/23043/3 "2020-08-05T01:10:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 5, 2020, 1:15am UTC](https://discourse.processing.org/t/how-do-i-call-fill-in-a-function/23043/4 "2020-08-05T01:15:05Z")

</div>

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

[Processing.org/reference/this.html](http://Processing.org/reference/this.html)

---

<div class="post-metadata">

**Author:** ![alkilum](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@alkilum](https://discourse.processing.org/u/alkilum)\
**Post date:** [August 5, 2020, 1:17am UTC](https://discourse.processing.org/t/how-do-i-call-fill-in-a-function/23043/5 "2020-08-05T01:17:47Z")

</div>

Yeah but I made my function non static
