Loading...
Logo
Processing Forum

Text random program

in Programming Questions  •  1 month ago  
Hello I would like to do an automaitc program wich write no sense text with all the characters of the
ASCII keyboard that i'm using, i've started, and i have a manual program wich is:

char letter;
String words = "Begin...";

void setup() {
  size(640, 360);
  // Create the font
  textFont(createFont("Georgia", 36));
}

void draw() {
  background(0); // Set background to black

  // Draw the letter to the center of the screen
  textSize(14);
  text("Click on the program, then type to add to the String", 50, 50);
  text("Current key: " + letter, 50, 70);
  text("The String is " + words.length() +  " characters long", 50, 90);
 
  textSize(36);
  text(words, 50, 120, 540, 300);
}

void keyPressed() {
  // The variable "key" always contains the value
  // of the most recent key pressed.
  if ((key >= 'A' && key <= 'z') || key == ' ') {
    letter = key;
    words = words + key;
    // Write the letter to the console
    print(key);
  }
}


I can't write numbers and the rest of symbols.

Do you have any idea to continue with my proyect? I would like also to make it automatic,
i don't need it in the screen i just need some text with no sense made by a program, I thought having
all this text in the print part of processing!

THANK YOU!

Replies(4)

Try out this condition expression to include both letters & numbers & space:

  if (key >= 'A' & key <= 'Z' | key >= 'a' & key <= 'z' | 
    key >= '0' & key <= '9' | key == ' ') {

And a crazy online example:
http://studio.processingtogether.com/sp/pad/export/ro.9tldOdgwNJPID/latest
gREAT!

thank you!, any idea to make it automatic?
i just need a program wich write automatically no sense text, with all the characters.

thank you anyway GoToLoop
What about a random char function?
Copy code
    // http://forum.processing.org/topic/text-random-program
    
    void setup() {
      frameRate(1);
      textSize(0100);
      textAlign(CENTER, CENTER);
    }
    
    void draw() {
      background(0);
      text(randomCharacter(), width>>1, height>>1);
    }
    
    char randomCharacter() {
      char c;
    
      do c = (char) random(' ', 'z'+1);
      while (c<'A'|c>'Z' && c<'a'|c>'z' && c<'0'|c>'9' && c!=' ');
    
      return c;
    }
    
And this 1 keeps adding char by char to a String:
Copy code
    // http://forum.processing.org/topic/text-random-program
    
    String gibberish = "";
    
    void setup() {
      frameRate(1);
    }
    
    void draw() {
      println(gibberish += randomCharacter());
    }
    
    char randomCharacter() {
      char c;
    
      do c = (char) random(' ', 'z'+1);
      while (c<'A'|c>'Z' && c<'a'|c>'z' && c<'0'|c>'9' && c!=' ');
    
      return c;
    }