here is a solution that has one line only that’s chosen once and for all (not what you want, I know)
//float textX; // x position
float xspeed = 2.15; // fart som den bevæger sig på x-aksen
String [] words = {"vinterjazz", "01-24 feb. 2019", "www.jazz.dk"}; // string med de 3 sætninger
PFont font1;
int a;
float textX=10;
void setup() {
println(words.length);
size (700, 1000);
font1 = createFont ("Akkurat-Bold-18.vlw", 30);
textAlign(LEFT);
textX = 0;
frameRate(20);
fill( random(100, 255), random(100, 255), random(100, 255) );
a = int(random(words.length));
}
void draw() {
background (0);
textFont(font1, 30); // loader skrifttype
text(words[a], textX, 200); // String er genereret random
textX = textX + xspeed; // bevæg med xspeed til højre hvert loop
// bounce frem og tilbage
if (textX > width-textWidth(words[a])) {
xspeed = -abs(xspeed); //hvis tekst når width skal den gå modsat vej
}
if (textX < 0) { // hvis tekst når 0 skal den gå tilbage igen
xspeed = abs(xspeed);
}
//
}
here a version like from solub avbove in java
float location = 0;
float speed = 1.8;
int nLines = 32;
float step = 1000 / nLines;
String [] words = {"vinterjazz", "01-24 feb. 2019", "www.jazz.dk"};
float longestWord = 0.0;
String [] wordsList = new String[nLines];
void setup() {
size(700, 1000, P2D);
fill(255);
for (int i = 0; i < words.length; i++) {
longestWord = max(longestWord, textWidth(words[i]));
}
for (int i = 0; i < nLines; i++) {
wordsList[i] = words[int(random(words.length))];
}
}// function
void draw() {
background(0);
location += speed;
for (int i = 0; i < nLines; i++) {
text(wordsList[i], location, (i+1) * step);
}
if (location + longestWord >= width || location <= 0) {
speed *= -1;
}
}// function
similar but with different colors and different x pos (and speed) for each line:
int nLines = 32;
float step = 1000 / nLines;
String [] words = {"vinterjazz", "01-24 feb. 2019", "www.jazz.dk"};
float longestWord = 0.0;
String [] wordsList = new String[nLines];
float[] location = new float[nLines];
float[] speed = new float[nLines]; // 1.8
color[] col = new color[nLines];
void setup() {
size(600, 1000, P2D);
for (int i = 0; i < words.length; i++) {
longestWord = max(longestWord, textWidth(words[i]));
}
for (int i = 0; i < nLines; i++) {
wordsList[i] = words[int(random(words.length))];
location[i] = i*3.4;
speed[i] = 1.8;
col[i] = color ( random(100, 255), random(100, 255), random(100, 255));
}
}// function
void draw() {
background(0);
for (int i = 0; i < nLines; i++) {
fill ( col [i] );
text(wordsList[i],
location[i], (i+1) * step);
location[i] += speed[i];
if (location[i] + longestWord >= width || location[i] <= 0) {
speed[i] *= -1;
}
}//for
}// function