Save drawn Constructs

Hello. I want to save drawn constructs, if they are too big to recalculate every tick. I don’t know exactly how it works, but I think it works with PMatrix. My Idea was:

ConstructXY x;

void setup(){
x = new ConstructXY()
}

void draw(){
     background(255);
     x.drawConstruct();
}

class ConstructXY{
     PMatrix2D construct1= null;
    ConstructXY() {
          pushMatrix();
          fill(0);
          strokeWeight(2);
          ellipse(100, 100, 40, 40);
          rect(200, 200, 60, 10);
          ...

          construct1 = getMatrix(construct1);
          //popMatrix();
     }

     public void drawConstruct(){
          // I want something that adds a matrix to another matrix
          setMatrix(construct1);
     }

}

Where is the Problem???

Hi,

Welcome to the community! :wink:

Please format your code using the </> button in the message editor on the forum.

Can you be more precise about what kind of structure you need to save (do you have some visuals)? And also are you using a library, because I can’t see any PMatrix2D in the reference.

please always post a runnable code to demonstrate the problem

No use to draw something in the constructor of the class.

It depends from what you want to achieve.

But the matrix is only the translate and rotate data, not the rect or the triangle.

1 Like

https://processing.github.io/processing-javadocs/core/processing/core/PMatrix2D.html

2 Likes

OK thanks. I will try the loadPixels () and updatePixels () methods

I don’t know why?

Because these are operations on pixel level.

You can make a list of rectangles or rectangles and store their position and draw them from the ArrayList.

For example:
When I draw large transitions, it takes too much time to recalculate them using the Rect / Ellipse function.
It is easier to save the constructed element at the pixel level than to save the ellipse coordinates and calculate the object.
-> When I make a ellipse-transition I call the ellipse () method very often and when I calculate every pixel of the ellipse (or edge of the ellipse) every tick n times, it takes too long

I would disagree on the speed question…

maybe a group of PShape can help you:

see https://www.processing.org/tutorials/pshape/

2 Likes

Thank you… Thats exactly what i need

1 Like

PMatrix2D 1

Yes, PMatrix2D is a stack frame object for pushMatrix() and popMatrix(). Although you can get and set them directly, most users only interact with them by modifying the current PMatrix using things like translate() rotate() scale() – some users further learn to push and pop them – but few directly manipulate them (there isn’t a reference page).

1 Like