Text Wall
in
Programming Questions
•
1 years ago
Hello all I'm trying to create a "wall of text" in processing and I have come to a bit of a problem. I'm not sure what the best method is for knowing exactly how many I can have in my string that will basically take up exactly one half of the screen. The idea is to populate this string with that many characters and continue to replace characters in that string. I'm wondering if the text() functions width parameter automatically adds in \n characters or if there is a better way of addressing this problem.
Any help/advice is appreciated.
Thanks!
EDIT:
I have found a method of doing this after banging my head against a few walls. I created my own version of the width parameter in the text() method. I created a variable to only monitor the text of a single line instead of the whole string. This is the keyPressed code with the magic happening.
Any help/advice is appreciated.
Thanks!
EDIT:
I have found a method of doing this after banging my head against a few walls. I created my own version of the width parameter in the text() method. I created a variable to only monitor the text of a single line instead of the whole string. This is the keyPressed code with the magic happening.
- void keyPressed() {
- if (keyCode >=32 && keyCode <=126) {
- s.append(key);
- stringLength += textWidth(key);// stringLength will append textwidths of the keys pressed per line of text
- if (stringLength >= (width/2)) {
- // if the length of this variable is longer than the desired witdh(in my case half the screen width)
- s.append("\n");//append a new line
- stringLength -= width/2;// subtract the desired with from the var (ie resetting it to the new line)
- if(stringLength <0)stringLength = 0;// if you are in a situation where you need a buffer/padding (ex the //if statement is like if(stringLength >=(width/2) -5) for 5 px padding on the right side, this will just restart u //at the 0 marker instead of at a negativ number
- }
- }
- }
1