Hello all. Is it possible to make a bounding box around your text, so when it hits the right side it won’t go beyond the width of my work area? I could minus the text width from the xPos, but that would have to make the text a fixed size and I would prefer it to be random
float xPos = random(0, 500);
float xspeed = 10;
float direction = 1;
PFont font1;
float textStr;
void setup() {
size (350, 500);
textStr = random(10, 20);
}
void draw() {
background (0);
textSize(textStr);
fill(255);
textAlign(LEFT);
xPos = xPos + direction*xspeed;
text("this is a test", xPos, 425);
if (xPos > width) direction = -1;
if (xPos < 0) direction = 1;
if (xPos < 0)
textStr = random(10, 20);
if (xPos > width)
textStr = random(10, 20);
}
I tried a bunch of things but its still not working. I can’t seem to mix ints and floats so it’s I’ve tried both. The text is there but the animation is gone
String mytext = "this is a test";
float x1;
float x=x1, y=10, w=width, h=height;
float xPos = random(0, 500);
float xspeed = 10;
float direction = 1;
PFont font1;
float textStr;
void setup() {
x1=random(0, 500);
size (350, 500);
textStr = random(10, 20);
}
void draw() {
background (0);
textSize(textStr);
fill(255);
textAlign(LEFT);
xPos = xPos + direction*xspeed;
text("this is a test", x, y, w, h);
if (xPos > width) direction = -1;
if (xPos < 0) direction = 1;
if (xPos < 0)
textStr = random(10, 20);
if (xPos > width)
textStr = random(10, 20);
}