import rhinoscriptsyntax as rs import random as ran # Delete all objects and start from scratch rs.DeleteObjects(rs.AllObjects()) # Parameters bsize, dist, num = 10, 5, 30 # Box size, distance between boxes, and number of boxes per row offs = bsize + dist # Offset between the boxes corners = [(0, 0, 0), (bsize, 0, 0), (bsize, bsize, 0), (0, bsize, 0), (0, 0, bsize), (bsize, 0, bsize), (bsize, bsize, bsize), (0, bsize, bsize)] # Box corners # Disable redraw for faster execution rs.EnableRedraw(False) # Create and move boxes for i in range(num): for j in range(num): for p in range(num): if ran.randint(0, 9) < 6 and ((i + j) % 2) and ((i - j) % 4) and ((i + j - p) % 9): box = rs.AddBox(corners) # Create box rs.MoveObject(box, (i * offs, j * offs, p * offs)) # Move box rs.ObjectColor(box, (i * 255 // num, j * 255 // num, p * 255 // num)) # Color box # Enable redraw to update the view rs.EnableRedraw(True)