We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I wonder how I can return the walker to its original position once the counter condition is reached, no matter what the new position is.
PVector walker;
PVector start;
PVector seek;
float count;
void setup() {
size (900, 900);
walker= new PVector (width/2, height-10);
start= new PVector(0, -1);
seek=new PVector(random(-1, 1), random( 1));
count=0;
}
void draw() {
background(53, 111);
count++;
stroke(0, 0, 255);
rect(width/2, height-10, 10, 10);
noStroke();
fill(255, 0, 0);
ellipse(walker.x, walker.y, 5, 5);
startt();
limits();
println(count);
}
void startt() {
if (walker.y>=150 && count<50) {
walker.add(start);
} else {
walker.add(seek);
}
}
// once the condition is reached (count=1000) , walker "walks back" to its original position.
void limits() {
if (walker.x>width || walker.x <0) {
seek.x = -seek.x;
} else if (walker.y>height || walker.y <0) {
seek.y = -seek.y;
}
}
Answers
@jozze -- do you mean that you want to restore the original position? You defined this as:
...so that would be:
You could also store that original position in a global
PVector origin
and thenwalker.set(origin.x, origin.y);
That concept is similar to a walking ant returning to its anthill, right?
@jeremydouglass __ the .set method resets the position straight away from the current one. We do not see the object "going back home". Although this is not desired, it pointed out a way I think works out:
@GoToLoop __ Somehow yes, I found a similar approach in your AntHill Sketch (lines 118,122)
thx both of you!