private void RunScript(int n, ref object A)
{
if (n > 4)
{
Component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "n was lowered to 4");
n = 4;
}
var boxes = new List<Box>();
boxes.Add(new Box(Plane.WorldXY, new Interval(0, 10), new Interval(0, 10), new Interval(0, 10)));
for (var i = 0; i < n - 1; i++)
{
var temp = new List<Box>();
foreach (var b in boxes)
temp.AddRange(Subdivide(b));
boxes = temp;
}
if (n > 0)
{
var output = new List<GH_Box>();
foreach (var b in boxes)
output.AddRange(LastSubdivide(b));
A = output;
}
else A = boxes;
}
// <Custom additional code>
const double oneThird = 1.0 / 3.0;
const double twoThird = 2.0 / 3.0;
IEnumerable<Box> Subdivide(Box b)
{
var d = new Interval(0, (b.X.T1 - b.X.T0) * oneThird);
return new List<Box>()
{
new Box(new Plane(b.PointAt(oneThird, 0, 0), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(0, oneThird, 0), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(oneThird, oneThird, 0), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(twoThird, oneThird, 0), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(oneThird, twoThird, 0), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(0, 0, oneThird), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(oneThird, 0, oneThird), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(twoThird, 0, oneThird), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(0, oneThird, oneThird), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(oneThird, oneThird, oneThird), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(twoThird, oneThird, oneThird), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(0, twoThird, oneThird), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(oneThird, twoThird, oneThird), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(twoThird, twoThird, oneThird), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(oneThird, 0, twoThird), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(0, oneThird, twoThird), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(oneThird, oneThird, twoThird), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(twoThird, oneThird, twoThird), Vector3d.ZAxis), d, d, d),
new Box(new Plane(b.PointAt(oneThird, twoThird, twoThird), Vector3d.ZAxis), d, d, d),
};
}
IEnumerable<GH_Box> LastSubdivide(Box b)
{
var d = new Interval(0, (b.X.T1 - b.X.T0) * oneThird);
return new List<GH_Box>()
{
new GH_Box(new Box(new Plane(b.PointAt(oneThird, 0, 0), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(0, oneThird, 0), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(oneThird, oneThird, 0), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(twoThird, oneThird, 0), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(oneThird, twoThird, 0), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(0, 0, oneThird), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(oneThird, 0, oneThird), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(twoThird, 0, oneThird), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(0, oneThird, oneThird), Vector3d.ZAxis), d, d, d)),
//new GH_Box(new Box(new Plane(b.PointAt(oneThird, oneThird, oneThird), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(twoThird, oneThird, oneThird), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(0, twoThird, oneThird), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(oneThird, twoThird, oneThird), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(twoThird, twoThird, oneThird), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(oneThird, 0, twoThird), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(0, oneThird, twoThird), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(oneThird, oneThird, twoThird), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(twoThird, oneThird, twoThird), Vector3d.ZAxis), d, d, d)),
new GH_Box(new Box(new Plane(b.PointAt(oneThird, twoThird, twoThird), Vector3d.ZAxis), d, d, d)),
};
}
// </Custom additional code>
BoxFractal.gh (2.7 KB)