/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://cst1101.sketchpad.cc/sp/pad/view/ro.ZCaHMFXu0qI/rev.48
*
* authors:
* BARUCH SUAREZ
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
Car [] lot;
void setup() {
lot = new Car[500];
size(400, 300);
for (int m = 0; m < lot.length; m++) {
lot[m] = new Car(color ( m*180), random(0, width), m*2, m/18.2, 20);
}
}
class Car {
color carColor;
float carX;
int carY;
float carSpeed;
int carSize;
Car(color carColor_, float carX_, int carY_, float carSpeed_, int carSize_) {
carColor = carColor_;
carX = carX_;
carY = carY_;
carSpeed = carSpeed_;
carSize = carSize_;
}
void drive() {
carY = carY + 4;
if (carY > width) {
carY = 2;
}
}
void display() {
fill(carColor);
stroke(random (255));
rect(carX, carY, carSize, carSize/2);
}
}
void mousePressed() {
background (random (255));
}
void draw() {
fill (255);
for (int m = 0; m < lot.length; m++) {
lot[m].display();
lot[m].drive();
}
}