:Inside the processing libraries: Method Rect();

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


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();
  }

what is the idea, and why you can not use

https://processing.org/reference/rect_.html
combined with
https://processing.org/reference/fill_.html
https://processing.org/reference/stroke_.html

Did you mean the rect function? https://processing.org/reference/rect_.html

You can also use createShape to create rect PShape objects:

https://processing.org/reference/createShape_.html

1 Like

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.

1 Like

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?

1 Like

Use redraw() inside input event callbacks:
Processing.org/reference/redraw_.html

Java/Pjs example:

p5js example:


1 Like

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