int cant = 2000; boolean go = true; int t = 0; float wave; Attractor[] attractors; Attractor dragged = null; Dot[] dots; PFont font; void setup() { size(800, 600, P3D); colorMode(HSB, 255); background(0); frameRate(24); stroke(255, 100); fill(255); ellipseMode(CENTER); font = loadFont("Verdana-11.vlw"); textMode(SCREEN); textFont(font); makeAttractors(); makeDots(); } void makeAttractors() { int n = 8; int types = 14; attractors = new Attractor[n]; for(int i=0; i 0){ for(int j=0; j width) ax = x = 0; if (y < 1) ay = y = height; if (y > height-1) ay = y = 0; } } class Attractor { int type; float rad; float x, y; int col; Attractor(int type, float rad, int col) { this.type = type; this.rad = rad; this.col = col; this.x = random(width); this.y = random(height); } float[] act(float _x, float _y, float _vx, float _vy) { float[] forces = new float[3]; float dxy = dist(x, y, _x, _y); if(dxy < rad){ float rx, ry; float dx = x - _x; float dy = y - _y; float ang = atan2(dy, dx); float ratio = 1 - easeOut(dxy/rad, 1); switch(type) { case 0: default: rx = _x < x ? -2 : 2; ry = _y < y ? -2 : 2; break; case 1: rx = (width/2 - _x)/100; ry = (height/2 - _y)/100; break; case 2: float radium = dxy - random(40, 60); rx = radium/10 * sin(ang+HALF_PI); ry = -radium/10 * cos(ang+HALF_PI); break; case 3: rx = (wave*6-3) * sin(ang+HALF_PI); ry = -(wave*6-3) * cos(ang+HALF_PI); break; case 4: rx = -dx/50; ry = -dy/50; break; case 5: rx = random(-8, 8); ry = random(-8, 8); break; case 6: rx = 5 * sin(TWO_PI * wave); ry = -5 * cos(TWO_PI * wave); break; case 7: float _ang = atan2(_vy, _vx); rx = 3 * sin(_ang + PI*wave); ry = -3 * cos(_ang + PI*wave); break; case 8: rx = 5 * sin(ang); ry = -5 * cos(ang); break; case 9: rx = -5 * sin(ang + PI/12); ry = 5 * cos(ang + PI/12); break; case 10: rx = 5 * sin(ang - PI/12); ry = -5 * cos(ang - PI/16); break; case 11: rx = 5 * cos(ang); ry = -5 * sin(ang); break; case 12: rx = _vx * 2; ry = _vy * 2; break; case 13: rx = dy/20; ry = dx/20; break; } forces[0] = rx * ratio; forces[1] = ry * ratio; forces[2] = ratio; } return forces; } int getCol(){ return col; } void paso() { float d = dist(mouseX, mouseY, x, y); if(d < rad && abs(mouseX-pmouseX) > 0) { noFill(); stroke(255, 50); ellipse(x, y, rad*2, rad*2); noStroke(); fill(col, 200, 255, 50); ellipse(x, y, 16, 16); //fill(0); //text(type, x-2, y+4); if(dragged == this){ x = mouseX; y = mouseY; } } } void pressed() { if(dist(mouseX, mouseY, x, y) < 8) dragged = this; } } float easeIn (float t, float c) { return c*(t/=1)*t; } float easeOut (float t, float c) { return -c *(t/=1)*(t-2); }