2012-01-18 30 views

回答

1

我不知道,但寫一個並不難。

在這裏你去,希望它會做什麼你就預計:

fn shuffle &arr = 
(
    local temp, swapIndex, counter = arr.count + 1 
    while counter > 1 do 
    (
     swapIndex = random 1 (counter -= 1) 
     temp = arr[counter] 
     arr[counter] = arr[swapIndex] 
     arr[swapIndex] = temp 
    ) 
    OK 
) 

fn incrementCounters &r &g &b step = 
(
    if (b += step) > 256 do 
    (
     b = 1 
     if (g += step) > 256 do 
     (
      g = 1 
      if (r += step) > 256 do r = 1 
     ) 
    ) 
) 

fn assignRandomWirecolor objs simple:true = 
(
    local stepCount = objs.count^(double 1/3) + 1 
    local step = 255./stepCount 
    local redArr = #(0) + #{1..255} 
    local greenArr = copy redArr #noMap 
    local blueArr = copy redArr #noMap 
    local r = local g = local b = 1 

    if simple then 
    (
     shuffle &redArr 
     shuffle &greenArr 
     shuffle &blueArr 
    ) 
    else shuffle &sel -- slower with many objects 

    for obj in objs do 
    (
     obj.wirecolor = [redArr[int(r)], greenArr[int(g)], blueArr[int(b)]] 
     incrementCounters &r &g &b step 
    ) 
) 


sel = selection as array 
clearSelection() 
assignRandomWirecolor sel --simple:false --> if simple is not so cool, try the other option 
select sel 

當然,這一切也取決於你想使用它的目的,這僅僅是因爲這樣的一般方法和它可能不適合那個確切的任務。如果是這樣的話,你可以提供更多的細節,我會做一些調整。

+0

非常感謝您的幫助。這正是我正在尋找的,現在它正在工作! ;) 謝了哥們! –

相關問題