hello list,
I started a small program, to paint to an image, but performance is sub par. would somebody be so kind to point me at what I am doing wrong? This sketch loads the X-Server, its so busy, painting lags very much.
please see http://www.myzel.net/hungerburg/sketches/paint/ for a demo.
wimg is the canvas (white image, but maybe any image), bimg is the pencil color (black image, but maybe any image, that gets more and more visible) - the program must not use the display's pixels, because other stuff is to happen on the screen, that shall not modify the image.
Actually I chose the copy method, because I thought it may be faster than iterating over pixels and setting their color to black. position of the pencil is calculated after the sprite example in the processing install package.
Thank you in advance,
Peter
Code:
/* simple painting to an image */
PImage wimg; // image we want to paint on
PImage bimg; // image to use as pencil color
float xpos;
float ypos;
float drag = 30.0;
// --------------------------------------------------------
void setup()
{
framerate(20);
wimg = loadImage("white.png");
bimg = loadImage("black.png");
size (832, 624);
xpos = width/2;
ypos = height/2;
background(255);
}
void draw()
{
image(wimg, 0, 0);
int w = 10;
float difx = mouseX - xpos-w/2;
if(abs(difx) > 1.0) {
xpos = xpos + difx/drag;
xpos = constrain(xpos, 0, width-w);
}
float dify = mouseY - ypos-w/2;
if(abs(dify) > 1.0) {
ypos = ypos + dify/drag;
ypos = constrain(ypos, 0, height-w);
}
wimg.copy(bimg, int(xpos), int(ypos), w, w, int(xpos), int(ypos), w, w);
wimg.updatePixels(int(xpos), int(ypos), w, w);
}