import rhinoscriptsyntax as rs import Rhino.Geometry as rg import random as r rs.EnableRedraw(False) origin = rg.Point3d(0,0,0) length = 100 angle = 30 reduction_factor = 0.6 iterations = 12 reduction_jitter = 0.2 angle_jitter = 20 branches = [] current_iteration = [] next_iteration = [] start_point = origin end_point = start_point + rg.Vector3d.YAxis*length branch = rs.AddLine(start_point, end_point) current_iteration.append(branch) for i in range(iterations): for branch in current_iteration: start_point = rs.CurveEndPoint(branch) reduction_noise = r.uniform(-reduction_jitter, reduction_jitter) angle_noise = r.uniform(-angle_jitter, angle_jitter) length = rs.CurveLength(branch)*(reduction_factor + reduction_noise) axis = rs.VectorCreate(rs.CurveEndPoint(branch), rs.CurveStartPoint(branch)) axis_unitized = axis/rs.CurveLength(branch) end_point = start_point + axis_unitized*length branch_a = rs.AddLine(start_point, end_point) branch_b = rs.AddLine(start_point, end_point) rs.RotateObject(branch_a, start_point, angle + angle_noise) rs.RotateObject(branch_b, start_point, -angle + angle_noise) next_iteration.append(branch_a) next_iteration.append(branch_b) current_iteration = next_iteration next_iteration = []