Grashopper Sphere Packing, for random foam structures

how is the scripting of the following is done

and can it be done with hexapod modules as well?