//rgb cube with animation by Marc Roth //for troubleshooting mail to alsjeblieft@web.de //for animations choose dim higher than 2 and use //final_clock = 9*dim-7 for odd values of dim //final_clock = 9*dim-8 for even values of dim //for a realistic speed use somthing like 25*final_clock for number of frames @ 25fps #include "math.inc" //variables #declare dim = 3; //number of cubes per side #declare d = 0.05; //thickness of cube-wall #declare s = 1.0; //size of cube #declare a = 1.0; //space between cubes #declare D = s/10; //radius of conenction tubes #declare T = 0.8; //transparency (1=transparent, 0 = solid) #declare B = dim*(s+a); //total length of object's side #declare preview = 1; //1 = preview picture with camerapath shown with cones //0 = animation with camera following a path defined by cam_loc #declare where = array[dim][dim][dim]; //array for coordinates of all cubes //use the coordinates in where[x][y][z] for animation purposes of whatever //where[0][0][0] is the cube in the lower left front-corner //error catching for final_clock values below neccessary //comment this part out for animations that don't use the full cam_loc path #if (clock_on=1) #if (even(dim)=1) #if (final_clock<9*dim-8) #error concat("!!!you have to use a final_clock value of ",str(9*dim-8,0,0),"for even values of dim!!!\n") #end #end #if (odd(dim)=1) #if (final_clock<9*dim-7) #error concat("!!!you have to use a final_clock value of ",str(9*dim-7,0,0),"for odd values of dim!!!\n") #end #end #end #global_settings { //radiosity { } max_trace_level 10*dim } /*//x-/y-/z-axis just for development purposes cylinder { <-1000,0,0>,<1000,0,0>,0.05 pigment { rgbt <1,0,0,0.5>}} //x-achse cylinder { <0,-1000,0>,<0,1000,0>,0.05 pigment { rgbt <0,1,0,0.5>}} //y-achse cylinder { <0,0,-1000>,<0,0,1000>,0.05 pigment { rgbt <0,0,1,.05>}} //z-achse */ //cam&light #if (preview=1) camera { location B*<1.2,1.3,-1> look_at 0 } #end light_source { <10000,15000,-8000>, rgb 1 } //the cubus itself. leave out the part after the closing bracket of merge to get solid cubes #declare cubus2 = difference { merge { box { -s/2,s/2 } cylinder { <-(a/2+s/2),0,0>,<+(a/2+s/2),0,0>, D } //x-direction tube cylinder { <0,-(a/2+s/2),0>,<0,+(a/2+s/2),0>, D } //y-direction tube cylinder { <0,0,-(a/2+s/2)>,<0,0,+(a/2+s/2)>, D } //z-direction tube } box { -(s/2-d),+(s/2-d) } cylinder { <-1.1*(a/2+s/2),0,0>,<+1.1*(a/2+s/2),0,0>, 0.9*D } //x-direction tube-cutout cylinder { <0,-1.1*(a/2+s/2),0>,<0,+1.1*(a/2+s/2),0>, 0.9*D } //y-direction tube-cutout cylinder { <0,0,-1.1*(a/2+s/2)>,<0,0,+1.1*(a/2+s/2)>, 0.9*D } //z-direction tube-cutout } //the rgb-cube including a debug-stream with coordinates of all cubes #declare rgb_cube = union { #declare X = 0; //x-coordinate of cube #declare Xc = 0; //red-value of cube #declare Y = 0; //y-coordinate of cube #declare Yc = 0; //green-value of cube #declare Z = 0; //z-coordinate of cube #declare Zc = 0; //blue-value of cube #while (X #declare where[X][Y][Z] = +(0.5*(s+a)-0.5*B)*<1,1,1>; //store cube's positions in an array for later use #debug concat("(",str(X,0,0),"|",str(Y,0,0),"|",str(Z,0,0),")=<",str(where[X][Y][Z].x,2,0),";",str(where[X][Y][Z].y,2,0),";",str(where[X][Y][Z].z,2,0),"> ") pigment { rgbt } finish { ambient .5 } } #declare Zc = Zc+1/dim; #declare Z = Z+1; #end #debug "\n" #declare Yc = Yc+1/dim; #declare Y = Y+1; #end #declare Xc = Xc+1/dim; #declare X = X+1; #end } //translates cube so that it's center = <0,0,0> object { rgb_cube translate (0.5*(s+a)-0.5*B)*<1,1,1> } //animation #declare cam_loc = spline { //this spline is used for the position of the camera //it creates a path from the upper right front-corner all around //to the upper right back-corner from there down and back to the //lower right front-corner,from there to the middle of the lower right //side and finally to the lower center and upwards out of the cube linear_spline 0, where[dim-1][dim-1][0]+, //A dim, where[0][dim-1][0], //B 2*dim-1, where[0][dim-1][dim-1], //C 3*dim-2, where[dim-1][dim-1][dim-1], //D 4*dim-3, where[dim-1][0][dim-1], //E 5*dim-4, where[0][0][dim-1], //F 6*dim-5, where[0][0][0], //G 7*dim-6, where[dim-1][0][0], //H #if (odd(dim)=1) 7*dim-6+dim/2-0.5, where[dim-1][0][dim/2-0.5], //I for odd numbers 8*dim-7, where[dim/2-0.5][0][dim/2-0.5], //J for odd numbers 9*dim-7, where[dim/2-0.5][dim-1][dim/2-0.5]+<0,s+a,0>, //K for odd numbers #else //#if (even(dim)=1) 7*dim-6+dim/2-1, where[dim-1][0][dim/2-1], //I for even numbers 8*dim-8, where[dim/2][0][dim/2-1], //J for even numbers 9*dim-8, where[dim/2][dim-1][dim/2-1]+<0,s+a,0>, //K for even numbers #end } #declare cam_loo = spline { //this spline is used for the orientation of the camera linear_spline 0, < -90,180, 0>, //A dim-1, < -90,180, 0>, dim, < -90,270, 0>, //B 2*dim-2, < -90,270, 0>, 2*dim-1, < -90,360, 0>, //C 3*dim-3, < -90,360, 0>, 3*dim-2, <-180,360, -90>, //D 4*dim-4, <-180,360, -90>, 4*dim-3, <-180,360,-180>, //E 5*dim-5, <-180,360,-180>, 5*dim-4, < -90,450,-180>, //F 6*dim-6, < -90,450,-180>, 6*dim-5, < -90,540,-180>, //G 7*dim-7, < -90,540,-180>, 7*dim-6, < -90,630,-180>, //H #if (odd(dim)=1) 7*dim-6+dim/2-1.5, < -90,630,-180>, 7*dim-6+dim/2-0.5, < -90,720,-180>, //I for odd numbers 8*dim-8, < -90,720,-180>, 8*dim-7, <-180,720,-270>, //J for odd numbers 9*dim-7, <-180,720,-270>, //K for odd numbers #else //#if (even(dim)=1) 7*dim-6+dim/2-2, < -90,630,-180>, 7*dim-6+dim/2-1, < -90,720,-180>, //I for even numbers 8*dim-9, < -90,720,-180>, 8*dim-8, <-180,720,-270>, //J for even numbers 9*dim-8, <-180,720,-270>, //K for even numbers #end } #if (preview=0) camera { location <0,0,0> look_at <1,0,0> rotate cam_loo(clock) translate cam_loc(clock) } #else #declare n = 0; #while (n<9*dim-7) cone { <0,0,0>,0.1,<0.2,0,0>,0 rotate cam_loo(n) translate cam_loc(n) pigment { rgb <1,0,0> } no_shadow } #declare n = n+0.1; #end #end