Option Explicit '------------------------------------------------------------------------------------------- 'fractal volumes 'Pablo Miranda Carranza, code released under GNU General Public License (www.gnu.org/licenses/gpl.txt) '------------------------------------------------------------------------------------------- Sub fractal() Dim arrVertCube(7) 'the vertices of the cube Dim i Dim Objcube1ID Dim Objcube2ID Dim arrcube_vert Dim cube_vert randomize 'only needed if we are using any random function 'initialise the array with all the vertices of the cube...this is the way of describing a cube in Rhino arrVertCube(0)= Array(-1.0,-1.0,-1.0) arrVertCube(1)= Array( 1.0,-1.0,-1.0) arrVertCube(2)= Array( 1.0, 1.0,-1.0) arrVertCube(3)= Array(-1.0, 1.0,-1.0) arrVertCube(4)= Array(-1.0,-1.0, 1.0) arrVertCube(5)= Array( 1.0,-1.0, 1.0) arrVertCube(6)= Array( 1.0, 1.0, 1.0) arrVertCube(7)= Array(-1.0, 1.0, 1.0) Rhino.EnableRedraw(vbFalse) 'so it goes faster. If you want to see Rhino drawing, comment off this line... Objcube1ID = Rhino.AddBox (arrVertCube) 'it needs to go between parenthesis when returning a value Recurse arrVertCube, 5 'this is the recursive subrutine, the heart of a fractal Rhino.EnableRedraw(vbTrue)'we enable it back after generating geometry End sub 'end of the main subrutine 'recursive subrutine Sub Recurse(arr_vertices, byval recnum) Dim cube_vert Dim arr_new_vert(7) Dim new_ObjectcubeID Dim cube_size 'reduce the recursion index (otherwise it will run to infinity (until rhino crashes...) recnum=recnum-1 'we calculate here the size of the cube (more or less) we have got cube_size=arr_vertices(0)(0)- arr_vertices(1)(0) cube_size= Abs (cube_size) 'absolute value, that is, if negative make it positive cube_size=cube_size/4 'we will use a fourth of the size for each cube_vert in arr_vertices 'we make a new cube centred around each vertex of the old one (and a fourth in size) arr_new_vert(0)=array (cube_vert(0)-cube_size, cube_vert(1)-cube_size ,cube_vert(2)-cube_size) arr_new_vert(1)=array (cube_vert(0)+cube_size, cube_vert(1)-cube_size ,cube_vert(2)-cube_size) arr_new_vert(2)=array (cube_vert(0)+cube_size, cube_vert(1)+cube_size ,cube_vert(2)-cube_size) arr_new_vert(3)=array (cube_vert(0)-cube_size, cube_vert(1)+cube_size ,cube_vert(2)-cube_size) arr_new_vert(4)=array (cube_vert(0)-cube_size, cube_vert(1)-cube_size ,cube_vert(2)+cube_size) arr_new_vert(5)=array (cube_vert(0)+cube_size, cube_vert(1)-cube_size ,cube_vert(2)+cube_size) arr_new_vert(6)=array (cube_vert(0)+cube_size, cube_vert(1)+cube_size ,cube_vert(2)+cube_size) arr_new_vert(7)=array (cube_vert(0)-cube_size, cube_vert(1)+cube_size ,cube_vert(2)+cube_size) new_ObjectcubeID = Rhino.AddBox (arr_new_vert) 'THE RECURSIVE CALL!!!!!LOOK AT IT HERE!!!!!IT CALLS ITSELF!!!! 'if the recursion number is not 0 call itself again 'if recnum > 0 then 'this is other version has random added if recnum > 0 AND Rnd>0.5 then Recurse arr_new_vert,recnum end if next End sub 'we call the sub here so we don't have to run it (it will run at load) fractal()