We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › painting onto image performance
Page Index Toggle Pages: 1
painting onto image performance (Read 406 times)
painting onto image performance
Apr 6th, 2006, 3:49pm
 
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);
}

Re: painting onto image performance
Reply #1 - Apr 6th, 2006, 4:38pm
 
first item under "drawing in 2D" in the faq:
http://processing.org/faq/bugs.html#java2d
Page Index Toggle Pages: 1