# Headlines arrays with line break

**URL:** https://discourse.processing.org/t/headlines-arrays-with-line-break/38918
**Category:** Coding Questions
**Created:** [September 21, 2022, 3:42pm UTC](https://discourse.processing.org/t/headlines-arrays-with-line-break/38918 "2022-09-21T15:42:39Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![yves](https://avatars.discourse-cdn.com/v4/letter/y/9e8a1a/32.png) [@yves](https://discourse.processing.org/u/yves)
#### Post date: [September 21, 2022, 3:42pm UTC](https://discourse.processing.org/t/headlines-arrays-with-line-break/38918/1 "2022-09-21T15:42:39Z")

</div>

Hi every one,  
I’m working on that example of scrolling headlines from : [scrollingtext | Learning Processing 2nd Edition](http://learningprocessing.com/examples/chp17/example-17-03-scrollingtext)  
how can I “play” headlines vertically with a line break at the end of each headline  
something like :

```auto
   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

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [September 22, 2022, 7:25am UTC](https://discourse.processing.org/t/headlines-arrays-with-line-break/38918/2 "2022-09-22T07:25:40Z")

</div>

Hi @yves,

> [@yves](#):
>
> how can I “play” headlines vertically with a line break at the end of each headline

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?

---

<div class="post-metadata">

### Author: ![yves](https://avatars.discourse-cdn.com/v4/letter/y/9e8a1a/32.png) [@yves](https://discourse.processing.org/u/yves)
#### Post date: [September 24, 2022, 9:00am UTC](https://discourse.processing.org/t/headlines-arrays-with-line-break/38918/3 "2022-09-24T09:00:33Z")

</div>

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

```auto
// 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 :

```auto
   pushMatrix() ;
    pushStyle();   

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

```

thank’s  
Yves

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [September 24, 2022, 9:45am UTC](https://discourse.processing.org/t/headlines-arrays-with-line-break/38918/4 "2022-09-24T09:45:20Z")

</div>

Hi @yves,

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

Cheers  
— mnse

```auto
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);
  }
}

```

---

<div class="post-metadata">

### Author: ![yves](https://avatars.discourse-cdn.com/v4/letter/y/9e8a1a/32.png) [@yves](https://discourse.processing.org/u/yves)
#### Post date: [September 24, 2022, 9:51am UTC](https://discourse.processing.org/t/headlines-arrays-with-line-break/38918/5 "2022-09-24T09:51:59Z")

</div>

> [@mnse](#):
>
> ```auto
> 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

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [September 24, 2022, 10:13am UTC](https://discourse.processing.org/t/headlines-arrays-with-line-break/38918/6 "2022-09-24T10:13:07Z")

</div>

Hi @yves,

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

```auto
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
