Friday, April 27, 2012

Techno Tulips on a curve


import rhinoscriptsyntax as rs
import math as m 


curve = rs.GetObject("curve")


domain = rs.CurveDomain(curve)
domain_length = domain[1]-domain[0]
divisions = 20
step = domain_length / divisions
pt_crv = []


for i in rs.frange(domain[0], domain[1], step):
    pt_crv.append(rs.AddPoint(rs.EvaluateCurve(curve, i)))


line = []
mid_pt = []
list_normal_pts = []
perp_line = []


attractor_pt1 = rs.GetPoint("select attractor")


for i in range(0,len(pt_crv)-1):
    p = []
    p = [pt_crv[i], pt_crv[i+1]]
    
    line.append(rs.AddPolyline(p))
    mid_pt.append(rs.CurveMidPoint(line[i]))
    scale = (rs.Distance(mid_pt[i], attractor_pt1))/2
    curve_length = rs.CurveLength(line[i])
    normal_vector = rs.CurveNormal(line[i])
    normal_vector = rs.VectorUnitize(normal_vector)
    normal_vector = rs.VectorScale(normal_vector, scale)
    
    normal_pt = rs.VectorAdd(mid_pt[i], normal_vector)
#    normal_pt = rs.VectorRotate(normal_pt, 180/scale ,pt_crv[i])
    normal_pt = rs.AddPoint(normal_pt)
    perp_line.append(rs.AddCurve([normal_pt, mid_pt[i]],1))
    
    list_normal_pts.append(normal_pt)


rs.DeleteObject(curve)


pt = []
main_ptlist = []
div = []


for i in range(0, len(perp_line)):
    divisions = 10
    circle = []
    val = 1
    for j in range(divisions+1):
        parameter = j/divisions
        val = (val + j)
        radius = rs.CurveLength(line[i])/(2*val)
        eval_param = rs.CurveParameter(perp_line[i],parameter)
        perp_frame = rs.CurvePerpFrame(perp_line[i], eval_param)
        circle.append(rs.AddCircle(perp_frame, radius))
    rs.AddLoftSrf(circle)
    for k in range(0,len(circle)):
        div_circle = rs.DivideCurve(circle[k], divisions/2)
    div.append(div_circle)
    rs.DeleteObjects(circle)

No comments:

Post a Comment