//competitive plotter attractor net //by Steed neuron [] n = new neuron [256]; plot one; body [] p = new body[100]; int d = 0; BImage output; float E = 2.71828182845904523536; void setup(){ size (640,320); background(255); output = loadImage("output.gif"); for (int i=0; i -1){ if (c == d-1){ p[c] = null; d--; println(d); } else { p[c] = p[d-1]; p[d-1] = null; d--; println(d); } } else if (d < 100){ p[d] = new body(mouseX,mouseY); d++; println(d); } } void net2image (){ for (int i =0; i < n.length; i++){ output.pixels[i] = color (n[i].b*300,0,0); } push(); scale(20); image(output,0,0); pop(); } class neuron{ float w,a,b,d; neuron (){ this.a = 1.0; this.w = 0.0; this.d = 1.0; } void fire(){ d = (d+0.05)%6.0; w = normalD (d, 1.0, 3.0); b = a * w; } }//class; void loadn(){ int [] dm = new int[d]; for(int i = 0; i < d; i++){ dm[i] = 0; } for (int i1 = 0; i1 < 16; i1++){ for (int i2 = 0; i2 < 16; i2++){ for (int i3 = 0; i3 < d; i3++){ if (overRect(p[i3].x,p[i3].y,i1*20,i2*20,(i1+1)*20,(i2+1)*20)){ n[i1+(i2*16)].fire(); dm[i3] = i1+(i2*16); } } } } float x2 = 0.0; float y2 = 0.0; float [] c = new float [d]; for (int i = 0; i < d; i++){ c[i] = n[dm[i]].b; } sort(c); for (int i = 0; i < d; i++){ if (c[c.length-1] == n[dm[i]].b){ x2 = p[i].x+320; y2 = p[i].y; } } if (d > 0){ one.move(0.5,x2,y2); } for (int i = 0; i < d; i++){ p[i].move(); } } class body{ float x,y,th; body(float x, float y){ this.x = x; this.y = y; this.th = 0.0; } void move(){ th += random (1.0)-0.5; float m = 1.0; x = fwrap(x + cos(th) * m,315); y = fwrap(y + sin(th) * m,315); stroke(200); fill(100); ellipse(x-7,y-7,14,14); stroke(50); fill(70); ellipse(x-2,y-2,4,4); } } class plot{ float x,y,th; plot(float x, float y){ this.x = x; this.y = y; } void move(float speed,float x2,float y2){ float t = atan2 (y2-y,x2-x); if (t > th){ th += PI/8; } if (t < th){ th -= PI/8; } float m = speed; x += cos(th) * m; y += sin(th) * m; stroke(93,93,76); point(x,y); } } float [] netOut (){ float [] r = new float [n.length]; for (int i = 0; i < n.length; i++){ r[i] = n[i].b; } return r; } float normalD (float xx, float sigma, float mu){ return pow(E,-(sq((xx-mu))) / (2 * sq(sigma))) / (sigma*sqrt(TWO_PI)); }//where sigma is the scale of the graph & mu shifts the location of the graph along x boolean overRect(float xo, float yo, float x1, float y1, float x2, float y2){ if (xo >= x1 && xo <= x2 && yo >= y1 && yo <= y2) { return true; } else { return false; } } float fwrap (float fvalu, float flimi){ float fcar=fvalu; if (fcar>flimi){ fcar=(fcar)%flimi; } if (fcar<0){ fcar=flimi-fcar; fcar=(fcar)%flimi; fcar=flimi-fcar; } return fcar; }//fwrap;