We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
text formatting (Read 380 times)
text formatting
Apr 23rd, 2009, 9:28am
 
Hi, I am new to Processing and I was wondering if anyone could help me with this:
I have this text file uploaded into a string array and it runs over 4 lines (elements 0,1,2,3)
I have to center the first two lines
And format the [3] 4th line so that it runs over many lines and is left aligned.
here is a some copies of my setup and draw:

void setup()
{
 size(600, 600);

//this is the information used for the text and font
 font = loadFont("Tahoma-48.vlw");

 textFont(font, 16);
 textAlign(LEFT);
 smooth();
 
 prose = loadStrings("prose.txt");

 lineHeight = textDescent() + textAscent();
 x = 10;
 y = lineHeight;

}

void draw()
{
 background(32);
 
 fill(255);

 y = lineHeight;

 for(int i = 0; i < prose.length; i++)
 {
   text(prose[i], x, y);
       
   float lineWidth = textWidth(prose[i]);
 
   y += lineHeight;
//formatting the first two lines
   prose[0] = prose[0].toUpperCase();
   stroke(255);
   line(x,lineHeight,textWidth(prose[0]),lineHeight);
   prose[1] = prose[1].toLowerCase();
   
 }

Huh
Page Index Toggle Pages: 1