Text bounce bounding box?

possibly use the variables for the text boundaries?

String mytext = "this is a test";
float y=10, w, h;
float xPos = 0;
float xspeed = 10;
float direction = 1;
//PFont font1;
float textStr;

void setup() {
  size (350, 500);
  textStr = random(10, 20);
  h=height-y;
  w=width;
} 

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

it is difficult to see what the result of your sketch should be?

1 Like