Drawing a trail for a moving object
in
Programming Questions
•
8 months ago
I'm working on an object moving around an attractor (maths mainly based on the GravitationalAttraction3D example).
However, I'd like to have it leave a trail to make it a bit more obvious. The point moves around in the expected fashion, but leaves no trail.
It's been a while since I've tried processing (never really got the hang of arrays the first time!) but this code also looks wrong. Is there anyway I can leave a trail, and make the code more readable?
- void display() {
- trailx[0] = location.x;
- traily[0] = location.y;
- for(int i = 0; i < trailx.length-1; i++){
- trailx[i+1] = trailx[i];
- }
- for(int i = 0; i < traily.length-1; i++){
- traily[i+1] = traily[i];
- }
- for(int i = traily.length-1; i > 1; i--){
- line(trailx[i], traily[i], trailx[i-1], traily[i-1]);
- }
- line(location.x, location.y, trailx[0], traily[0]);
- }
1