Text Rain Processing

hello! i am creating random alphabet rain at this moment,
but it seems like continuously same position with same alphabets.
I want it to be all random! is there any solution for this problem?

thanks!

String [] data = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", 
  "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
Drop[] drops = new Drop[7];

void setup() {
  size(640, 640);
  textAlign(CENTER);
  for (int i = 0; i < drops.length; i++) {
    drops[i] = new Drop();
  }
}

void draw() {
  background(250);
  for (int i = 0; i < drops.length; i++) {
    drops[i].fall();
    drops[i].show();
  }
}

class Drop {
  float x;
  float y;
  float len;
  float yspeed;
  String textHolder = "text";

  Drop() {
    x  = random(width);
    y  = random(-300, -50);
    yspeed  = random(1, 5);
    textHolder = data[int(random(data.length))];
  }

  void fall() {
    y = y + yspeed;
    float grav = map(0, 0, 20, 0, 0.2);
    yspeed = yspeed + grav;
    if (y > height) {
      y = random(1, 5);
      yspeed = map(0, 0, 20, 3, 5);
    }
  }

  void show() {
    fill(0);
    textSize(30);
    text(textHolder, x, y, y+len);
  }
}

Textholder= str(int(random(32,165)));

umm this is not working as well

What happens here?

same number with same position continuously

String [] data = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", 
  "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
Drop[] drops = new Drop[8];

void setup() {
  size(640, 640);
  textAlign(CENTER);
  for (int i = 0; i < drops.length; i++) {
    drops[i] = new Drop();
  }
}

void draw() {
  background(250);
  for (int i = 0; i < drops.length; i++) {
    drops[i].fall();
    drops[i].show();
  }
}

class Drop {
  float x;
  float y;
  float len;
  float yspeed;
  String textHolder = "text";

  Drop() {
    x  = random(40,560);
    y  = random(-300, -50);
    yspeed  = random(1, 5);
    textHolder = str(int(random(32,165)));
  }

  void fall() {
    y = y + yspeed;
    float grav = map(0, 0, 20, 0, 0.2);
    yspeed = yspeed + grav;
    if (y > height) {
      y = random(1, 5);
      yspeed = map(0, 0, 20, 3, 5);
    }
  }

  void show() {
    fill(0);
    textSize(30);
    text(textHolder, x, y, y+len);
  }
}

x=random (width);

textHolder = str(int(random(32,165)));

another good solution
for random alphabet, use parseChar() function to get alphabet from ascii code. so you dont need String[] data anymore, line saved!
ascii code for A is 65 and for Z is 90.
random between 65 and 90, will gives you random capital alphabet letters.

//show() function in Drop class change to this 
  void show() {
    fill(0);
    textSize(30);
    char t = parseChar(floor(random(65, 90)));
    text(t, x, y, y+len);
  }

you dont need this anymore

String [] data = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", 
  "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};

line saved!

and for random position, just random x location for each letter when hit bottom

void fall() {
    y = y + yspeed;
    float grav = map(0, 0, 20, 0, 0.2);
    yspeed = yspeed + grav;
    if (y > height) {
      y = random(1, 5);
      yspeed = map(0, 0, 20, 3, 5);
      x = random(width); // add this
    }
  }

Interesting to see parseChar(). Another concept:

char t = char('A' + floor(random(0,25)));

Kf

2 Likes