Untitled

By: a guest on May 6th, 2012  |  syntax: None  |  size: 1.22 KB  |  hits: 15  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. Give each object in scene a unique wirecolor?
2. fn shuffle &arr =
3. (
4.     local temp, swapIndex, counter = arr.count + 1
5.     while counter > 1 do
6.     (
7.         swapIndex = random 1 (counter -= 1)
8.         temp = arr[counter]
9.         arr[counter] = arr[swapIndex]
10.         arr[swapIndex] = temp
11.     )
12.     OK
13. )
14.
15. fn incrementCounters &r &g &b step =
16. (
17.     if (b += step) > 256 do
18.     (
19.         b = 1
20.         if (g += step) > 256 do
21.         (
22.             g = 1
23.             if (r += step) > 256 do r = 1
24.         )
25.     )
26. )
27.
28. fn assignRandomWirecolor objs simple:true =
29. (
30.     local stepCount = objs.count^(double 1/3) + 1
31.     local step = 255./stepCount
32.     local redArr = #(0) + #{1..255}
33.     local greenArr = copy redArr #noMap
34.     local blueArr = copy redArr #noMap
35.     local r = local g = local b = 1
36.
37.     if simple then
38.     (
39.         shuffle &redArr
40.         shuffle &greenArr
41.         shuffle &blueArr
42.     )
43.     else shuffle &sel -- slower with many objects
44.
45.     for obj in objs do
46.     (
47.         obj.wirecolor = [redArr[int(r)], greenArr[int(g)], blueArr[int(b)]]
48.         incrementCounters &r &g &b step
49.     )
50. )
51.
52.
53. sel = selection as array
54. clearSelection()
55. assignRandomWirecolor sel --simple:false --> if simple is not so cool, try the other option
56. select sel