Untitled

mail@pastecode.io avatar
unknown
plain_text
4 years ago
1.6 kB
3
Indexable
Never
import Rhino as rc
import random


def splitQuad(quad,edgeValues):
    
    # Get edges and vertices
    segs = quad.GetSegments()
    
    # Calculate orientation
    if segs[0].Length > segs[1].Length:
        edgeStart = 0
    else:
        edgeStart = 1
    
    # Make new vertex list
    if edgeStart == 0:
        faceVts = [(segs[3].To,segs[3].From),]
    elif edgeStart == 1:
        faceVts = [(segs[0].To,segs[0].From),]
    else:
        print "edgeStart must be 0 or 1"
        
    # Add splits to vertex list
    for v in sorted(edgeValues):
        pt0 = segs[edgeStart].PointAt(v)
        pt1 = segs[edgeStart+2].PointAt(1-v)
        faceVts.append((pt0,pt1))
        
    # Add last vertices
    faceVts.append((segs[edgeStart+1].From,segs[edgeStart+1].To))
    
    # Make new split quads
    newQuads = []
    for i in range(len(faceVts)-1):
        vts = (faceVts[i][0],faceVts[i][1],faceVts[i+1][1],faceVts[i+1][0],faceVts[i][0])
        plc = rc.Geometry.Polyline(vts)
        newQuads.append(plc)
        
    return newQuads



allQuads = [Rectangle]
params=[[0.3, 0.7], [0.2, 0.8], [0.4, 0.6], [0.5, 0.9]]
for i in range(Levels):
    for j in range(len(allQuads)):
        
        # Set random seed and generate splitting quad values
#        random.seed(i+j+Seed)
#        splitCount = random.randint(MinSplits,MaxSplits)
#        params = [random.uniform(MinParam,MaxParam) for k in range(splitCount)]

        newQuads = splitQuad(allQuads[j],params[j])
        allQuads.extend(newQuads)


SplitRectangles = allQuads