/* what i decided to do was make bugs that you completely control (minus the color).
so the bugs move around on the axis of sin and cos.
once they meet randomly, the yellow one quickly jumps away from the gray one, while causing an explosion (cause by the speed and radius combined)
*/
JitterBug j1;// Declare
JitterBug j2;
void setup() {
size(400, 400);
noStroke();
smooth();
j1 = new JitterBug();
j2 = new JitterBug();
// angle, speed, radius, sx, sy, circle diameter,
j1.assignValues(10, 0.01, 0.002, 150.0, 1.5, 3.0, 10, j2); //grey
j2.assignValues(10, 0.01, 0.8, 250.0, 3.0, 2.0, 6, j1); // yellow
}
void draw() {
fill(0, 4);
rect(0, 0, width, height);
fill(30, 120, 90);
j1.move();
j1.display();
fill(80, 230, 30);
j2.move();
j2.display();
}
class JitterBug {
float angle;
float speed0;
float speed1;
float speed;
float radius;
float sinval = sin(angle);
float cosval = cos(angle);
float x;
float y;
float sx;
float sy;
float dia;
JitterBug other;
JitterBug() {
}
void assignValues(float anglex, float speedNormal, float speedCollision, float radiusx, float sxx, float syx, float diax, JitterBug otherBug) {
angle = anglex;
speed0 = speedNormal;
speed1 = speedCollision;
speed = speed0;
radius = radiusx;
sx = sxx;
sy = syx;
dia = diax;
other = otherBug;
}
void move() {
angle += speed;
if (dist(x, y, other.x, other.y) < (dia*2 + other.dia*2)) {
speed = speed1;
}
else{
speed = speed0;
}
x = width/2 + cos(angle * sx) * radius / 2;
y = height/2 + sin(angle * sy) * radius / 2;
}
void display() {
if (dist(x, y, other.x, other.y) < (dia*2 + other.dia*2)) {
ellipse(x, y, (random(10)*speed*radius), (random(10)*speed*radius));
}
else{
ellipse(x, y, dia, dia);
}
}
}
Everett - K
on Wednesday, Nov 5, 2008 – 5:18 am