PFont font;
Letter[] name = new Letter[24];
int letter_width = 8;
String name_array = "P a u l  T u r o w s k i";
float xtime = 0.0;  //noise x
float ytime = 100.0; //noise y
float TIME_INC = .0005;
float X_MF = 5.0;
float Y_MF = 3.0;

void setup(){
  size(200, 50);
  frameRate(10);

  font = loadFont("Courier New");
  textFont(font, 24);
  
  for(int i=0; i<name.length; i++){
    name[i] = new Letter(i, i*letter_width, 30);
  }
}

void draw(){
  background(0);
 
  for(int i=0; i<name.length; i++){
    name[i].move();
    name[i].display();
  }
}

class Letter{
  int i;
  float x, y;
  
  Letter(int ind, int posX, int posY){
    i = ind;
    x = posX;
    y = posY;
  }
  
  void move(){
    float inc_x, inc_y;
    
    if(mousePressed){
         inc_x = (noise(xtime+i)*2-.93) * X_MF;
         inc_y = (noise(ytime+i)*2-.93) * Y_MF;
         
         x = constrain(x+inc_x, 0, width-12);
         y = constrain(y+inc_y, 0+14, height);
         
         xtime += TIME_INC;
         ytime += TIME_INC;
       }
    else {
      for(int j=0; j<name.length; j++){
        name[j] = new Letter(j, j*letter_width, 30);
      }
    }
  }
  
  void display(){
  
    color c;
    
    if(mouseX>5 && mouseX<width-10 && mouseY>10 && mouseY<height-10){
        c = color(random(128,256),random(128,256),random(128,256));
        fill(c);
        text(name_array.charAt(i), x, y);
        }
    else{
        fill(#cc9999);
        text(name_array.charAt(i), x, y);
        }
  }
}
