Moving object from random spot back to origin

Okay, I have posted previous questions that are similar, but I am still having trouble with my program. I am trying to print out a char, have it put to a random position, then slowly move back to the origin. In the code below, I have a char 'M', and I want it drawn to a random spot. But what I want is it to draw to the random spot then head back to the origin (200,200). I just cant seem to understand how I can do this! Its really driving me crazy. All the examples I have been shown are very helpful but are just to complex. I am looking for just a very bare-bones example. Would this be hard to accomplish due to the way I am printing it out? Please help!

char m = 'M';
float xPos, yPos;
PFont f;
float r1 = random(400);
float r2 = random(400);
void setup(){
  background(255);
  size(400,400);
  xPos = 200;
  yPos = 200;
  f = createFont("Arial", 30, false);
}

void draw(){
  background(0);
  fill(255);
  textFont(f);
  text(m, r1, r2);

}
Tagged:

Answers

  • Answer ✓

    I figured it out, very easy actually. I apologize for asking this question so much. For any of you who stumbled upon this, use this.

    char m = 'M';
    float xPos, yPos;
    float r1, r2;
    PFont f;
    void setup(){
      r1 = random(400);
      r2 = random(400);
      background(255);
      size(400,400);
      xPos = 200;
      yPos = 200;
      f = createFont("Arial", 30, false);
    }
    
    void draw(){
    
      background(0);
      fill(255);
      textFont(f);
      text(m,r1,r2);
      r1 = lerp(r1, xPos, 0.1);
      r2 = lerp(r2, yPos, 0.1);
    }
    
Sign In or Register to comment.