simple trails question

hello, im trying to do something really simple but i dont know how to do it in openframeworks, in processing i need to call the command background(204, 222, 22); for each draw because if i dont do this my moving elements create a trail in the canvas. it seem openframewok doesnt work in the same way because i dont need to call ofBackground(255, 255, 255); for each draw, so i have basically 2 questions, how can i make for creating a trail when my agent or graphic element moves in the canvas? and which possibilities does i have for creating this kind of trail in openframeworks?

thanks

Matias.

if you call ofSetBackgroundAuto(false); in setup you’ll get the same behaviour as in processing.

hi thanks for the reply, but what about if i need that each ball leaves a trails of balls or objects? in the programm im working on a group of ball moves randomly leaving a trail of balls, and i need that the balls can collide with the trails, which is the best way of doing this?
thanks

Matias

hi Matias,

best way to achieve something like this is to keep a list that holds the last positions of the ball. each frame you add the current position of the ball on to the back of the list. eventually you will need to clear old positions off the front of the list so that it doesn’t grow too big.

hope this helps
damian

well, I was working with ofFbo to replace PGraphics from processing, but I can´t clean the buffer properly.
So, I want to try the “mathematical method” saving old positions of an object to use it to drawing a path, but I can´t figured out how I can do that.

Maybe you can explain the algorithm.

thanks in advances!

  
deque<ofVec2f>positions;  
  
//in update()  
  
positions.push_back(currentPosition); // add a new one  
if(positions.size() > 100) positions.pop_front(); // if it's too big, get rid of the oldest one  
  
// in draw()  
deque<ofVec2f>::iterator it = positions.begin();  
while(it != positions.end()) {  
   ofCircle(*it, 10);  
   ++it;  
}  

Checking for collision is just a matter of looking through each the paths and checking it’s positions against whatever is supposed to be getting collided against.

Actually, it might make more sense to use a vector rather then a deque, but the syntax is almost exactly the same. You can see it in action here: http://cplusplus.com/reference/stl/vector/

1 Like