Skip to content

Instantly share code, notes, and snippets.

@captDaylight
Last active December 11, 2018 23:20
Show Gist options
  • Save captDaylight/9056694fc5164db83411b118413e23ca to your computer and use it in GitHub Desktop.
Save captDaylight/9056694fc5164db83411b118413e23ca to your computer and use it in GitHub Desktop.
import random
import rhinoscriptsyntax as rs
def draw_box(x, y, z, box_size):
surface_points = [
[x, y, z],
[x + box_size, y, z],
[x + box_size, y + box_size, z],
[x, y + box_size, z]
]
curve = rs.AddCurve([x, y, z], [x, y, z + box_size])
surface = rs.AddSrfPts(surface_points)
box = rs.ExtrudeSurface(surface, curve)
rs.DeleteObjects([curve, surface])
return box
def draw_unit(x, y):
box_size = 0.1
probabilty = 1
pos = [0, 0, 0]
boxes = []
boxes.append(draw_box(x, y, 0))
while random.random() < probabilty:
probabilty += 0.1
ran = random.random()
if ran < 0.333:
pos[0] += box_size
elif ran < 0.666:
pos[1] += box_size
else:
pos[2] += box_size
boxes.append(draw_box(x + pos[0], y + pos[1], 0 + pos[2], box_size))
rs.BooleanUnion(boxes)
def main():
for x in range(5):
for y in range(5):
draw_unit(x, y)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment