int screenX = 500; int screenY = 500; int mousePressX = 0; int mousePressY = 0; Runner her; Runner him; HashSet bangs = new HashSet(); class Bang { float x,y; int step = 0; int endstep = 100; int flares = 40; int r,g,b; Bang(float x, float y) { step = 1; this.x = x; this.y = y; r = int(random(200,255)); g = int(random(200,255)); b = 100; } void goBang() { if (step>0) { float d = step; float phase = 1 - (1.0*step/endstep); int a = floor(255.0*phase); //fill(r,g,b,20); //noStroke(); //ellipse(x,y,d*2,d*2); for (int i=0; iendstep) step = 0; } } } class Runner { float x0, y0, x1, y1, x2, y2, x3, y3; int r,g,b; float xStep = 0.1; float yStep = 0.1; int yDirection = 1; Runner other = null; float masa = 1.0; // tiene que ser 1, sino no es muy estable y no bailan nada Runner (float x, float y) { this.x0 = this.x1 = this.x2 = this.x3 = x; this.y0 = this.y1 = this.y2 = this.y3 = y; r = int(random(150,255)); g = int(random(0,25)); b = int(random(0,25)); } void setOther(Runner r) { other = r; } void setStep(float x, float y) { this.xStep = x; this.yStep = y; } void setColor(int r, int g, int b) { this.r=r; this.g=g; this.b=b; } void goRun() { x0 = x1; x1 = x2; x2 = x3; y0 = y1; y1 = y2; y2 = y3; // normalmente random // float distancia = dist(x3,y3,other.x3,other.y3); boolean seArriman = (distancia < dist(x2,y2,other.x2,other.y2)); boolean cerca = (distancia < screenX/3); boolean seTocan = (distancia < 4); boolean muyLejos = (dist(x3,y3,0,0) > screenX); boolean muyCerca = (dist(x3,y3,0,0) < screenX/5); float randomMult = 10; if (muyLejos) { // traer para el centro x3 = x3 * 0.95; y3 = y3 * 0.95; } else if (seTocan) { x3 = x3 + random(-screenX/2,screenX/2); y3 = y3 + random(-screenY/2,screenY/2); } else if (cerca) { // arrimarse mas x3 = x3 + xStep * (other.x3-x3) + masa*(x2-x1); y3 = y3 + yStep * (other.y3-y3) + masa*(y2-y1); x3 = x3 * 0.94; y3 = y3 * 0.94; randomMult = 2; } else { randomMult = 30; } // masa y random x3 = x3 + randomMult * (random(-1,1)); y3 = y3 + randomMult * (random(-1,1)); // siempre se tira hacia el centro if (muyCerca) { x3 = x3*random(1.03,1.05); y3 = y3*random(1.03,1.05); } else { x3 = x3*0.99; y3 = y3*0.99; } // coordenadas de pantalla float sx0 = x0+screenX/2; float sy0 = y0+screenY/2; float sx1 = x1+screenX/2; float sy1 = y1+screenY/2; float sx2 = x2+screenX/2; float sy2 = y2+screenY/2; float sx3 = x3+screenX/2; float sy3 = y3+screenY/2; // las curvas stroke(r,g,b); curve (sx0, sy0, sx1, sy1, sx2, sy2, sx3, sy3); stroke(r,g-2,b+5); curve (sx0+1, sy0+1, sx1+1, sy1+1, sx2+1, sy2+1, sx3+1, sy3+1); if (!cerca) { stroke(r,g,b-3); curve (sx0+2, sy0+2, sx1-4, sy1-2, sx2-1, sy2+5, sx3+2, sy3+2); curve (sx0+2, sy0+2, sx1-8, sy1-4, sx2+1, sy2-5, sx3+2, sy3+2); curve (sx0+2, sy0+2, sx1+3, sy1+5, sx2-1, sy2+3, sx3+2, sy3+2); } if (cerca) { //fill(r,g,b,30); //ellipse(sx3,sy3, distancia/10, distancia/10); } if (seTocan) { fill(255,60); noStroke(); rect(0,0,screenX, screenY); //fill(255,255,255,150); //ellipse(sx2,sy2, random(30,40), random(30,40)); bangs.add(new Bang(sx2,sy2)); } } } //------------------------------------ void setup() { him = new Runner(-screenX/3, 0); her = new Runner(screenX/3, 0); him.setOther(her); her.setOther(him); him.setColor(60,60,255); her.setColor(255,0,0); size(screenX,screenY); framerate(15); background(0); smooth(); } void draw() { fill(0,10); noStroke(); rect(0,0,screenX, screenY); her.goRun(); him.goRun(); Iterator it = bangs.iterator(); HashSet toRemove = new HashSet(); while (it.hasNext()) { Bang b = (Bang)it.next(); if (b.step == 0) { toRemove.add(b); } else { b.goBang(); } } it = toRemove.iterator(); while (it.hasNext()) { bangs.remove(it.next()); } }