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.
IndexProgramming Questions & HelpSyntax Questions › Simple interactive typography...
Page Index Toggle Pages: 1
Simple interactive typography... (Read 353 times)
Simple interactive typography...
May 20th, 2009, 5:17am
 
Hello,

I'm new to processing, and am working on several sketches which use input from the keyboard to set parameters for specific animations.

I'm having trouble conjuring the code (or finding appropriate code/libraries to borrow from  Wink) to create an input text field which will then generate info based on the stored text.

I.E. Like a chat client, where you type your message, then hit "send", except rather than seeing that message appear, it's contents will be used as input for a separate function.

Here is an example of what I've got so far:

PFont drawFont;
char[] nextPhrase, drawPhrase;
float[] xLocation, yLocation, xDestination, yDestination;
int nextCharIndex = 0;  
int numChars = 40;

void setup() {
 size(720, 480);
 nextPhrase = new char[numChars];
 drawPhrase = new char[numChars];
 xLocation = new float[numChars];
 yLocation = new float[numChars];
 xDestination = new float[numChars];
 yDestination = new float[numChars];

 for(int ii = 0; ii < numChars; ii++) {
   nextPhrase[ii] = ' ';
   drawPhrase[ii] = ' ';
   xLocation[ii] = 0;
   yLocation[ii] = 0;
   xDestination[ii] = 0;
   yDestination[ii] = 0;
 }

 smooth();
 fill(255);

 drawFont = loadFont("HelveticaNeue-24.vlw");

 textFont(drawFont);
}

void draw() {
 background(0);

 for(int ii = 0; ii < numChars; ii++) {

   text(drawPhrase[ii], xLocation[ii], yLocation[ii]);

   if(abs(xLocation[ii] - xDestination[ii]) > 0.1) {

     xLocation[ii] = xLocation[ii] + ((xDestination[ii] - xLocation[ii]) / 10);

   } else {
     xLocation[ii] = xDestination[ii];
   }

   if(abs(yLocation[ii] - yDestination[ii]) > 0.1) {
     yLocation[ii] = yLocation[ii] + ((yDestination[ii] - yLocation[ii]) / 10);
   } else {
     yLocation[ii] = yDestination[ii];
   }    
 }
}

void keyPressed() {
 

 nextPhrase[nextCharIndex] = key;


 nextCharIndex = (nextCharIndex + 1) % numChars;
}

void mousePressed() {

 nextCharIndex = 0;
 float kerningWidth = 0;
 for(int ii = 0; ii < numChars; ii++) {

   drawPhrase[ii] = nextPhrase[ii];

   xLocation[ii] = random(720);
   yLocation[ii] = random(480);

   xDestination[ii] = mouseX + kerningWidth;
   yDestination[ii] = mouseY;

   nextPhrase[ii] = ' ';

   kerningWidth = kerningWidth + textWidth(drawPhrase[ii]); // total character width so far
 }
}

But I want the message to be displayed AS you type it, with dynamic, selectable text like in the text fields in the Interfascia library.  I would just use that library, but as a newbie to processing I don't know how to work with custom libraries.

Any help or advice would be greatly appreciated!  Thanks.

- Tmnt

Page Index Toggle Pages: 1