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 › particles without background refresh
Page Index Toggle Pages: 1
particles without background refresh (Read 970 times)
particles without background refresh
Aug 24th, 2007, 10:28am
 
I've made a hyper basic drawing app which I'd like to pollish with particles.
As I draw a line I want a particle cloud to follow the line movement. The problem is that the particle system from the examples adds a background(0); to the draw() section as it needs to refresh the particles. What happens then is that the drawing get's refreshed and thus entirely cleared too which shouldn't be happening. Any clues?

Thanks.
Re: particles without background refresh
Reply #1 - Aug 24th, 2007, 11:09am
 
You'll need to store the line information somehow, and draw it all each frame, as without the background(...); call the particles will leave trails.
Re: particles without background refresh
Reply #2 - Aug 24th, 2007, 11:14am
 
Hi cer(e)bellum,

You could store in an array the x and y coordinates of the mouse as you draw, and each loop (of draw) run through this array. As your drawing gets bigger the application is getting slower though.
You could also remove the background(0) from the particle code, but then you might want to change the code even further because of particle traces (if it's too much for your taste).

Good luck, BEnm
Re: particles without background refresh
Reply #3 - Aug 24th, 2007, 3:06pm
 
Thanks for the thinkering, removing the background leaves a bit too much of trails indeed Smiley

I was thinking saving X,Y in an array would help. The slowing down shouldn't be too much of a problem as the drawing shouldn't be much more then some lines which will get cleared at some point.

I'll have a look at arrays then Smiley
Re: particles without background refresh
Reply #4 - Aug 24th, 2007, 7:47pm
 
there may be another way that fades the background rather than blanking it (doesn't work in opengl)

at the top of your draw() (and this is from memory so could be wrong)

fill(255, 50); // white, semi transparent
rect(0, 0, width, height); // fill screen

so each time through the current image gets made paler and paler whereas the newly drawn stuff will be bright and bubbly.

fiddle with the 255 and 50 and see what they do. (i can never remember whether 95 as second argument is mostly transparent or mostly opaque)
Re: particles without background refresh
Reply #5 - Aug 29th, 2007, 10:39am
 
Can't seem to work out the array thing, been looking at the examples and I guess I have to work with a 2D array to store mouseX and mouseY values but that's rly as far as I get.

Help sincerely appreciated.
Re: particles without background refresh
Reply #6 - Aug 29th, 2007, 11:50am
 
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1185508727
Re: particles without background refresh
Reply #7 - Aug 30th, 2007, 12:27pm
 
Thanks lenny, it helped alot. I'm able to save the mouseXY in the array and using these values to draw lines (basic drawing app). Still having some minor problems/questions though.

I'm only saving my mouseXY values when the mouse is pressed and calling those values to draw the lines. The problem is, when I release the mousepress and want to start a new line it automatically connects the point of release and the new click point with a line as the line-drawing code just takes the previous array index spot (i-1), being the point of release, and connects it with the new click point (i).
Same problem happens at the very beginning, as I start drawing it automatically takes the first value being 0,0 and connects it with the first click point x,y.

As a last thing, right now I've set my array to 1000 (to get a reasonable drawing time), what would be better is to get an array without a max size, which would be cleared every time a drawing get's cleared.

Thanks.

Code:

import processing.opengl.*;
import processing.video.*;

Capture camera;
int cameraWidth = 1024;
int cameraHeight = (cameraWidth/4)*3;

float x,y;
float[] xpos=new float[1000];
float[] ypos=new float[1000];
void setup(){
size(cameraWidth*2,cameraHeight);
smooth();
for(int i=0;i<1000;i++){
xpos[i]=x;
ypos[i]=y;
}
background(0,0,255);
stroke(255);
strokeWeight(10);
strokeJoin(ROUND);
strokeCap(ROUND);

camera = new Capture(this,cameraWidth,cameraHeight,30);
}

void captureEvent(Capture camera)
{
camera.read();
}

void draw(){
background(0,0,255);
image(camera,0,0);
//motion
if (mousePressed == true){
x=mouseX;
y=mouseY;
}

for(int i=1;i<1000;i++){
xpos[i-1]=xpos[i];
ypos[i-1]=ypos[i];
}
xpos[999]=x;
ypos[999]=y;

noFill();
beginShape();
for(int i=999;i>0;i--){
vertex(xpos[i],ypos[i]);
vertex(xpos[i-1],ypos[i-1]);
}
endShape();

noFill();
beginShape();
for(int i=999;i>0;i--){
vertex(xpos[i]+cameraWidth,ypos[i]);
vertex(xpos[i-1]+cameraWidth,ypos[i-1]);
}
endShape();
}

Re: particles without background refresh
Reply #8 - Aug 30th, 2007, 4:32pm
 
not sure if this helps...
check your examples-folder and look for yellowtail
it's a very good example from golan levin. i think there's some good stuff you can use in there....
Page Index Toggle Pages: 1