Car Example

You can download the sketch here: http://aaron-sherwood.com/carExample.zip

Car sportsCar;
Car miniVan;

void setup(){
size(640, 480);
rectMode(CENTER);
sportsCar = new Car(255,0,0,100,15,15);
miniVan = new Car(150,50,200,150,112,2);
}

void draw(){
background(255);
sportsCar.display();
sportsCar.move(0);
miniVan.display();
miniVan.move(2);
}

class Car{
int speed;
int w;
int h;
int red, green, blue;
float x, y;
float angle;
int radius=200;

Car(int r, int g, int b, int W, int H, int s){
speed=s;
w=W;
h=H;
red=r;
green=g;
blue=b;
x = 0;
y = random(height);
angle=0;
radius=200;
}

void move(int mode){
x+=speed;
if (mode==0){
if(x>width || x<0){ speed*=-1; } } if (mode==1) { if (x>width){
x=0;
}
}

if (mode==2) {
x = width/2 + radius * cos(angle);
y = height/2 + radius * sin(angle);
angle+=.01;
}
}

void display(){
fill(red,green,blue);
rect(x, y, w, h);
}

}