I have been working on a function to draw a text string of any size and wrap it to a certain width and justify the text by adding spaces. I have it working however the spaces are added to each line starting from the left until the line is the correct width which makes it look kind of off-balance. Here is a screen-shot of the system and I have replaced the added spaces with "#" to make it more clear what I mean.
I am just not sure of the best way to evenly disperse the spaces over the whole line without things getting pretty messy. My closest attempt so far was to divide the number of spaces on a line by the number of spaces needed to be added and then loop through the characters on the line and add a space to every nth space however sometimes too many or too few spaces were added which ruined the justification. Any ideas or points to resources would be much appreciated!
I am just not sure of the best way to evenly disperse the spaces over the whole line without things getting pretty messy. My closest attempt so far was to divide the number of spaces on a line by the number of spaces needed to be added and then loop through the characters on the line and add a space to every nth space however sometimes too many or too few spaces were added which ruined the justification. Any ideas or points to resources would be much appreciated!