//a spaceship is trying to get out of a planet's gravity. at first, it //is attached. But, it gets away. however, be patient. the //planet's gravity will pull it back.
JitterBug j1; // Declare
JitterBug j2;
void setup() {
size(400, 400);
smooth();
noStroke();
randomSeed(7);
j1 = new JitterBug();
j2 = new JitterBug();
j1.assignValues(width * 0.45, height/2, 120, j2);
j2.assignValues(width * 0.55, height/2, 50, j1);
}
void draw() {
background(177, 77, 80);
j1.move();
j1.display();
j2.move();
j2.display();
}
class JitterBug {
float x;
float y;
float diameter = 40;
float speed = 10.0;
int direction = 4;
JitterBug other;
JitterBug() {
}
void assignValues(float centerx, float centery, float dia, JitterBug otherBug) {
x = centerx;
y = centery;
diameter = dia;
other = otherBug;
}
void move() {
if (dist(x, y, other.x, other.y) < (diameter/2 + other.diameter/2)) {
speed = 6.0;
}
else {
speed = 2;
}
x = x + random(-speed, speed);
y = y + random(-speed, speed);
}
void display() { //making it like a spaceship
ellipse(x, y, diameter, diameter);
ellipse(x, y, 80, 30);
ellipse(x, y, 110, 10);
}
}Lena - K
on Tuesday, Nov 4, 2008 – 10:42 pm