global_settings {
	max_trace_level 100
	adc_bailout 1/255
}



camera {
	perspective
	location <0, 1, -6>
	sky <0, 1, 0>
	direction <0, 0, 1>
	right <1.33333, 0, 0>
	up <0, 1, 0>
	look_at <0, 0, 0>
}

light_source {
	<0, 2.5, -2.5>, 0.9
}

// x1,x2 = endpoints of cylinder
// dx = length of each block
// sx = x spacing between each block
// r = radius to center of block
// height = size of block
// dz = Z size
// copies = copies of block per section
// ph = phase, given in terms of _amount of ONE BLOCK_
// shear1,shear2 = start and end values for Z-shearing (linear)
#macro Make_Blocked_Cylinder_Corrected(x1, x2, dx, sx, r, height, dz, copies, ph, shear1, shear2)
	#local arc = 360/copies;
	#local start = arc * ph;
	#local cx = x1;
	// Linear formula thingy, y=mx+b
	#local m = (shear1 - shear2) / (x1 - x2);
	#local b = shear1 - m * x1;
	#local step = 0;
	#while (cx <= x2)
		#local shear = m * cx + b;
		#local i = 0;
		#while (i < copies)
			box {
				< 0, -height/2, -dz/2>,
				< dx, height/2,  dz/2>
				matrix <1,0,shear,
					0,1,0,
					0,0,1,
					0,0,0>
				translate <cx, r, 0>
				rotate <i * arc + start + step, 0, 0>
			}
			#local i = i + 1;
		#end
		#local cx = cx + dx + sx;
		//#debug "\nStep: "
		//#debug str(, 0, -1)
		#local step = step + degrees(atan2(shear,r));
	#end
#end


#declare outer_red = texture {
	pigment { rgbft<0.3, 0.3, 0.7, 0.4, 0.3> }
	finish {
		ambient 0.7
		specular 0.25
		roughness 0.02
	}
}
#declare outer_cyan = texture {
	pigment { rgbft<0.5, 0.8, 0.9, 0.3, 0.5> }
	finish {
		ambient 0.4
		specular 0.25
		roughness 0.02
	}
}
#declare med_red = texture {
	pigment { rgbft<0.2, 0.2, 0.8, 0.1, 0.2> }
	finish {
		ambient 0.4
		specular 0.25
		roughness 0.05
	}
}
#declare med_orange = texture {
	pigment { rgbft<0.2, 0.5, 0.8, 0.1, 0.2> }
	finish {
		ambient 0.45
		specular 0.20
		roughness 0.05
	}
}
#declare inner_yellow = texture {
	pigment { rgbft<0.4, 0.8, 0.9, 0.0, 0.0> }
	finish {
		ambient 0.6
		specular 0.35
		roughness 0.02
		//reflection 0.3
	}
}
#declare inner_red = texture {
	pigment { rgbft<0.0, 0.0, 0.8, 0.0, 0.0> }
	finish { ambient 0.8 }
}
#declare core_red = texture {
	pigment { rgbft<0.1, 0.6, 1.0, 0.0, 0.0> }
	finish { ambient 1.0 }
}

#declare glow = material {
	texture { pigment { rgbt 1 } }
	interior {
		media {
			emission 2
			density {
				bozo density_map {
					[0 rgb<0.2, 0.7, 0.8>]
					[0.35 rgb<0, 0.4, 0.9>]
					[0.5 rgb 0]
					[0.65 rgb<0, 0.4, 0.9>]
					[1.0 rgb<0.2, 0.7, 0.8>]
				}
				scale 1
			}
		}
	}
}
     // Make_Blocked_Cylinder_Corrected(x1, x2,  dx,  sx,    r, height, dz, copies, ph, shear_start, shear_end)
union { Make_Blocked_Cylinder_Corrected(-4,   4, 0.8, 0.02, 2.4,   0.1, 0.4,    16,    0, -1, 0)
	texture { outer_red } }
union { Make_Blocked_Cylinder_Corrected(-4,   4, 0.8, 0.02, 2.4,   0.1, 0.4,    16,    0.5, -1, 0)
	texture { outer_cyan } }
union { Make_Blocked_Cylinder_Corrected(-4,   4, 0.8, 0.1,  2.0,   0.1, 0.2,    12,    0, 0, 1)
	texture { med_red } }
// union { Make_Blocked_Cylinder_Corrected(-4,   4, 0.8, 0.1,  2.0,   0.1, 0.3,    12,    0.5, 0, 1)
// 	texture { med_orange } }
union { Make_Blocked_Cylinder_Corrected(-3.6, 4.4, 0.75, 0.07, 1.8,   0.03, 0.2,    11,    0, -1, -0)
	texture { inner_yellow } }
// union { Make_Blocked_Cylinder_Corrected(-4,  4, 0.2, 0.01, 1.6,   0.1, 0.05,    32,    0, -1.5, -1.4)
// 	texture { inner_red } }
union { Make_Blocked_Cylinder_Corrected(-3.9,  4.1, 0.2, 0.01, 1.4,   0.1, 0.05,    23,    0, 1.1, 1.2)
	texture { core_red } }

cylinder {
	<-5, 0, 0>, <5, 0, 0>, 1.2
	hollow
	material { glow }
}

#macro Crazy_Tile(x1, x2, z1, z2, dx, dz, sx, sz, height, xz_sh1, xz_sh2, zx_sh1, zx_sh2, tex1, tex2)
	#local cx = x1;
	// Linear formula thingy, y=mx+b
	#local xz_m = (xz_sh1 - xz_sh2) / (z1 - z2);
	#local xz_b = xz_sh1 - xz_m * z1;
	#local zx_m = (zx_sh1 - zx_sh2) / (x1 - x2);
	#local zx_b = zx_sh1 - zx_m * x1;
	#local tex = 0;
	#while (cx < x2)
		#local cz = z1;
// 		#if (tex = 0) #local tex = 1;
// 		#else #local tex = 0;
// 		#end
		#while (cz < z2)
			#local z_shift = 0;
			#local x_shift = 0;
			#if (tex = 0) #local tex = 1;
			#else #local tex = 0;
			#end
			box {
				#local x_shear = zx_m*cx + zx_b;
				#local z_shear = xz_m*cz + xz_b;
				<0, 0, 0>, <dx, height, dz>
				matrix < 1, 0, z_shear,
					0, 1, 0,
					x_shear, 0, 1
					0, 0, 0 >
				translate <cx + x_shift, 0, cz + z_shift>
				#if (tex=0) texture { tex1 }
				#else texture { tex2 }
				#end
				#local x_shift = x_shift + x_shear * dz;
				#local z_shift = z_shift + z_shear * dx;
			}
			#local cz = cz + dz + sz;
		#end
		#local cx = cx + dx + sx;
	#end
#end

#declare t1 = texture { pigment { rgb<1, 0.5, 0.5> } }
#declare t2 = texture { pigment { rgb<0.5, 0.5, 1> } }

// union {
// 	Crazy_Tile(-5, 5, -5, 5, 0.5, 0.5, 0.05, 0.05, 0.5, 0.5, -1.5, -1.5, 1.5, t1, t2)
// 	//rotate -45*x
// 	translate -*y
// }