int kp=0; int mp=0; int cross=0; float SEED; float MyNoise(Vertex a, Vertex b) { double x=Math.pow(Math.pow(Math.sin(a.x+0.234241)*(b.y+0.13112*(b.x-121.28456))*atan2((float)a.z,(float)b.y+45.12313214551)+Math.cos(b.x-(a.y*b.z+152.4712313))*((a.y+123.34234)*(b.x-1.21424))*Math.cos(b.z-1.734234)+0.4234123123,2),0.25); // x=Math.pow(x*b.z*a.y*(a.x-b.z)*0.2342412341,0.12); x+=0.7324*SEED; // x=x-(int)x; x=cos((float)x); // print(x); // print(" - "); // return (float)x-0.5; return (float)x; } class Vertex { Vertex(double _x, double _y, double _z) { x=_x; y=_y; z=_z; } double X() { return x; } double Y() { return y; } double Z() { return z; } double x,y,z; } class Triangle { boolean isParent=false; float Scaling; Vertex[] Verticies=new Vertex[3]; Triangle[] Child; Triangle(Vertex a, Vertex b, Vertex c,float scalefactor) { Verticies[0]=a; Verticies[1]=b; Verticies[2]=c; Scaling=scalefactor; } void Draw() { if(!isParent) { beginShape(TRIANGLES); { // stroke(255,0,0); noStroke(); double R=Math.sqrt(Verticies[0].x*Verticies[0].x+Verticies[0].y*Verticies[0].y+Verticies[0].z*Verticies[0].z); // R=R/3.0; R=R-100.0; int c=(int)(R*32); if(R<0.0) fill(color(0,0,255+c)); else { fill(color((2*c)-256,c+64,(2*c)-256)); } // fill(color(255,255,255)); vertex((float)Verticies[0].x,(float)Verticies[0].y,(float)Verticies[0].z); R=Math.sqrt(Verticies[1].x*Verticies[1].x+Verticies[1].y*Verticies[1].y+Verticies[1].z*Verticies[1].z); R=R-100.0; c=(int)(R*32); if(R<0.0) fill(color(0,0,255+c)); else { fill(color((2*c)-256,c+64,(2*c)-256)); } vertex((float)Verticies[1].x,(float)Verticies[1].y,(float)Verticies[1].z); R=Math.sqrt(Verticies[2].x*Verticies[2].x+Verticies[2].y*Verticies[2].y+Verticies[2].z*Verticies[2].z); R=R-100.0; c=(int)(R*32); if(R<0.0) fill(color(0,0,255+c)); else { fill(color((2*c)-256,c+64,(2*c)-256)); } vertex((float)Verticies[2].x,(float)Verticies[2].y,(float)Verticies[2].z); } endShape(); } else { Child[0].Draw(); Child[1].Draw(); Child[2].Draw(); Child[3].Draw(); } } int Divide(int x) { if(isParent==false) { isParent=true; Child=new Triangle[4]; double R=Math.sqrt(Math.pow(Verticies[0].x,2.0)+Math.pow(Verticies[0].y,2.0)+Math.pow(Verticies[0].z,2.0)); R+=Math.sqrt(Math.pow(Verticies[1].x,2)+Math.pow(Verticies[1].y,2)+Math.pow(Verticies[1].z,2)); R=R/2.0; //R is average of two parents. // println(R); // float xp=(float)(sin((float)(Verticies[0].x*Verticies[1].x))*cos((float)(Verticies[0].y*Verticies[1].y))*cos((float)(Verticies[0].z*Verticies[1].z))); // float xp=(float)(Math.sin(Verticies[0].x-Verticies[1].y)*Math.cos(Verticies[1].z-Verticies[0].x)); float xp=MyNoise(Verticies[0],Verticies[1]); R=R+Scaling*xp; Vertex abmid=new Vertex((Verticies[0].x+Verticies[1].x)/2.0,(Verticies[0].y+Verticies[1].y)/2.0,(Verticies[0].z+Verticies[1].z)/2.0); double Q=Math.sqrt(Math.pow(abmid.x,2)+Math.pow(abmid.y,2)+Math.pow(abmid.z,2)); double S=(R/Q); abmid.x=abmid.x*S; abmid.y=abmid.y*S; abmid.z=abmid.z*S; R=Math.sqrt(Math.pow(Verticies[0].x,2)+Math.pow(Verticies[0].y,2)+Math.pow(Verticies[0].z,2)); R+=Math.sqrt(Math.pow(Verticies[2].x,2)+Math.pow(Verticies[2].y,2)+Math.pow(Verticies[2].z,2)); R=R/2.0; //R is average of two parents. // xp=(float)(sin((float)(Verticies[0].x*Verticies[2].x))*cos((float)(Verticies[0].y*Verticies[2].y))*cos((float)(Verticies[0].z*Verticies[2].z))); // xp=(float)(Math.sin(Verticies[0].x-Verticies[2].y)*Math.cos(Verticies[2].z-Verticies[0].x)); xp=MyNoise(Verticies[0],Verticies[2]); R=R+Scaling*xp; Vertex acmid=new Vertex((Verticies[0].x+Verticies[2].x)/2.0,(Verticies[0].y+Verticies[2].y)/2.0,(Verticies[0].z+Verticies[2].z)/2.0); Q=Math.sqrt(Math.pow(acmid.x,2)+Math.pow(acmid.y,2)+Math.pow(acmid.z,2)); S=(R/Q); acmid.x=acmid.x*(S); acmid.y=acmid.y*(S); acmid.z=acmid.z*(S); R=Math.sqrt(Math.pow(Verticies[2].x,2)+Math.pow(Verticies[2].y,2)+Math.pow(Verticies[2].z,2)); R+=Math.sqrt(Math.pow(Verticies[1].x,2)+Math.pow(Verticies[1].y,2)+Math.pow(Verticies[1].z,2)); R=R/2.0; //R is average of two parents. // xp=(float)(sin((float)(Verticies[2].x*Verticies[1].x))*cos((float)(Verticies[2].y*Verticies[1].y))*cos((float)(Verticies[2].z*Verticies[1].z))); // xp=(float)(Math.sin(Verticies[2].x-Verticies[1].y)*Math.cos(Verticies[1].z-Verticies[2].x)); xp=MyNoise(Verticies[2],Verticies[1]); R=R+Scaling*xp; Vertex bcmid=new Vertex((Verticies[2].x+Verticies[1].x)/2.0,(Verticies[2].y+Verticies[1].y)/2.0,(Verticies[2].z+Verticies[1].z)/2.0); Q=Math.sqrt(Math.pow(bcmid.x,2)+Math.pow(bcmid.y,2)+Math.pow(bcmid.z,2)); S=(R/Q); // S=S*1.05; bcmid.x=bcmid.x*(S); bcmid.y=bcmid.y*(S); bcmid.z=bcmid.z*(S); Child[0]=new Triangle(Verticies[0],acmid,abmid,Scaling/1.8); Child[1]=new Triangle(bcmid,acmid,abmid,Scaling/1.8); Child[2]=new Triangle(bcmid,Verticies[1],abmid,Scaling/1.8); Child[3]=new Triangle(bcmid,acmid,Verticies[2],Scaling/1.8); return x+4; } else { for(int i=0;i<4;i++) { x=Child[i].Divide(x); } return x; } } } Triangle[] Foo=new Triangle[8]; int NumTris=8; int foo=8; void setup() { size(500,300); SEED=random(100); // Foo=new Triangle[8]; float base=10.0; Foo[0]=new Triangle(new Vertex(0,-100,0),new Vertex(0,0,100),new Vertex(-100,0,0),base); Foo[1]=new Triangle(new Vertex(0,-100,0),new Vertex(0,0,-100),new Vertex(-100,0,0),base); Foo[2]=new Triangle(new Vertex(0,-100,0),new Vertex(0,0,-100),new Vertex(100,0,0),base); Foo[3]=new Triangle(new Vertex(0,-100,0),new Vertex(0,0,100),new Vertex(100,0,0),base); Foo[4]=new Triangle(new Vertex(0,100,0),new Vertex(0,0,100),new Vertex(-100,0,0),base); Foo[5]=new Triangle(new Vertex(0,100,0),new Vertex(0,0,-100),new Vertex(-100,0,0),base); Foo[6]=new Triangle(new Vertex(0,100,0),new Vertex(0,0,-100),new Vertex(100,0,0),base); Foo[7]=new Triangle(new Vertex(0,100,0),new Vertex(0,0,100),new Vertex(100,0,0),base); /* for(int i=0;i0) { /* for(int i=0;i