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
Acrostic issues (Read 244 times)
Acrostic issues
Feb 17th, 2008, 5:07pm
 
I'm new to processing and I am trying to make an acrostic. The issues I am having are:

A. hitting the backspace isn't visibly remove the letter.

B. I can't figure out how to create a text field for each letter. I can create static fields but I can't get it to generate a field for each letter in the word.
I am not sure what I am doing wrong.

here's my code:

void setup() {
 size(640,530);
 colorMode(RGB, 255, 255, 255);
 background(0, 0, 25);
 
 //loads the font
 PFont font;
 font = loadFont("Andalus-48.vlw");
 textFont (font, 48);

 //loads the data from the text file and
 //coverts it into an array.
 String words[] = loadStrings("wordlist.txt");

 //displays a random word from the array
 float y = random(words.length-1);
 int x = round(y);
 text (words[x], 250, 50);

 //splits the word into the letters then displays them vertically
 String letters[] = splitTokens(words[x], " ");
 int i= 0;
 int Height = (400/letters.length);
 for (int c=0; c < letters.length; c++) {
   i++;
   int Height2 = Height * i;
   text (letters[i-1], 100, (Height2 + 40));
 }
}
String typed = "";

//copied from the book. this displays the string that is
//being edited by my typing. I think it is rendering a new
//object each time I press a button instead of rerendering
//the current one.
void draw() {
 float cursorPosition = textWidth(typed);
 line(cursorPosition, 100, cursorPosition, 100);
 text(typed, 0, 50);
}
void keyPressed() {
 if (key == BACKSPACE) {
   if (typed.length() > 0) {
     typed = typed.substring(0, typed.length()-1);
   }
 }
 else if (textWidth(typed+key) < width){
   typed = typed+key;
 }
}
Re: Acrostic issues
Reply #1 - Feb 17th, 2008, 9:39pm
 
A. in your draw loop, clear the screen before displaying your string : background(0);

Page Index Toggle Pages: 1