FSOSS 2010/processing.js/randomText

From CDOT Wiki
Jump to: navigation, search
/*
  FSOSS 2010
  Andor Salga
  Example of random and text
*/
PFont font;
float textY, textX;
String textString = new String();

// color does not use 'new'
color col = color(80, 90, 100);

void setup(){
  size(250, 250);
  font = createFont("verdana", 30);
  textFont(font);
}

void draw(){
  background(0);

  // move text up
  textY -= 0.5;

  // text uses fill, not stroke colors
  fill(col);
  text(textString, textX, textY);
}


void mousePressed(){
  textX = mouseX;
  textY = mouseY;
 
  // Create a random number from 0 to 10
  // not including 10
  float rand = random(0, 10);
 
  // Convert the float to a String
  textString = new String("" + rand);
}

Run me