// TWIGS3D / Feelers '07.11 // by Tsutomu HIGO URL:http://www.asahi-net.or.jp/~nj2t-hg/ #version 3.6; global_settings { max_trace_level 5 assumed_gamma 2.2 } light_source {<2000, 10000, -5000> color <1, 1, 1>} light_source {<-60000, -30000, -40000> color <0, 0, 0>} camera { location <-30, -100, -100> angle 4.8 look_at <0.2, 0.1, 0> } #declare Rndm = seed(29); #declare R1 = seed(5); #declare Rdg = 5; //radius of arranging sphere #macro Dla31 (Nmax, Rds) #declare Cp = array[Nmax][6] #declare Cp[0][0] = 0; // x of sphere's center #declare Cp[0][1] = 0; // z of sphere's center #declare Cp[0][2] = 0; // y of sphere's center #declare Cp[0][3] = 0; // Distanse of sphere's center #declare Cp[0][4] = 2*pi*rand(R1); // Longitude Angle of sphere's center (keido) #declare Cp[0][5] = pi/2*(0.5+0.5*rand(R1)); // Latitude Angle of sphere's center (ido) sphere { Rds pigment {color rgb <1, 1-0/Nmax*0.8, 0.2>} finish { reflection 0.3 phong 2 brilliance 1 ambient 0.4 } no_shadow } #declare Np = 1; #while (Np < Nmax) #declare Cp[Np][4] = 2*pi*rand(R1); #declare Cp[Np][5] = pi/2*(0.5+0.5*rand(R1)); //pi*rand(R1)-pi/2; #if (Np = 1) #declare Cp[Np][3] = 2; //Templary size #declare Cp[Np][0] = Cp[Np][3]*cos(Cp[Np][5])*cos(Cp[Np][4]); #declare Cp[Np][1] = Cp[Np][3]*cos(Cp[Np][5])*sin(Cp[Np][4]); #declare Cp[Np][2] = Cp[Np][3]*sin(Cp[Np][5]); #declare Nsclose = 0; #else #declare Ns = Np-1; #while (Ns>0) #declare Cp[Np][3] = Cp[Ns][3]; #declare Cp[Np][0] = Cp[Np][3]*cos(Cp[Np][5])*cos(Cp[Np][4]); #declare Cp[Np][1] = Cp[Np][3]*cos(Cp[Np][5])*sin(Cp[Np][4]); #declare Cp[Np][2] = Cp[Np][3]*sin(Cp[Np][5]); #declare Det = 0; #declare Ldis = sqrt(pow(Cp[Np][0]-Cp[Ns][0],2)+pow(Cp[Np][1]-Cp[Ns][1],2)+pow(Cp[Np][2]-Cp[Ns][2],2)); #if (Ldis < 1) //< 2) #declare Apn = asin(Ldis/2/Cp[Ns][3]); #declare Cp[Np][3] = Cp[Ns][3]*cos(2*Apn)+sqrt(4-pow(Ldis*cos(Apn),2)); // Real size #declare Cp[Np][0] = Cp[Np][3]*cos(Cp[Np][5])*cos(Cp[Np][4]); #declare Cp[Np][1] = Cp[Np][3]*cos(Cp[Np][5])*sin(Cp[Np][4]); #declare Cp[Np][2] = Cp[Np][3]*sin(Cp[Np][5]); #declare Nsclose = Ns; #declare Det = 1; #declare Ns = 1; #end #declare Ns = Ns-1; #end #if (Det = 0) #declare Cp[Np][3] = 2; #declare Cp[Np][0] = Cp[Np][3]*cos(Cp[Np][5])*cos(Cp[Np][4]); #declare Cp[Np][1] = Cp[Np][3]*cos(Cp[Np][5])*sin(Cp[Np][4]); #declare Cp[Np][2] = Cp[Np][3]*sin(Cp[Np][5]); #declare Nsclose = 0; #end #end union { sphere { Rds} cylinder { Rds} pigment {color rgb <1,0.7,0.7>} finish { reflection 0.3 phong 2 brilliance 1 ambient 0.5 } no_shadow } #declare Np = Np+1; #end #end //initialize the coordinates of beads (X=Cp[I][0] Y=Cp[I][1]) #declare Imax=100; #declare Cd=array[Imax][3] #declare I=0; #while (I0.3) #declare Ad=0.5*rand(Rndm); #end //confuse the arrangement #if (Ae-Ap<0) #declare Ap=Ap-2*pi; #end #declare Bo=acos(1/Rdg/tan(pi-2*Ao)); #if (Ao>pi/4) #declare Rb=2*Bo/pi; #else #declare Rb=1; #end #if (Ae-Ap-As-Al-Ad>0) #declare I=0; #while (I0) #declare I=0; #while (Ipi/2-1/Rdg) #declare Jd=Jdl; #end #declare Jd=Jd+1; #end #declare I=0; #while (I0) #declare Ai=sqrt(Cd[I][0]*Cd[I][0]+Cd[I][1]*Cd[I][1])/2/Rdg; #declare Ri=sin(Ai)*cos(Ai)/Ai; #else #declare Ai=0; #declare Ri=1; #end //arranging beads and calculating the coordinates of the holes position #declare Cd[I][0]=Ri*Cd[I][0]; #declare Cd[I][1]=Ri*Cd[I][1]; #declare Cd[I][2]=Rdg-2*Rdg*sin(Ai)*sin(Ai); #declare I=I+1; #end //initialize the coordinates for mesh Cp(x,y,z,r) #declare Vmax=72; // #declare Hmax=2*Vmax; #declare Cp=array[Hmax][Vmax+2][4] #declare V=0; #while (V, , } triangle { , , } #end //normal vector of the plar coordinates point #macro Vd (Ph,Pv) <(Cp[mod(Ph-1+Hmax,Hmax)][Pv][1]-Cp[Ph][Pv][1])*(Cp[Ph][Pv-1][2]-Cp[Ph][Pv][2])-(Cp[Ph][Pv-1][1]-Cp[Ph][Pv][1])*(Cp[mod(Ph-1+Hmax,Hmax)][Pv][2]-Cp[Ph][Pv][2]), (Cp[Ph][Pv-1][0]-Cp[Ph][Pv][0])*(Cp[mod(Ph-1+Hmax,Hmax)][Pv][2]-Cp[Ph][Pv][2])-(Cp[mod(Ph-1+Hmax,Hmax)][Pv][0]-Cp[Ph][Pv][0])*(Cp[Ph][Pv-1][2]-Cp[Ph][Pv][2]), (Cp[mod(Ph-1+Hmax,Hmax)][Pv][0]-Cp[Ph][Pv][0])*(Cp[Ph][Pv-1][1]-Cp[Ph][Pv][1])-(Cp[Ph][Pv-1][0]-Cp[Ph][Pv][0])*(Cp[mod(Ph-1+Hmax,Hmax)][Pv][1]-Cp[Ph][Pv][1])> #end //smooth_triangle of the surface #macro Trisd (Ph,Pv) #declare Ph1=mod(Ph-1+Hmax,Hmax); smooth_triangle { Vd(Ph,Pv) Vd(Ph1,Pv-1) Vd(Ph,Pv-1) } smooth_triangle { Vd(Ph1,Pv) Vd(Ph1,Pv-1) Vd (Ph,Pv) } #end //radius caliculation and the translation from polar to xyz coordinsates #declare V=0; #while (V } #declare P = P+1; #end pigment {color rgbt <1, 0, 0, 0.3>} finish { reflection 0.7 phong 2 brilliance 1 ambient 0.3 } rotate <30, 200, 60> no_shadow } background {color rgb <0.01, 0, 0.2>}