We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I was inspired by this video of sand art on a potter's wheel by KRUGOVOROT, and want to see if I can make something similar in Processing. I need to be able to draw on a canvas, then rotate it before drawing the next frame.
I don't quite have my algorithm sorted out yet, but I'm pretty sure I need to draw one PGraphics buffer into another to pull this off. In my test code below, though, buffer.image(oldbuffer, 51, 30);
produces a null pointer exception on the very first pass.
How can I do this? Am I going about it all wrong?
PGraphics buffer;
PGraphics oldbuffer;
void setup() {
size(100, 100);
buffer = createGraphics(width, height);
oldbuffer = createGraphics(width, height);
}
void draw() {
buffer.beginDraw();
rotate(0.1);
buffer.image(oldbuffer, 51, 30);
buffer.ellipse(mouseX, mouseY, 10, 10);
buffer.endDraw();
image(buffer, 0, 0);
oldbuffer = buffer;
}
Answers
After instantiating a PGraphics w/ createGraphics(), it still needs beginDraw() before start using it! :-@
I think the rotate() call should be prefixed by buffer. too. And the first time draw() is called, oldbuffer isn't drawn on yet, so it is in a state where it cannot be drawn. As GoToLoop said, you need to add:
at the end of setup() to make it work.