9-10XIST
Drop
Drop[] drops = new Drop[100] ; //this is an array for making 100 drops to fall to make more increase the number
void setup(){
size(640, 360); //size of the screen
for (int i= 0; i < drops.length; i++) { // creating a loop to add 100 drops into the array
drops[i] = new Drop();
}
}
void draw() {
background(0); //color of the screen
for (int i = 0; i < drops.length; i++) { //creating a loop to draw 100 drops
drops[i].fall();
drops[i].show();
}
}
​
-----------------------------------------------------------------------------------------
​
//declare data types
int num;
int time;
class Drop {
float x = random(width) ; //random location to star on the screen
float y = random(-400,-250); // object starting randomly off the screen
float yspeed = random(4, 10); //random speed of the drop
void fall() { //function to make it fall
y= y + yspeed;
yspeed = yspeed - 0.05; //increase speed while falling
if (y> height) {
y = random (-20, -10); // this will make the drop reset back to the top to star again
yspeed = random(4, 10); //reset speed
}
}
void show() { // function to show or rendered on the screen
text("priority", x, y+10); // here we are creating a text to drop
// fill (191,227,247);
num=round(random(1,10));
println("num = " +num);
time++;
if(time%0.5==0)
{
if (num==1) fill(255,0,0);
if (num==2) fill(0,255,0);
if (num==3) fill(0,0,255);
if (num==4) fill(255,255,0);
if (num==5) fill(255,0,255);
if (num==6) fill(0,255,255);
if (num==7) fill(30,144,255);
if (num==8) fill(0,255,127);
if (num==9) fill(189,183,107);
if (num==10) fill(128,0,128);
}
}
}
Code
Video Demonstration
This exercise actually adds on to the previous exercise, Falling like the Rain. Instead of the lines falling down in a loop, this exercises uses two tabs in Processing to make the lines fall and float right back up. To modify this code, I made the word “priority” fall instead of lines. I chose the word priority because I was testing out possible codes that I could use in the upcoming empathy project. To make this code more interesting, I made the colour of the text random. By using the random() function, I was able to declare 10 different colours that the text could turn into. I struggled with this code as it used two tabs which I have never done before. Through trial and error and managed to make it work. Besides from random(), this exercise also uses the functions int and text() instead of line().
(click the functions underlined to learn more about them)