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 › Keyboard input — just a simple typewriter
Page Index Toggle Pages: 1
Keyboard input — just a simple typewriter (Read 890 times)
Keyboard input — just a simple typewriter
Sep 13th, 2005, 2:35pm
 
I am trying to create a typewriter that spans the whole width and lenght of the page.[I've searched and searched but all I found were complicated expamples]. All I want is to type a text and to have it appear on the canvas, when the line reaches the right canvas border have it go to x = 0 and y = lastLine.y + character.height. As simple as it gets. I'm trying to work from Nimoy's version, which only allows for one line. If anyone could help me I would very much apreciate it.

PFont f;
int leftmargin = 10;
int rightmargin = width;
String buff = "";

void setup() { ... }

void draw()
{

 fill(0);
 pushMatrix();
 translate(rPos,10+25);
 char k;
 for(int i=0;i<buff.length();i++){
   k = buff.charAt(i);
   translate(-textWidth(k),0);  
  // scale(1.1);
    text(k,0,0);
 }
 popMatrix();
}

void keyPressed() {

 char k;

  k = (char)key;

  switch(k){
   case 8:                         // delete
   if(buff.length()>0){ buff = buff.substring(1); }
   break;

   case 13:  // enter key - How do I get the text to go to the next line
   
   text(k,0, (present character y position + characterHeight) );
   
   break;
   default:
   if(textWidth(buff+k)+leftmargin < width-rightmargin){
     buff= k+buff;
   }
   
   break;
 }
}
Re: Keyboard input — just a simple typewriter
Reply #1 - Sep 13th, 2005, 3:53pm
 
processing provides a form of text(..) that will do multiple lines already:

text(String,x,y,width,height);

so: text(k,leftmargin,35,width-leftmargin,height-35); should do what you want.
Re: Keyboard input — just a simple typewriter
Reply #2 - Sep 13th, 2005, 4:06pm
 
Thank you for your reply.
However I still get:

Perhaps you wanted the overloaded version "void text(java.lang.String $1, float $2, float $3, float $4, float $5);" instead?

any ideas on how to solve this?
Re: Keyboard input — just a simple typewriter
Reply #3 - Sep 13th, 2005, 4:58pm
 
it should be text(buff, ...) not text(k, ...) so that it'll do your whole text block.
Page Index Toggle Pages: 1