Square s1; //declare the object
Square s2; //declare the second object
float x = 20;
float y = 25;
int tall = 45;
float speedX = 0.2;
float speedY = 1.0;
int directionX = 1;
int directionY = 1;
void setup() {
size (400, 400);
smooth();
noStroke();
s1 = new Square();
s2 = new Square();
s1.Values(20, 0, 60, s1);
s2.Values(300, 210, 20, s2);
}
void draw() {
frameRate(15);
fill (0, 12); //creates trail
rect ( 0,0, width, height);
fill(60, 16, 131, 15);
s1.move();
s1.display();
fill(16, 192, 131);
s2.move();
s2.display();
}
class Square {
float x;
float y;
float diameter = 10;
float speed = 0.1;
Square s2;
Square() {
}
void Values (float originx, float originy, float dia, Square Square2) {
x = originx;
y = originy;
diameter = dia;
s2 =Square2;
}
void move() {
y += speedY * directionY;
if ((y > width-tall) || (y < tall)) {
directionY = -directionY;
}
x = x + random(-10, 10);
y = y + random(-10, 10);
x= constrain(x, 0, width);
y= constrain(y, 0, height);
x += speedX * directionX;
if ((x > width-tall) || (x < tall)) {
directionX = -directionX;
}
if (x > 20) {
fill(131,16,64);
}
if(y < 100){
fill(131, 53,16);
}
}
void display() {
rect(x, y, tall, tall);
}
}
Jessica - K
on Wednesday, Nov 5, 2008 – 4:11 am