# :Inside the processing libraries: Method Rect();

**URL:** <https://discourse.processing.org/t/inside-the-processing-libraries-method-rect/11830>\
**Category:** Gallery\
**Created:** [June 4, 2019, 8:44am UTC](https://discourse.processing.org/t/inside-the-processing-libraries-method-rect/11830 "2019-06-04T08:44:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![RayRay](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@RayRay](https://discourse.processing.org/u/RayRay)\
**Post date:** [June 4, 2019, 8:44am UTC](https://discourse.processing.org/t/inside-the-processing-libraries-method-rect/11830/1 "2019-06-04T08:44:47Z")

</div>

as I did not find information about the processing rect library on the official page, I decided to try to make my own.

what do you think? feel free to complement this code

```auto

att_rect(width/2,height/2,100,100);

void att_rect(int PosX, int PosY, int SizeX, int SizeY){
    loadPixels();
    for(int i = 0; i < SizeY; i ++){
      for(int j = 0; j < SizeX; j++){
        pixels[PosX + (screen_width * PosY) + (screen_width * i) + j] = object_color;  
      }
    }
    updatePixels();
  }

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [June 5, 2019, 9:50am UTC](https://discourse.processing.org/t/inside-the-processing-libraries-method-rect/11830/2 "2019-06-05T09:50:27Z")

</div>

what is the idea, and why you can not use

[https://processing.org/reference/rect\_.html](https://processing.org/reference/rect_.html)  
combined with  
[https://processing.org/reference/fill\_.html](https://processing.org/reference/fill_.html)  
[https://processing.org/reference/stroke\_.html](https://processing.org/reference/stroke_.html)

---

<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 6, 2019, 6:21am UTC](https://discourse.processing.org/t/inside-the-processing-libraries-method-rect/11830/3 "2019-06-06T06:21:19Z")

</div>

> [@RayRay](#):
>
> I did not find information about the processing rect library on the official page

Did you mean the rect function? [rect() / Reference / Processing.org](https://processing.org/reference/rect_.html)

You can also use createShape to create rect PShape objects:

> **[createShape() / Reference](https://processing.org/reference/createShape_.html)**
>
> The createShape() function is used to define a new shape. Once created, this shape can be drawn with the shape() function. The basic way to use the function defines new primitive shapes.…

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [June 6, 2019, 12:07pm UTC](https://discourse.processing.org/t/inside-the-processing-libraries-method-rect/11830/4 "2019-06-06T12:07:00Z")

</div>

Does this run smoothly for larger rectangles, ive tried this in p5.js and it was not cpu friendly. Its fine if noLoop() is usdd but then i couldnt use the function for filling rotating 3d shapes, as they did require loop. Perhaps its different in Processing.

---

<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 6, 2019, 3:22pm UTC](https://discourse.processing.org/t/inside-the-processing-libraries-method-rect/11830/5 "2019-06-06T15:22:58Z")

</div>

> Does this run smoothly for larger rectangles, ive tried this in p5.js and it was not cpu friendly. Its fine if noLoop() is usdd but then i couldnt use the function for filling rotating 3d shapes, as they did require loop. Perhaps its different in Processing.

You can fill a rotated shape while using noLoop, but you can’t animate it (it won’t move) ( **unless you call redraw from input events, see below** ). Without loop, no animation. Also, a rectangle is not a 3D shape – although you can draw them in both 2D and 3D renderers. Rectangle size probably shouldn’t matter. Rectangle count should matter. If you have 100,000 rectangles, PShape (in Java mode) is really inefficient compared to a non-object based approach. If your view isn’t changing, the most efficient thing is to render once to PGraphics or the canvas, then reuse that pre-rendered image.

re:CPU friendly: p5.js and Processing(Java) are implemented in different languages, so different things may be fast or slow. You usually need to test or optimize separately depending on the language mode you are using. What specifically are you trying to do?

---

<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:** [June 6, 2019, 5:29pm UTC](https://discourse.processing.org/t/inside-the-processing-libraries-method-rect/11830/6 "2019-06-06T17:29:31Z")

</div>

> [@jeremydouglass](#):
>
> You can fill a rotated shape while using **noLoop()**, but you can’t animate it (it won’t move).

Use **redraw()** inside input event callbacks:

> **[redraw() / Reference](https://processing.org/reference/redraw_.html)**
>
> Executes the code within draw() one time. This functions allows the program to update the display window only when necessary, for example when an event registered by mousePressed() or

Java/Pjs example:

> **[Rotating Cube \[Java/Pjs\] - GoToLoop - OpenProcessing](https://openprocessing.org/sketch/421281)**
>
> PeterCollingridge.AppSpot.com/3D-tutorial

p5js example:

> <https://gist.github.com/GoSubRoutine/a117ecb16a8b0f939a190f87d3a13267>

> <https://gist.github.com/GoSubRoutine/a117ecb16a8b0f939a190f87d3a13267#file-sketch-js>

---

<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 13, 2019, 5:08pm UTC](https://discourse.processing.org/t/inside-the-processing-libraries-method-rect/11830/8 "2019-06-13T17:08:17Z")

</div>

Looks like this got caught in the spam queue somehow – OP wrote the response 7 days ago 😧
