Headlines arrays with line break

Hi every one,
I’m working on that example of scrolling headlines from : scrollingtext | Learning Processing 2nd Edition
how can I “play” headlines vertically with a line break at the end of each headline
something like :

   pushMatrix() ;
    pushStyle();   

for (int i=0; i<headlines.length; i++) {
  
    text(headlines[i],width/2,100,'\n'); 
}
     popStyle();
    popMatrix();  


Thank’s for any help
Yves

Hi @yves,

Can you please elaborate on that? Maybe post a sketch of what it would look like.

If I understand correctly you mean displaying multiple headlines vertically and moving from top to bottom? Do they have different speed and timing?

thank’s for the answer,
I have these headlines :

// An array of news headlines
String[] headlines = {
  "Processing downloads break downloading record.", 
  "New study shows computer programming lowers cholesterol.",
"bla bla bla",
};

I want to make a text with the first and the second headline with a line break between them
something like :

   pushMatrix() ;
    pushStyle();   

for (int i=0; i<headlines.length; i++) {
  
    text(headlines[i],width/2,100,'\n'); 
}
     popStyle();
    popMatrix(); 

thank’s
Yves

Hi @yves,

you can play arround a bit with that, so you can find a way to do …

Cheers
— mnse

String[] lines;
color[]  colors;
int      lineHeight;

void setup() {
  size(600, 400);  
  textSize(40);
  
  lineHeight=int(textAscent()+textDescent());
  int maxLines = height / lineHeight;
  
  lines  = new String[maxLines];
  colors = new color[maxLines];
  colorMode(HSB, maxLines, 100, 100);
  for (int i = 0; i < maxLines; i++) {
    lines[i] = "I'm line "+(i+1)+" of "+maxLines+" lines...";     
    colors[i] = color(i, 100, 100);
  }
}

void draw() {
  background(0);  
  for (int i = 0, y = lineHeight; i < lines.length; i++, y+=lineHeight) {
    int idx = (int(frameCount/25)+i) % lines.length;
    fill(colors[idx]);
    text(lines[idx], 20, y);
  }
}

thank’s for the answer,
I’m in P3D mode, it’s not working with this mode,
But, I’ll try something like this
++
Yves

Hi @yves,

The above also works in P3D !? Below only P3D mode enabled …

String[] lines;
color[]  colors;
int      lineHeight;

void setup() {
  size(600, 400, P3D);  
  textSize(40);
  
  lineHeight=int(textAscent()+textDescent());
  int maxLines = height / lineHeight;
  
  lines  = new String[maxLines];
  colors = new color[maxLines];
  colorMode(HSB, maxLines, 100, 100);
  for (int i = 0; i < maxLines; i++) {
    lines[i] = "I'm line "+(i+1)+" of "+maxLines+" lines...";     
    colors[i] = color(i, 100, 100);
  }
}

void draw() {
  background(0);    
  for (int i = 0, y = lineHeight; i < lines.length; i++, y+=lineHeight) {
    int idx = (int(frameCount/25)+i) % lines.length;
    fill(colors[idx]);
    text(lines[idx], 20., y);
  }
}

Cheers
— mnse

1 Like