// Cube Gluing: written by Eric Ferrante #version 3 #include "colors.inc" #include "shapes.inc" camera { location <0, 10, -20> direction 1.4*z right 4/3*x rotate(-20*y) look_at <0,0,0> } light_source { < 40, 50, -30> color White } light_source { < 0, 10, -30> color White } #declare radius1 = 5 // major axis of torus #declare radius2 = 1 // minor axis of torus #declare mybox = // opposite faces are same color intersection { plane { y, 1 pigment { color Yellow } finish { phong 0.7 } } plane { -y, 1 pigment { color Yellow } finish { phong 0.7 } } plane { x, 1 pigment { color Green } finish { phong 0.7 } } plane { -x, 1 pigment { color Green } finish { phong 0.7 } } plane { z, 1 pigment { color Blue } finish { phong 0.7 } } plane { -z, 1 pigment { color Blue } finish { phong 0.7 } } bounded_by { box { <-1.1,-1.1,-1.1>, <1.1,1.1,1.1> } } translate(-radius1*y) } #declare mycylinder1 = difference { union { cylinder { (-1*z),(1*z),(radius1+1) pigment { color Blue } finish { phong 0.7 } } cylinder { (-1*z),(1*z),(radius1+1.0001) open pigment { color Yellow } finish { phong 0.7 } } } cylinder { (-1.0001*z),(1.0001*z),(radius1-1) pigment { color Yellow } finish { phong 0.7 } } bounded_by { cylinder { (-1.1*z),(1.1*z),(radius1+2) } } } #declare mycylinder2 = difference { cylinder { (-1*y),(1*y),(radius2+1.1) pigment { color Blue } finish { phong 0.7 } } cylinder { (-1.0001*y),(1.0001*y),(radius2+0.6) pigment { color Blue } finish { phong 0.7 } } bounded_by { cylinder { (-1.1*y),(1.1*y),(radius2+1.5) } } } #switch (clock) // clock=[0,3] #range (0,0.75) // 0<=clock<=0.75 #debug "Status: Phase I, rotating cube\n" #debug concat("clock:",str(clock,3,5),"\n") object { mybox rotate(clock/0.75*180*y) translate((0.75-clock)*radius1*y)} #break #range (0.75001, 1.75) // 0.75< clock<=1.75 #debug "Status: Phase II, gluing green faces\n" #debug concat("clock:",str(clock,3,5),"\n") #debug concat("theta1:",str((180*(clock-0.75)),3,5),"\n") #declare theta1=0 #while (theta1 <= (180*(clock-0.75) )) object { mybox translate(radius1*y) scale<1, 1, (1-.2*(clock-0.75))> translate(-radius1*y) rotate ( theta1*z) } object { mybox translate(radius1*y) scale<1, 1, (1-.2*(clock-0.75))> translate(-radius1*y) rotate (-theta1*z) } #declare theta1=theta1+5 #end #break #range (1.75001, 1.78) // 1.75< clock<=1.80 #debug "------------------------------------\n" #debug "Status: Phase II, gluing green faces\n" #debug concat("clock:",str(clock,3,5),"\n") #debug concat("--Idle--\n") #debug "------------------------------------\n" object { mycylinder1 scale<1, 1, .8> } #break #range (1.78001, 3) // 1.80< clock<=3 #debug "------------------------------------\n" #debug "Status: Phase III, gluing yellow faces\n" #debug concat("clock:",str(clock,3,5),"\n") #declare theta1 = 360*(clock-1.48)/(3-1.48) #debug concat("theta1:",str(theta1,3,5),"\n") #if (theta1<180) #debug "theta1<180" #declare shell = intersection { object { mycylinder2 } object { plane {( 1*z), 0 } rotate(-theta1/2*y) pigment { color Yellow }} object { plane {(-1*z), 0 } rotate(theta1/2*y) pigment { color Yellow }} } #end #if (theta1=180) #debug "theta1=180" #declare shell = intersection { object { mycylinder2 } object { plane {(-1*x), 0 } pigment { color Yellow } } } #end #if ( (theta1>180)&(theta1<360) ) #debug "(theta1>180)&(theta1<360)" #declare pie_slice = intersection { plane {( 1*z), 0 rotate(theta1/2*y) pigment { color Yellow }} plane {(-1*z), 0 rotate(-theta1/2*y) pigment { color Yellow }} } #declare shell = difference { object { mycylinder2 } object { pie_slice } } #end #if (theta1=360) #debug "theta1=360" #declare shell = object { mycylinder2 } #end #debug "\n------------------------------------\n" #declare theta2 = 0 #while (theta2 <= 180) object { shell rotate(-90*y) translate <(radius1+0.1),0,-2> rotate(theta2*z) } object { shell rotate(-90*y) translate <(radius1+0.1),0,-2> rotate(-theta2*z) } #declare theta2=theta2+15 #end #break #range (3.0001, 3.5) // 3< clock<=3.5 #declare theta2 = 0 #declare mytorus = union { #while (theta2 <= 180) object { mycylinder2 rotate(-90*y) translate <(radius1+0.1),0,-2> rotate(theta2*z) } object { mycylinder2 rotate(-90*y) translate <(radius1+0.1),0,-2> rotate(-theta2*z) } #declare theta2=theta2+15 #end } intersection { object { plane { y, 0 } pigment { color Yellow } } object { mytorus } } intersection { object { plane { -y, 0 } pigment { color Yellow } } object { mytorus } translate((clock-3)*2*8*y) } #break #end