//Pylon object with screws

#declare PYL_PylonColor = color srgb 1;
#declare PYL_SmallPylonRadius = 0.5;
#declare PYL_BasePylonRadius = 0.75;
#declare PYL_JunctionHeight = 0.2;
#declare PYL_ScrewColor = color srgb 0.7;
#declare PYL_ScrewSideNum = 8;
#declare PYL_ScrewRadius = 0.075;
#declare PYL_ScrewCoords = array[PYL_ScrewSideNum];
#declare PYL_PerPylonScrewsNumber = 12;
#declare PYL_NutThickness = 0.075;

#for( It, 0, PYL_ScrewSideNum - 1 )
	#declare PYL_ScrewCoords[It] = vrotate( < PYL_ScrewRadius, 0, 0 >, < 0, 360 / PYL_ScrewSideNum * It, 0 >);
#end

#declare PYL_MainCylinder = cylinder{ < 0, PYL_JunctionHeight, 0 >,< 0, 1.5, 0 >, PYL_SmallPylonRadius pigment{ PYL_PylonColor } }
#declare PYL_BaseCylinder = cylinder{ < 0, 0, 0 >, < 0, PYL_JunctionHeight, 0 >, PYL_BasePylonRadius pigment{ PYL_PylonColor } }

#declare ScrewNut = 
prism{ linear_sweep linear_spline 0, PYL_NutThickness, PYL_ScrewSideNum + 1
	#for( It, 0, PYL_ScrewSideNum )
		#local Index = mod( It, PYL_ScrewSideNum );
		< PYL_ScrewCoords[Index].x, PYL_ScrewCoords[Index].z >
	#end
}

#declare CompleteScrew =
union{
	object{ ScrewNut }
	sphere{ < 0, PYL_NutThickness, 0 >, PYL_ScrewRadius * 3 / 4 }
	pigment{ PYL_ScrewColor }
}

#declare CompletePylon =
union{
	object{ PYL_MainCylinder }
	object{ PYL_BaseCylinder }
	#for( It, 0, PYL_PerPylonScrewsNumber - 1 )
		object{ CompleteScrew 
				translate < -PYL_BasePylonRadius + PYL_ScrewRadius * 2, PYL_JunctionHeight, 0 >
				rotate 360 / PYL_PerPylonScrewsNumber * It * y
		}
	#end
}