Forwarding and reversing time in physics sim

void update(){
    steps = pos.size()-1;
    text (counter, 150,20);
    fill(255);
      text(index,200,10);
      fill(col);
    if(forward){
      
      if(index==0){
        if(pos.size()>0){
          counter = pos.size()-1;
        }
    //if(lim>0){
    //  vx += Limit(vx,lim);
    //  vy += Limit(vy,lim);
    //}else{
    
    if(vx>4){
      vx = 4;
    }
    
    if(vx<-4){
      vx = -4;
    }
    if(vy>4){
      vx = 4;
    }
    if(vy<-4){
      vx = -4;
    }
    x += vx;
    y += vy;
    
      pos.add(new PVector(x,y));
      vel.add(new PVector(vx,vy));
    }
    else if(index ==1){
      
      x = pos.get(counter).x;
      y = pos.get(counter).y;
      counter++;
      if(counter == pos.size()-1){
        index = 0;
      }
    }}
    else if(backward){
      if(counter>0){
        index = 1;
      vx = vel.get(counter).x;
      vy = vel.get(counter).y;
      x -= vx;
      y -= vy;
      //x = pos.get(counter).x;
      //y = pos.get(counter).y;
      counter --;
      if(counter<pos.size()-1){
        pos.remove(pos.size()-1);
      }
      if(counter == 0){
        index = 0;
      }
      //steps = counter;
    }}
    else if(pause){
      
    }
  };

This is the code I have for a physics sim i am writing, I want it to be able to go forward and backwards, it works fine providing that I go back completely but otherwise the pattern changes. Not sure what to do on this one.

full code

com-video-to-gif

1 Like

There are some Nice menus!

Chrisir

Thanks Chrisir, they are fully customisable, im going to add a hashmap to make click logic more intuitive. The only thing im struggling with currently is the drag function.

Nice! (So the Big Crunch is the right theory?)

Well if you right click its the big bang

Yes, the infinite loop theory. Could be. Recently was said by the community, that the universe after all is sphere like, not flat!

Oh those crazy sphere universe theorists, it all sounds like tin foil hat stuff to me!

1 Like

I don’t know what’s more ‘thin foiled’. Big Bounce or M-theory. Any how, I thought your art above was some thought expression.
P.S B.T.W, I think artists are thin foiled as well.

Lol i was making a joke

Your problem might be float precision –
edit sorry, didn’t see that you had a github link, haven’t looked at the full source.

1 Like

I partially solved by implementing a counter and not clearing the array if I go backwards. The only issue with this, is that if I added some attractors during the initial forward phase, not deleting the array means when I go backwards means that I cannot add anymore, or rather anything I add wont affect the particles until the forward counter position has reached the end of the array.