Text bounce bounding box?

ok, no wrap, miss understanding…
just move to right and back?
using correct textwidth

String mytext = "this is a test";
float y=10;
float x = 0;
float xspeed = 10;
float direction = 1;

float textStr;

void setup() {
  size (350, 500);
  textStr = random(10, 20);
} 

void draw() {
  background (0);
  textSize(textStr);
  fill(255);
  //textAlign(LEFT);
  x = x + direction*xspeed;
  if (x > width-textWidth(mytext)) {  
    direction = -1;
    textStr = random(10, 20);
  }
  if (x < 0) {     
    direction = 1;
    textStr = random(10, 20);
  }
  text(mytext, x, y);
} 
1 Like