// orbiting creatures // wander till someone appears. int screenX = 600; int screenY = 600; int howMany = 30; float Gx = 1.5; float Gy = 1.5; HashSet bichos = new HashSet(); void setup() { for (int i=0; i0?1:-1); fillColor = color(random(100,255),random(100,255),(m*100)%255); } void step() { // no target, apunto al diome. if (target == null) { target = new Target(0,0); } float dt = millis() - lastTime; lastTime = millis(); float d = dist(x,y,target.x,target.y); float dx = target.x - x; float dy = target.y - y; // calculo pero no la tiro al caraj. if (d > 40) { ax = (dx/d) * Gx * target.m / (d*d); ay = (dy/d) * Gy * target.m / (d*d); vx = vx + ax * dt; vy = vy + ay * dt; } else { // si estan muy cerca, los empujo un poco vx = vx * 1.01; vy = vy * 1.01; } x = x + vx*dt; y = y + vy*dt; // los roto un poquito float r = clockwise * (-HALF_PI)/53; x = ( x*cos(r) - y*sin(r) ); y = ( x*sin(r) + y*cos(r) ); // siempre tiro un poco hacia el centro x = x * 0.99; y = y * 0.99; } void draw() { // screen coords float sx = x + screenX/2; float sy = y + screenY/2; float tsx = target.x + screenX/2; float tsy = target.y + screenY/2; noStroke(); fill(fillColor); ellipse(sx,sy,diameter,diameter); // the Target stroke(200); noFill(); ellipse(tsx,tsy,40,40); } } // ------------------------------------ // --- class Target ------------------- class Target { float x = 0; float y = 0; float m = 1; Target(float posX, float posY) { this.x = posX; this.y = posY; } }