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 & HelpSyntax Questions › trails and no trails.
Page Index Toggle Pages: 1
trails and no trails. (Read 827 times)
trails and no trails.
Oct 15th, 2009, 3:51pm
 
to the mighty code senseis,

Here's the hypothetical setup:
I have a sketch with two rects() whizzing around the screen.
If I want the rects to draw a trail behind them, then I just let them move around.
If I want no trails to be drawn, then I put  background(0) at the beginning of the draw-cycle
That's easy enough.

But how do I manage to, simultaneously, draw one rect with a trail and the other without?

Is there a way to prevent one object from coloring the background pixels, while the other object does, but still have it appear on screen?
To give a more concrete example: Within a drawing tool, how can the paintbrush icon move over the canvas, while beneath it a stroke is drawn?
Or can toggable guidelines within a sketch exist without them recoloring the background pixels?

The only solution I can think of, is to save the pixel values from the background area the object is going to cover, then draw an object and when it moves away/is deleted redraw the background pixels using the presaved values. But this approach seems very unsexy and clunky.

I don't even know under which keywords I should start researching this problem. I hope I've managed to make my question clear enough without creating too much mass confusion. Any pointers to where I should start looking would be great.

cheers,
Greg
Re: trails and no trails.
Reply #1 - Oct 15th, 2009, 5:54pm
 
You can do this by drawing into a pgraphics where you atdd this trail effect. take a look at.
http://processing.org/reference/PGraphics.html

this is an example :



PGraphics pg;

void setup() {
 size(500, 500,P3D);
 pg = createGraphics(500, 500, P3D);
}

void draw() {
 background(0);
 pg.beginDraw();
 pg.fill(0, 20);
 pg.rect(0,0,500,500);
 pg.fill(255);
 pg.ellipse(mouseX-20, mouseY+20,16,16);
 pg.endDraw();
 
 image(pg, 0, 0);
 
fill(255,0,0);
ellipse(mouseX+20, mouseY+20,15,15);
 
}
Re: trails and no trails.
Reply #2 - Oct 16th, 2009, 1:09am
 
ok, I'll have to dig into this.
thanks!
Re: trails and no trails.
Reply #3 - Oct 16th, 2009, 6:18am
 
Another nice point to Cedric's point is that you can manage several layers, like big paint programs! Smiley
Page Index Toggle Pages: 1