//pattern 3 float p=PI; //ratio by which random distances are determined float xtf; //carrier for flipper float ytf; //carrier for flipper float o; //for calculating tan-1 float ao; //trig at xya float bo; //trig at xyb float a; //for calculating tan-1 float aa; //trig at xya float ba; //trig at xyb float theta; //for trigonometry float aTheta; //anchor angle at xya float bTheta; //anchor angle at xyb float L; //for trigonometry (hypotenuse) float aL; //xya to xyc float bL; //xyb to xyd float nL; //random new hypotenuse int choice; //random choice int q; //random child index float xta; //carrier variable float yta; //carrier variable float xtb; //carrier variable float ytb; //carrier variable float xtc; //carrier variable float ytc; //carrier variable float xtd; //carrier variable float ytd; //carrier variable // child co-ord table float [] xva=new float[2000]; //float [] xva=new float[3]; float [] yva=new float[xva.length]; float [] xvb=new float[xva.length]; float [] yvb=new float[xva.length]; float [] xvc=new float[xva.length]; float [] yvc=new float[xva.length]; float [] xvd=new float[xva.length]; float [] yvd=new float[xva.length]; int [] flag=new int[xva.length]; //line or curve (0 or 1) int mUnit=10; int mWidth=50; int mHeight=50; int mLimit=5; int [][] matrix=new int[mWidth][mHeight]; //density matrix boolean verify=true; void setup (){ size (500,500); background (255); ellipseMode(CENTER_DIAMETER); //smooth(); xva[0]=200; yva[0]=300; xvb[0]=300; yvb[0]=200; xvc[0]=200; yvc[0]=200; xvd[0]=300; yvd[0]=300; flag[0]=1; //xvc[0]=200; //yvc[0]=200; //xvd[0]=300; //yvd[0]=100; } void loop () { //wipe matrix for(int j=0; jmLimit) || (matrix[int(xtb/mUnit)][int(ytb/mUnit)]>mLimit)){ if (int(random(2))==1) { //line or curve flag[i]=0; }else{ flag[i]=1; } q=int(random(i)); //carriers copy existing random line xta=xva[q]; yta=yva[q]; xtb=xvb[q]; ytb=yvb[q]; //set curve control to zero then establish if necessary xtc=xta; ytc=yta; xtd=xtb; ytd=ytb; if ((flag[i]==1) && (flag[q]==1)) { //if parent is curve, copy xtc=xvc[q]; ytc=yvc[q]; xtd=xvd[q]; ytd=yvd[q]; } if ((flag[i]==1) && (flag[q]==0)) { //if parent is line, random anchors if (int (random(2))==1){ trig(); //float dL=((L/p)/p)+random(L/p); float dTheta=random(TWO_PI); xtc+=(cos(dTheta)*random(L)); ytc+=(sin(dTheta)*random(L)); }else{ trig(); //float dL=((L/p)/p)+random(L/p); float dTheta=random(TWO_PI); xtd+=(cos(dTheta)*random(L)); ytd+=(sin(dTheta)*random(L)); //xtd+=xtb+(cos(random(TWO_PI))*L); //ytd+=ytb+(sin(random(TWO_PI))*L); } } //flipper if (int(random(2))==1) { xtf=xta; xta=xtb; xtb=xtf; ytf=yta; yta=ytb; ytb=ytf; xtf=xtc; xtc=xtd; xtd=xtf; ytf=ytc; ytc=ytd; ytd=ytf; } // Trig a=(xtb-xta); aa=(xtc-xta); ba=(xtd-xtb); o=(ytb-yta); ao=(ytc-yta); bo=(ytd-ytb); theta=atan2(o,a); aTheta=atan2(ao,aa); bTheta=atan2(bo,ba); L=sqrt(sq(abs(a))+sq(abs(o))); aL=sqrt(sq(abs(aa))+sq(abs(ao))); bL=sqrt(sq(abs(ba))+sq(abs(bo))); nL=(L-(L/p))+random((L/p)*2); //nL=(L-(L/p))+random(L/p); // Type of mutation choice=int(random(3)); if (choice==0){ displacer(); parallel(); } if (choice==1){ perpendicular (); } if (choice==2){ displacer(); rotation (); } xta=constrain(xta,0,width-1); xtb=constrain(xtb,0,width-1); yta=constrain(yta,0,height-1); ytb=constrain(yta,0,height-1); } //values taken from carriers xva[i]=xta; xvb[i]=xtb; xvc[i]=xtc; xvd[i]=xtd; yva[i]=yta; yvb[i]=ytb; yvc[i]=ytc; yvd[i]=ytd; //update density matrix matrix[int(xta/mUnit)][int(yta/mUnit)]++; matrix[int(xtb/mUnit)][int(ytb/mUnit)]++; } // draw children for (int i=0; iTWO_PI){ theta-=TWO_PI; } if (bTheta>TWO_PI){ bTheta-=TWO_PI; } xtb=xta+(cos(theta)*nL); xtd=xtb+(cos(bTheta)*bL); ytb=yta+(sin(theta)*nL); ytd=ytb+(sin(bTheta)*bL); } void rotation() { float nTheta=(theta-(TWO_PI/p))+(random((TWO_PI/p)*2)); if (theta<0){ theta+=TWO_PI; } else if (theta>TWO_PI){ theta-=TWO_PI; } aTheta+=(nTheta-theta); bTheta+=(nTheta-theta); if (aTheta<0){ aTheta+=TWO_PI; } else if (aTheta>TWO_PI){ aTheta-=TWO_PI; } if (bTheta<0){ bTheta+=TWO_PI; } else if (bTheta>TWO_PI){ bTheta-=TWO_PI; } xtc=(xta+(cos(aTheta)*aL)); ytc=(yta+(sin(aTheta)*aL)); xtb=(xta+(cos(nTheta)*nL)); ytb=(yta+(sin(nTheta)*nL)); xtd=(xtb+(cos(bTheta)*bL)); ytd=(ytb+(sin(bTheta)*bL)); } //Button boolean overRect(int x, int y, int width, int height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } } void trig(){ a=(xtb-xta); o=(ytb-yta); theta=atan2(a,o); L=sqrt(sq(abs(a))+sq(abs(o))); nL=(L-(L/p))+random((L/p)*2); } float mx = constrain(mouseX, 30, 70);