# Text(); questions. Color and other

**URL:** <https://discourse.processing.org/t/text-questions-color-and-other/18174>\
**Category:** Beginners\
**Created:** [February 27, 2020, 10:51am UTC](https://discourse.processing.org/t/text-questions-color-and-other/18174 "2020-02-27T10:51:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)\
**Post date:** [February 27, 2020, 10:51am UTC](https://discourse.processing.org/t/text-questions-color-and-other/18174/1 "2020-02-27T10:51:10Z")

</div>

Hello.  
Just a few questions.

1. I know that you can paste text to a new line in text ();  
But I could not figure out how to do this?  
Can a simple example, I’ll figure it out.

2. The question is also about text ();  
Is it possible to make the text color change right in the middle? Or not?

Thanks in advance.  
The forum helps me a lot. You are best.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 27, 2020, 10:55am UTC](https://discourse.processing.org/t/text-questions-color-and-other/18174/2 "2020-02-27T10:55:35Z")

</div>

1. 

> [@NoName](#):
>
> text to a new line in text ();  
> But I could not figure out how

```auto
fill(245,0,0); 
text("Hello \nNew line", 14, 14);

```

---

<div class="post-metadata">

**Author:** ![Waboqueox](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/waboqueox/32/5643_2.png) [@Waboqueox](https://discourse.processing.org/u/Waboqueox)\
**Post date:** [February 27, 2020, 11:16am UTC](https://discourse.processing.org/t/text-questions-color-and-other/18174/3 "2020-02-27T11:16:49Z")

</div>

1. 

> [@NoName](#):
>
> The question is also about text ();  
> Is it possible to make the text color change right in the middle? Or not?

```auto
fill(245,0,0); 
text("Hello", 14, 14);
fill(0,255,0); 
text("\nNew line", 14, 14);

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 27, 2020, 11:57am UTC](https://discourse.processing.org/t/text-questions-color-and-other/18174/4 "2020-02-27T11:57:01Z")

</div>

> [@Waboqueox](#):
>
> fill(245,0,0); text(“Hello”, 14, 14); fill(0,255,0); text(“\nNew line”, 14, 14);

Or in one line:

```auto
size(333, 333); 

background(0);

fill(245, 0, 0); 
text("Hello", 14, 14);
float xlen=textWidth("Hello"); 
fill(0, 255, 0); 
text("New text color", 14+xlen, 14);

```

---

<div class="post-metadata">

**Author:** ![NoName](https://avatars.discourse-cdn.com/v4/letter/n/58f4c7/32.png) [@NoName](https://discourse.processing.org/u/NoName)\
**Post date:** [February 27, 2020, 9:51pm UTC](https://discourse.processing.org/t/text-questions-color-and-other/18174/5 "2020-02-27T21:51:40Z")

</div>

Thanks a lot!)

By the way, Chrisir has been helping (saving) me many times already. You are the best.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [March 4, 2020, 8:30pm UTC](https://discourse.processing.org/t/text-questions-color-and-other/18174/6 "2020-03-04T20:30:35Z")

</div>

> [@NoName](#):
>
> The question is also about text ();  
> Is it possible to make the text color change right in the middle? Or not?

You cannot pass a single string to `text()` with multiple fills. However, you can call  
`text()` multiple times. To align segments on a single line, use `textWidth()` to determine the offset.

```auto
String s1 = "Hello";
String s2 = " colorful";
String s3 = " World";
size(200, 100);
float offset = 10;
fill(0, 192, 0);
text(s1, offset, height/2);
offset += textWidth(s1);
fill(255, 0, 0);
text(s2, offset, height/2);
offset += textWidth(s2);
fill(0, 0, 255);
text(s3, offset, height/2);

```

Here it is with an array of words and colors, plus a loop:

```auto
String[] ss = new String[]{"Hello", " colorful", " World"};
color[] cc = new color[]{color(0, 192, 0), color(255, 0, 0), color(0, 0, 255)};
size(200, 100);
pushMatrix();
translate(10, height/2.0);
for(int i=0; i<ss.length; i++) {
  fill(cc[i]);
  text(ss[i],0,0);
  translate(textWidth(ss[i]), 0);
}
popMatrix();

```
