# Replace words with different synonyms and print each combination in a text file

**URL:** <https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110>\
**Category:** Coding Questions\
**Created:** [January 16, 2021, 10:57am UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110 "2021-01-16T10:57:42Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sophie](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@Sophie](https://discourse.processing.org/u/Sophie)\
**Post date:** [January 16, 2021, 10:57am UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/1 "2021-01-16T10:57:42Z")

</div>

Hello,

My goal is to replace words from a String with synonyms. Right now the code can replace one word with another one and write the sentence in my text file. But I would like to have different opportunities to replace the words randomly and write the different sentences with the different combinations to my text file. Is there any way to do so? I am very new to Processing and couldn’t find any solution. So I would be grateful for any help. Thanks in advance!

Sophie

Oh and in addition another question would be: Is it possible to add random text sizes to the words as well? Many thanks!!

```auto
PrintWriter output;

String s = "Wie froh bin ich, daß ich weg bin! Bester Freund, was ist das Herz des Menschen! Dich zu verlassen, den ich so liebe, von dem ich unzertrennlich war, und froh zu sein!";

void setup() {
  size(600,360);
  background(255);
}

void draw() {

s = s.replaceAll("Wie", "Und");
s = s.replaceAll("froh", "ausgelassen");
s = s.replaceAll("bin", "bin");
s = s.replaceAll("ich", "ich");
s = s.replaceAll("daß", "daß");
s = s.replaceAll("weg", "fort");
s = s.replaceAll("Bester", "Erster");
s = s.replaceAll("Freund", "Vertrauter");
s = s.replaceAll("was", "was");
s = s.replaceAll("ist", "befindet");
s = s.replaceAll("das", "das");
s = s.replaceAll("Herz", "Zentrum");
s = s.replaceAll("des", "des");
s = s.replaceAll("Menschen", "Sterblichen");
s = s.replaceAll("verlassen", "entfernen");
s = s.replaceAll("liebe", "anbete");
s = s.replaceAll("unzertrennlich", "vertraut");
s = s.replaceAll("sein", "entstammen");

output = createWriter("positions.text");
output.print(s);

output.flush();
output.close();

stop();
}

```

---

<div class="post-metadata">

**Author:** ![ReyzArtz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/reyzartz/32/11750_2.png) [@ReyzArtz](https://discourse.processing.org/u/ReyzArtz)\
**Post date:** [January 16, 2021, 1:31pm UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/2 "2021-01-16T13:31:31Z")

</div>

for getting a random sentence every time try this

```auto
PrintWriter output;

String s = "Wie froh bin ich, daß ich weg bin! Bester Freund, was ist das Herz des Menschen! Dich zu verlassen, den ich so liebe, von dem ich unzertrennlich war, und froh zu sein!";

void setup() {
  size(600,360);
  background(255);
}

void draw() {
   if(random(100)<20)
      s = s.replaceAll("Wie", "Und");
   if(random(100)<20)
      s = s.replaceAll("froh", "ausgelassen");
   if(random(100)<20)
      s = s.replaceAll("bin", "bin");
   if(random(100)<20)
      s = s.replaceAll("ich", "ich");
   if(random(100)<20)
      s = s.replaceAll("daß", "daß");
   if(random(100)<20)
      s = s.replaceAll("weg", "fort");
   if(random(100)<20)
      s = s.replaceAll("Bester", "Erster");
   if(random(100)<20)
      s = s.replaceAll("Freund", "Vertrauter");
   if(random(100)<20)
      s = s.replaceAll("was", "was");
   if(random(100)<20)
      s = s.replaceAll("ist", "befindet");
   if(random(100)<20)
      s = s.replaceAll("das", "das");
   if(random(100)<20)
      s = s.replaceAll("Herz", "Zentrum");
   if(random(100)<20)
      s = s.replaceAll("des", "des");
   if(random(100)<20)
      s = s.replaceAll("Menschen", "Sterblichen");
   if(random(100)<20)
      s = s.replaceAll("verlassen", "entfernen");
   if(random(100)<20)
      s = s.replaceAll("liebe", "anbete");
   if(random(100)<20)
      s = s.replaceAll("unzertrennlich", "vertraut");
   if(random(100)<20)
      s = s.replaceAll("sein", "entstammen");

output = createWriter("positions.text");
output.print(s);

output.flush();
output.close();

stop();
}

```

Since u are new to processing I tried to write a simple solution in which each word now has a 20% chance of being replaced and for random text size use this reference  
[textSize()](https://processing.org/reference/textSize_.html) add textSize(random(50)); this might just do the trick let me know if it works or not

---

<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:** [January 16, 2021, 1:47pm UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/3 "2021-01-16T13:47:24Z")

</div>

> [@Sophie](#):
>
> add random text sizes to the words

Do you mean to store this as a text file?? I don’t think that’s a good idea.  
Instead you can just have them on the screen and save an image of it using save() or saveFrame();

```auto

// WILL OVERWRITE OLD IMAGES !!!!!

PrintWriter output;

String s = "Wie froh bin ich, daß ich weg bin! Bester Freund, was ist das Herz des Menschen! Dich zu verlassen, den ich so liebe, von dem ich unzertrennlich war, und froh zu sein!";

void setup() {
  size(1900, 760);
  background(255);
}

void draw() {
  if (random(100)<20)
    s = s.replaceAll("Wie", "Und");
  if (random(100)<20)
    s = s.replaceAll("froh", "ausgelassen");
  if (random(100)<20)
    s = s.replaceAll("bin", "bin");
  if (random(100)<20)
    s = s.replaceAll("ich", "ich");
  if (random(100)<20)
    s = s.replaceAll("daß", "daß");
  if (random(100)<20)
    s = s.replaceAll("weg", "fort");
  if (random(100)<20)
    s = s.replaceAll("Bester", "Erster");
  if (random(100)<20)
    s = s.replaceAll("Freund", "Vertrauter");
  if (random(100)<20)
    s = s.replaceAll("was", "was");
  if (random(100)<20)
    s = s.replaceAll("ist", "befindet");
  if (random(100)<20)
    s = s.replaceAll("das", "das");
  if (random(100)<20)
    s = s.replaceAll("Herz", "Zentrum");
  if (random(100)<20)
    s = s.replaceAll("des", "des");
  if (random(100)<20)
    s = s.replaceAll("Menschen", "Sterblichen");
  if (random(100)<20)
    s = s.replaceAll("verlassen", "entfernen");
  if (random(100)<20)
    s = s.replaceAll("liebe", "anbete");
  if (random(100)<20)
    s = s.replaceAll("unzertrennlich", "vertraut");
  if (random(100)<20)
    s = s.replaceAll("sein", "entstammen");

  output = createWriter("positions.text");

  int x=30;
  int y=200; 
  fill(0); 
  for (String wordIn : s.split(" ")) {
    textSize(random(9, 56)); 
    text (wordIn, x, y); 
    x+=textWidth(wordIn)+6;
    if (wordIn.indexOf("!") > 0) {
      x=30; 
      y+=90;
    }
  }
  //output.print(s);

  //output.flush();
  //output.close();

  stop();
  save("t1.jpg"); 
  noLoop();
}

```

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 16, 2021, 3:52pm UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/6 "2021-01-16T15:52:56Z")

</div>

here is a program I made : P, use the addWord(word,“syn1,syn2,syn3,…”) to add words. Good luck

> **Code**
>
> ```auto
> ArrayList<String> documented = new ArrayList<String>(), words = new ArrayList<String>();
> ArrayList<ArrayList<String>> syn = new ArrayList<ArrayList<String>>();
> String text = "the new world is a small world";
> char acceptable[] = ("aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789").toCharArray();
> 
> void setup() {
> size(600,600);
> addWord("small","meager,minuscule,paltry");
> addWord("new","novel,current,modern");
> printArray(documented);
> printArray(syn);
> splitWords();
> printArray(words);
> for(int i = 0; i < words.size(); i++) print(wordSwap(words.get(i))+ " ");
> }
> void draw() {
> }
> void addWord(String word, String syn_s) {
> documented.add(word);
> String syn_s2[] = split(word+","+syn_s,",");
> ArrayList<String> syn_s3 = new ArrayList<String>();
> for(int i = 0; i < syn_s2.length; i++) syn_s3.add(syn_s2[i]);
> syn.add(syn_s3);
> }
> void splitWords() {
> String words_[] = split(text, " ");
> for(int i = 0; i < words_.length; i++) words.add(purify(words_[i]));
> }
> 
> String wordSwap(String word) {
> if(documented.contains(word)) {
> int pos = getIndex(documented,word);
> //if(pos != -1) return syn.get(pos).get(floor(random(syn.get(pos).size())));
> if(pos != -1) {
> return syn.get(pos).get(floor(random(syn.get(pos).size())));
> }
> //syn.get(index).get(floor(random(syn.get(index).size()))))
> }
> return word;
> }
> 
> int getIndex(ArrayList<String> reference, String item) {
> for(int i = 0; i < reference.size() && reference.contains(item); i++) if(reference.get(i).equals( item )) return i;
> return -1;
> }
> 
> String purify(String input) {
> String newString = "";
> for (int i = 0; i < input.length(); i++) for (int j = 0; j < acceptable.length; j++) if (input.charAt(i) == acceptable[j]) {
> newString += acceptable[j];
> break;
> }
> return newString;
> }
> 
> ```

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/9eef213bb12bfa7d84ccd62bc741341eb7aa326c.png)

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [January 16, 2021, 3:53pm UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/7 "2021-01-16T15:53:33Z")

</div>

Hello,

An example for you:

```auto
String words1[] = {"Wie", "Und", "froh", "ausgelassen", "bin", "ich", "daß"};

String s = "Wie froh bin ich, daß ich weg bin! Bester Freund, was ist das Herz des Menschen! Dich zu verlassen, den ich so liebe, von dem ich unzertrennlich war, und froh zu sein!";

void setup() 
  {
  for(int i=0; i<words1.length; i++)
    {
    print(words1[i] + " ");
    }
    
    int r1 = int( random(words1.length));
    int r2 = int( random(words1.length));
    s = s.replaceAll( words1[r1], words1[r2] );
    
    println(r1, r2, words1[r1], words1[r2]);
    println(s);
    
  noLoop();  
  }

```

You can also do this with:  
[https://processing.org/reference/StringList.html](https://processing.org/reference/StringList.html)

`:)`

---

<div class="post-metadata">

**Author:** ![Sophie](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@Sophie](https://discourse.processing.org/u/Sophie)\
**Post date:** [January 16, 2021, 4:41pm UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/8 "2021-01-16T16:41:38Z")

</div>

Many thanks! I try to understand what you did. Is there also a way to print every possible combination?

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 16, 2021, 4:42pm UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/9 "2021-01-16T16:42:54Z")

</div>

yes there is! Give me a few minutes, I’ll write a simple program that shows you how

edit: It is more difficult than expected. The main issue I found was the unconstant amount of things you need to change.  
So if you have: a = {a,b,c} b = {b,c,d} c = {e,a,t},…  
you need a for loop for each and every one of them.

so:  
abe ace ade  
aba aca ada  
abt act adt

bbe ace ade  
bba aca ada  
bbt act at

cbe ace ade  
cba aca ada  
cbt act at

in short, you need an `n` amount of for loops.

here is a program with 2 variable segments:

> **Code (for 2 only)**
>
> ```auto
> String a[] = {"1","2","3","4"}, b[] = {"a","b","c","d"};
> ArrayList<String> use = new ArrayList<String>();
> void setup() {
> size(600,600);
> }
> void draw() {
>   
> for(int i = 0; i < a.length; i++) {
> for(int j = 0; j < b.length; j++) {
> println(a[i],b[j]);
> }
> }
>   
> noLoop();
> }
> 
> ```

1 a1 b1 c1 d  
2 a2 b2 c2 d  
3 a3 b3 c3 d  
4 a4 b4 c4 d

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 16, 2021, 5:01pm UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/10 "2021-01-16T17:01:52Z")

</div>

i found a way! Coding it rn

---

<div class="post-metadata">

**Author:** ![Sophie](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@Sophie](https://discourse.processing.org/u/Sophie)\
**Post date:** [January 16, 2021, 5:04pm UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/11 "2021-01-16T17:04:13Z")

</div>

Thanks for the advice! I now wrote a code, where every line of my text just has a random text size on the screen. I don’t really understand how you managed to begin a new row when my line is longer than the width of the screen. Or how to write every line under the previous line and not in the next frame. Could you help me with that?

```auto
 PFont font;

  String [] lines;
  int index = 0;

void setup() {
  size(1100,800);
  font = createFont("Menlo-Regular", 20);
  String [] s = loadStrings("DieLeidendesjungenWerther.txt");
  String everything = join(s, " ");
  println(everything);
  lines = splitTokens(everything,",.?!;:");
  printArray(lines);
  frameRate(2);
}

void draw() {
  background(0);
  textFont(font);
  textSize(random(12,200));
  text(lines[index], 10, 200);
  index++;

}

```

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 16, 2021, 5:28pm UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/12 "2021-01-16T17:28:50Z")

</div>

I made the program! It will generate `n` options for a tower. Every tower is tall `random(min,max)`. It will generate every possibility. For now, every tower’s floor are just numbers. (tower with 3 floor has numbers: 0,1,2, one with 5 floors has numbers: 0,1,2,3,4 and so on). Now just plug in the words!

this is the principle behind its workings:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/1159fee1c2c08af9e8563eb13da5b16f8e884ab8.png)

> **Code**
>
> ```auto
> ArrayList<Integer> sizes = new ArrayList<Integer>();
> int n = 5, min = 1, max = 5, path[] = new int[n];
> boolean end = false;
> void setup() {
> size(600, 600);
> for (int i = 0; i < n; i++) sizes.add((int)random(min, max));
> printArray(sizes);
> printArray(path);
> }
> void draw() {
> takePath(path);
> for (int i = 0; i < n; i++) {
> print(path[i]);
> }
> println();
> if (end) noLoop();
> }
> 
> void takePath(int pPath[]) {
> pPath[n-1]++;
> for (int i = n-1; i >= 0; i--) {
> if (pPath[i] >= sizes.get(i)) {
> pPath[i] = 0;
> if (i > 0) {
> pPath[i-1]++;
> } else {
> end = true;
> }
> }
> }
> path = pPath;
> }
> 
> ```

---

<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:** [January 16, 2021, 5:28pm UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/13 "2021-01-16T17:28:58Z")

</div>

> [@Chrisir](#):
>
> ```auto
> if (wordIn.indexOf("!") > 0) {
> x=30; 
> y+=90;
> }
> 
> ```

That’s going into the next line

---

<div class="post-metadata">

**Author:** ![Sophie](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@Sophie](https://discourse.processing.org/u/Sophie)\
**Post date:** [January 16, 2021, 7:19pm UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/14 "2021-01-16T19:19:27Z")

</div>

Sorry, but now it’s not

```auto
newWord(word,“syn1,syn2,syn3,…”)

```

anymore. Do I have to add the words with path?

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 16, 2021, 9:03pm UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/15 "2021-01-16T21:03:06Z")

</div>

Yeah, I used the wrong thing. There was a blackout where I live so in the end I had to rewrite the code several times because it didn’t save. I used different variable/funtion names. : P

> [@Sophie](#):
>
> `newWord(word,“syn1,syn2,syn3,…”)`

> [@CodeMasterX](#):
>
> addWord(word,“syn1,syn2,syn3,…”);

example is:

> [@CodeMasterX](#):
>
> `addWord("new","novel,current,modern");`

---

<div class="post-metadata">

**Author:** ![Sophie](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@Sophie](https://discourse.processing.org/u/Sophie)\
**Post date:** [January 17, 2021, 9:24am UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/16 "2021-01-17T09:24:26Z")

</div>

But I don’t really understand where to put the words in the program that generates n options for the towers.

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [January 17, 2021, 9:51am UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/17 "2021-01-17T09:51:35Z")

</div>

How are you sourcing your synonims are you using a dictionary of sort?

---

<div class="post-metadata">

**Author:** ![Sophie](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@Sophie](https://discourse.processing.org/u/Sophie)\
**Post date:** [January 17, 2021, 10:02am UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/18 "2021-01-17T10:02:20Z")

</div>

Yes I search for the synonyms in a dictionary

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 17, 2021, 11:49am UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/19 "2021-01-17T11:49:50Z")

</div>

just create a tower by

```auto
ArrayList<ArrayList<String>> towers = new ArrayList<ArrayList<String>>();

void addTower(String info) {
   String a[] = split(info,",");
   ArrayList<String> tower = new ArrayList<String>();
   for(int i = 0; i < a.length; i++) tower.add(a[i]);
   towers.add(tower);
}
//after doing this, access it with
String acess(int towerID, int towerLevel) {
    return( towers.get(towerID).get(towerLevel) );
}
//so with: (I don't remember the names I used before)
void draw() {
    for(int i = 0; i < towers.size(); i++) {
         println( towers.get(i).path[i] );
    }
    noLoop();
}

```

---

<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:** [January 18, 2021, 9:23am UTC](https://discourse.processing.org/t/replace-words-with-different-synonyms-and-print-each-combination-in-a-text-file/27110/20 "2021-01-18T09:23:58Z")

</div>

> [@Sophie](#):
>
> I don’t really understand how you managed to begin a new row when my line is longer than the width of the screen.

(I am just referring to this part of the discussion, no mixing of words)

here is a version where you can hit a key to get a new screen

(text parts in different sizes)

```auto

PFont font;

String [] lines;
int index = 0;

void setup() {
  size(1700, 1000);
  font = createFont("Menlo-Regular", 20);
  // String [] s = loadStrings("DieLeidendesjungenWerther.txt");

  String everything; // = join(s, " ");
  everything = "Wie froh bin ich, daß ich weg bin! Bester Freund, was ist das Herz des Menschen! Dich zu verlassen, den ich so liebe, von dem ich unzertrennlich war, und froh zu sein!"; 

  println(everything);
  lines = splitTokens(everything, ",.?!;:");
  // printArray(lines);
  textFont(font);
  frameRate(2);
}

void draw() {
  background(0);
  int y=7; 
  for (int index=0; index<lines.length; index++) {
    textSize(random(12, 200));
    float a1= textAscent() + textDescent(); // adding the textAscent() and textDescent() values will give you the total height of the line.

    y+=a1+13;
    text(lines[index], 10, y);
  }
  noLoop();
}

void keyPressed() {
  redraw();
}

```

* * *

**In this version lines appear one by one**

```auto
PFont font;

String [] lines;
int index = 0;

int y=7; 

boolean stopFlag=false;

void setup() {
  size(1700, 1000);
  font = createFont("Menlo-Regular", 20);
  // String [] s = loadStrings("DieLeidendesjungenWerther.txt");

  String everything; // = join(s, " ");
  everything = "Wie froh bin ich, daß ich weg bin! Bester Freund, was ist das Herz des Menschen! Dich zu verlassen, den ich so liebe, von dem ich unzertrennlich war, und froh zu sein!"; 

  println(everything);
  lines = splitTokens(everything, ",.?!;:");
  // printArray(lines);
  textFont(font);
  frameRate(2);
  background(0);
}

void draw() {

  if ( ! stopFlag ) {
    textSize(random(12, 200));
    float a1= textAscent() + textDescent(); // adding the textAscent() and textDescent() values will give you the total height of the line.
    y+=a1+13;
    text(lines[index], 10, y);
  }

  if (index<lines.length-1) {
    index++;
  } else {
    stopFlag=true;
  }
}

void keyPressed() {
  // reset 
  println("key");
  background(0);
  clear();
  index=0;
  y=7;
  stopFlag=false;
}

```

line break is not when the  
line is longer than the width of the screen  
but I just display the content of the lines array item by item.

 ![xsdf](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f65a64fb513d771f71d9b28d8f28173ca4571bdb.png)

Chrisir
