/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://cst1101.sketchpad.cc/sp/pad/view/ro.SpVpq1Wi7hR/rev.15
*
* authors:
* Joe Perrino
* Corey Ausby
* Don Miller
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
Car myCar; // object data type
Car myCar2;
Car [] lot; // array called lot of "Car"s
void setup() {
lot = new Car[400]; // makes space for 100 Cars
size(400, 400);
for (int i = 0; i < lot.length; i++) {
lot[i] = new Car(color(i*2), random(0,width), i*2, i/20.0, 20);
}
}
void draw() {
background(0);
fill(255);
for (int i = 0; i < lot.length; i++) {
lot[i].display();
lot[i].drive();
}
}
//------------------------- CAR CLASS ----------------------------
class Car {
color carColor; // data
float carX;
int carY;
float carSpeed;
int carSize;
Car(color carColor_, float carX_, int carY_, float carSpeed_, int carSize_) { // constructor
carColor = carColor_;
carX = carX_;
carY = carY_;
carSpeed = carSpeed_;
carSize = carSize_;
}
void drive() { // methods
carX = carX + carSpeed;
if (carX > width) {
carX = 0;
}
}
void display() { // methods
fill(carColor);
stroke(255);
rect(carX, carY, carSize, carSize/2);
}
}