Hi!
For example I want the draw() function to be able to look like this:
I am quite new to this so please bear with me if what I am thinking here is stupid :). What I want to do is to have a separate class that can handle the recording to a new PGraphics object.
For example I want the draw() function to be able to look like this:
- OffScreenRender screenRender;
- public void setup()
- {
- screenRender = new OffScreenRender(this, 1000, 700);
- }
- public void draw()
- {
- background(0,0,0);
- //Render the graphics to an offScreen buffer
- screenRender.startRender();
- rect(600,50,230,150);
- .......................................
- etc....
- //Stop the render and save image
- screenRender.stopRender();
- }
The
OffScreenRender-class should look like this:
- import processing.core.*
- /**
- * Renders the processingsketch to a .jpg
- */
- public class OffScreenRender
- {
- PApplet parent; // The parent PApplet
- PGraphics render;
- int width;
- int height;
- OffScreenRender(PApplet p, int width_, int height_)
- {
- //Initialize variables
- parent = p;
- width = width_;
- height = height_;
- render = parent.createGraphics(width, height);
- }
- //Render the image
- void startRender()
- {
- render.beginDraw();
- }
- //Render the image
- void stopRender()
- {
- render.endDraw();
- render.save("hej.jpg");
- }
- }
So basically i want the PGraphics called "render" to listen and record while commands are executed in draw(). Is this possible? Right now I only get a black image.
Thank you!
1