///////////////////////////////////////////////// /* delayed magnets 2005 andreas gysin www.ertdfgcvb.ch */ ///////////////////////////////////////////////// magnet[] magnets; float molti = 0.0; //int cMode = 0; ///////////////////////////////////////////////// void setup(){ //params int bordo = 24; float hgrid = 12; float vgrid = hgrid*sqrt(0.75); int hlines = 40; int vlines = 46; int maxlen = 10;//int(vgrid-2); magnets = new magnet[vlines * hlines]; //screen setup int w = int(hgrid*(hlines-1)) + bordo*2; int h = int(vgrid*(vlines-1)) + bordo*2; println (h + " " + w); //size(w, h); size(515 , 516); framerate(30); //obj array int c = 0; for (int j=0; j 4){ cMode = 0; } } } */ ///////////////////////////////////////////////// class magnet { int l; float x1, y1; float x2, y2; float m2 = 0.0; float damp = 0.06; float mdamp = 0.02; ////////// magnet(int qx, int qy, int ql) { x1 = qx; y1 = qy; x2 = x1; y2 = y1; l = ql; } ////////// void step() { //x1 += random(-1, 1); //y1 += random(-1, 1); float x3 = mouseX - x1;//x1 - mouseX); float y3 = mouseY - y1;//y1 - mouseY; float m = sqrt(x3 * x3 + y3 * y3); if (m > l) { x3 = x1 + x3/m * l; y3 = y1 + y3/m * l; } else if (m < l){ x3 = x1 + x3; y3 = y1 + y3; } else { x3 = x1; y3 = y1; } x2 += (x3 - x2) * damp; y2 += (y3 - y2) * damp; m2 += (m - m2) * mdamp; strokeWeight(sin(m2 * molti) * 3.0); /* if (cMode == 0) {stroke(0, 0, 0); } else if (cMode == 1) {stroke(255, 0, 0); } else if (cMode == 2) {stroke(160-m2, m2*0.6, m2*1.1); } else if (cMode == 3) {stroke(m2, 255-m2, m2*1.8); } else if (cMode == 4) {stroke(190, 100-m2, 255-m2); } */ line(x1, y1, x2, y2); } }