# Text Rain Processing

**URL:** <https://discourse.processing.org/t/text-rain-processing/10306>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [April 15, 2019, 5:52pm UTC](https://discourse.processing.org/t/text-rain-processing/10306 "2019-04-15T17:52:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nothingnew](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@nothingnew](https://discourse.processing.org/u/nothingnew)\
**Post date:** [April 15, 2019, 5:52pm UTC](https://discourse.processing.org/t/text-rain-processing/10306/1 "2019-04-15T17:52:45Z")

</div>

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!

```auto
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);
  }
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 15, 2019, 6:32pm UTC](https://discourse.processing.org/t/text-rain-processing/10306/2 "2019-04-15T18:32:43Z")

</div>

> [@nothingnew](#):
>
> textHolder = data[int(random(data.length))];

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

---

<div class="post-metadata">

**Author:** ![nothingnew](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@nothingnew](https://discourse.processing.org/u/nothingnew)\
**Post date:** [April 15, 2019, 8:33pm UTC](https://discourse.processing.org/t/text-rain-processing/10306/3 "2019-04-15T20:33:06Z")

</div>

umm this is not working as well

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 15, 2019, 9:44pm UTC](https://discourse.processing.org/t/text-rain-processing/10306/4 "2019-04-15T21:44:14Z")

</div>

What happens here?

…

---

<div class="post-metadata">

**Author:** ![nothingnew](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@nothingnew](https://discourse.processing.org/u/nothingnew)\
**Post date:** [April 15, 2019, 9:56pm UTC](https://discourse.processing.org/t/text-rain-processing/10306/5 "2019-04-15T21:56:59Z")

</div>

same number with same position continuously

```auto
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);
  }
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 15, 2019, 10:29pm UTC](https://discourse.processing.org/t/text-rain-processing/10306/6 "2019-04-15T22:29:03Z")

</div>

> [@nothingnew](#):
>
> if (y \> height) {

x=random (width);

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

---

<div class="post-metadata">

**Author:** ![humayung](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humayung/32/6089_2.png) [@humayung](https://discourse.processing.org/u/humayung)\
**Post date:** [April 17, 2019, 11:16am UTC](https://discourse.processing.org/t/text-rain-processing/10306/7 "2019-04-17T11:16:07Z")

</div>

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.

```auto
//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

```auto
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

```auto
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
    }
  }

```

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [April 17, 2019, 6:21pm UTC](https://discourse.processing.org/t/text-rain-processing/10306/8 "2019-04-17T18:21:35Z")

</div>

> [@humayung](#):
>
> char t = parseChar(floor(random(65, 90)));

Interesting to see `parseChar()`. Another concept:

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

Kf
