xxxxxxxxxx
//of the class Square, call an instance called mySquares, and initiate an array of 100 instances
Square[] mySquares = new Square[100];
Line[] myLines = new Line[100];
void setup () {
size(1420, 850);
background (0);
//populate the array by calling each square in the list, starting with zero as the first in the qeue, and adding one until we get to the end of the list
// integer i represents the square's placeholder in the qeue, HINT: a NullPointer warning usually means a problem with length of array
//"as long as we have not reached the end of the list, generate a new ***Square*** with the following variables:"
for (int i= 0; i<100; i++) {
//variables reference the setup in the class, no longer rect variable convention
// "(float tempX,float tempY, float tempSpeed, float tempG)"
// built-in random convention gives limits to randomness as (* , *)
mySquares[i] = new Square (random(0, 1420), -10, random(1, 50), 0.1);
}
//"as long as we have not reached the end of the list, generate a new ***Line*** with the following variables:"
for (int i= 0; i<100; i++) {
//variables reference the setup in the class, no longer line convention
myLines[i] = new Line (0, 255, 255, 255);
}
}
void draw() {
//target all of the "new Lines" created within the length of the array, initiate the display function
for (int i=0; i < myLines.length; i++) {
myLines[i].display();
println(myLines[i].y);
}
//this way of updating background redraws with transparency as second argument so we can see a hint of the trails
fill(0, 80);
rect(0, 0, width, height);
//target all of the "new Squares" created within the length of the array list, initiate the display and fall functions on each of the instances
for (int i=0; i < mySquares.length; i++) {
mySquares[i].display();
mySquares[i].fall();
println(mySquares[i].y);
}
for (int i=0; i < mySquares.length; i++) {
if (mySquares[i].y >= myLines[i].y) {
myLines[i].changeColor(0.0, random(255.0), random(255.0), random(255.0));
}
}
//if the y position of Line falls anywhere within the height of a square, randomize the rgb values
// if ( myLines[].y == mySquares[].y + 2.5 || myLines[].y == mySquares[].y - 2.5 ) {
// Line.changeColor(random(0, 255), random(0, 255), random(0, 255));
// }
}
class Line {
float y;
float r;
float g;
float b;
// r color , g color, b color
Line ( float tempY, float tempR, float tempG, float tempB) {
r = tempR;
g = tempG;
b = tempB;
y = tempY;
}
void display() {
for (int y=0; y<=height; y+=10) {
line (0, y, width, y);
stroke (255, 255, 255);
}
}
void changeColor(float tempY, float tempR, float tempG, float tempB) {
stroke (y, r, g, b);
r = tempR;
g = tempG;
b = tempB;
y = tempY;
}
}
class Square {
float x;
float y;
float speed;
float gravity;
// tamp x position, temp y position, temp Speed, Temp Gravity
Square(float tempX,float tempY, float tempSpeed, float tempG){
x = tempX;
y = tempY;
speed = tempSpeed;
gravity = tempG;
}
void display(){
rect (x, y, 5, 5);
fill(255);
noStroke();
}
void fall(){
//why this?
y = y + speed;
speed = speed + gravity;
}
}