# Load and Update pixels inside a function

**URL:** <https://discourse.processing.org/t/load-and-update-pixels-inside-a-function/21872>\
**Category:** Coding Questions\
**Created:** [June 14, 2020, 6:59pm UTC](https://discourse.processing.org/t/load-and-update-pixels-inside-a-function/21872 "2020-06-14T18:59:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RenanRabelo](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@RenanRabelo](https://discourse.processing.org/u/RenanRabelo)\
**Post date:** [June 14, 2020, 6:59pm UTC](https://discourse.processing.org/t/load-and-update-pixels-inside-a-function/21872/1 "2020-06-14T18:59:31Z")

</div>

Inside the function line() there is an Load and Update pixels rigth?

Is possible to use those functions (rect, line, point etc) but loading the pixels at the start of the draw function and updating at the end?

I need to use a for loop to draw a lot of lines, and my perfomance is dropping, so maybe removig the load and update pixels from the functions may increase performance.

Thank you!

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [June 14, 2020, 7:52pm UTC](https://discourse.processing.org/t/load-and-update-pixels-inside-a-function/21872/2 "2020-06-14T19:52:54Z")

</div>

Hi,

Welcome to the forum! 😉

If you take a look at the [source code](https://github.com/processing/processing) for the `line()` function, it looks like this :

```auto
// processing/core/src/processing/core/PGraphics.java

public void line(float x1, float y1, float x2, float y2) {
  beginShape(LINES);
  vertex(x1, y1);
  vertex(x2, y2);
  endShape(); 
}

```

So it’s calling the `beginShape()` function in addition to the `endShape()` function to draw a line.

I also found that the `endShape()` function is doing nothing (lines 1729, 1730) :

```auto
// processing/core/src/processing/core/PGraphics.java

public void endShape(int mode) {
}

```

Maybe someone can help to figure out how Processing really render a line?

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [June 21, 2020, 4:45am UTC](https://discourse.processing.org/t/load-and-update-pixels-inside-a-function/21872/3 "2020-06-21T04:45:27Z")

</div>

> [@josephh](#):
>
> I also found that the `endShape()` function is doing nothing (lines 1729, 1730) :

Look in PGraphics2D or whatever the renderer is – the render-specific PGraphics should implement endShape for OpenGL or PDF etc etc.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [June 21, 2020, 4:48am UTC](https://discourse.processing.org/t/load-and-update-pixels-inside-a-function/21872/4 "2020-06-21T04:48:05Z")

</div>

> [@RenanRabelo](#):
>
> I need to use a for loop to draw a lot of lines

Instead of using line(), perhaps try beginShape(LINES)

> **[beginShape() / Reference](https://processing.org/reference/beginShape_.html)**
>
> Using the beginShape() and endShape() functions allow creating more complex forms. beginShape() begins recording vertices for a shape and endShape() stops recording. The va…
