2009年6月1日星期一

scatter-wip

scatter SCATTER2

 

Option Explicit
'Script written by <insert name>
'Script copyrighted by <insert company name>
'Script version Thursday, April 09, 2009 11:00:35 AM

Call scatter()
Sub scatter()
    If isnull(rhino.GetDocumentData("scatter")) Then
        rhino.SetDocumentData "scatter","D1","45"
        rhino.SetDocumentData "scatter","D2","0.2"
        rhino.SetDocumentData "scatter","D3","30"   
    End If
    Dim d1,d2,d3
        d1=rhino.GetDocumentData("scatter","D1")
        d2=rhino.GetDocumentData("scatter","D2")
        d3=rhino.GetDocumentData("scatter","D3")

    Dim answers:answers=Rhino.PropertyListBox(array(_
        "randomRotateDeg(0=none)","randomScale(0=none)",_
        "ObjectMaintain(100=no del)"),array(d1,d2,d3),"Input number only:")
    If isnull(answers) Then Exit Sub
    rhino.SetDocumentData "scatter","D1",answers(0)
    rhino.SetDocumentData "scatter","D2",answers(1)
    rhino.SetDocumentData "scatter","D3",answers(2)
    Dim strPrep:strPrep= answers(0)& ","& answers(1)& "," & answers(2)
    Dim str2pt:str2pt=rhino.Str2Pt(strPrep)

    Dim anglerand:anglerand=str2pt(0) 'random rotate degree      
    Dim scalerand:scalerand=str2pt(1) 'random scale intervane factor range : 0.2 means from 0.8-1.2
    Dim biasRetaindeletion:biasRetaindeletion=str2pt(2)  ' range (0-100) keep 60 out of 100, delete randomly 40, 100 mean keep all

    Dim obj:obj=rhino.GetObject("copy source?",,True,True)
    If isnull(obj) Then Exit Sub
    Dim basept:basept=rhino.GetPoint("base point copy from?")
    If isnull(basept) Then Exit Sub
    Dim pts:pts=rhino.Getobjects("select copy-to points",1)
    If isnull(pts) Then Exit Sub
    rhino.EnableRedraw False   
    Dim pt,dup               
    For Each pt In pts
        dup=rhino.CopyObject (obj, basept, rhino.PointCoordinates(pt))
        rhino.RotateObject dup, rhino.PointCoordinates(pt),anglerand*2*(rnd-0.5)
        rhino.scaleObject dup, rhino.PointCoordinates(pt),_
            array((1+scalerand*2*(rnd-0.5)),(1+scalerand*2*(rnd-0.5)),1)
        If (rnd-biasRetaindeletion/100)>0 Then
            rhino.DeleteObject dup
        End If       
    Next   
    rhino.EnableRedraw True
End Sub

没有评论:

发表评论