JAVA Code

We've recreated the DVD logo screensaver from that one episode of The Office. Will it ever land in one of the corners EXACTLY??

See Simon's Java code down below.

Here's the function that handles the ricocheting behavior of the DVD logo:

public void startAnimation(){
  Timer timer = new Timer(30, e -> {
    if (timeSinceHit < 5){
      timeSinceHit ++;
    }
    if (x >= xDist || x <= 0){
      xVel = -xVel;
      hits ++;
      if (timeSinceHit < 5){
        corner = true;
      }
      timeSinceHit = 0;
    }
    if (y >= yDist || y <= 0){
      yVel = -yVel;
      Hits ++;
      if (timeSinceHit < 5){
        corner = true;
      }
      timeSinceHit = 0;
    }
    x += xVel;
    y += yVel;
    repaint();
  });
  timer.start();
}