ScriptSpot

Forum topic · General Scripting

Qsorting by Position

By JokerMartini · 2011-03-30

Description

I've got the sorting by position figured out. But then how do I sort them in relation of there pos compared to the "start object position" and then alter the objects wirecolor, in order based on there position?


positions = for i=1 to selection.count collect (selection[i].pos)

StartPos = $start.pos

fn fnCompareDist v1 v2 =
(
local d = (length v1)-(length v2)
case of
(
(d < 0.): -1
(d > 0.): 1
default: 0
)
)

qsort positions fnCompareDist

for p in positions do print p
for p in position do p.wirecolor = [i*25,i*50,(5-i)*50]

Comments (1)

It's easier than you think ;)

Garp · 2011-03-31


(
  local starter = $Point01

  fn dist_comp obj1 obj2 =
  distance starter obj1 - distance starter obj2

  local objs = selection as array
  qsort objs dist_comp
  print objs

  -- for shades of grey
  for i = 1 to (cnt = objs.count) do
    if cnt != 0 do
      objs[i].wirecolor = i * white / cnt

  -- for variation from yellow to blue
  for i = 1 to (cnt = objs.count) do
    if cnt != 0 do
    (
      local k = (i as float) / cnt
      objs[i].wirecolor = yellow * (1 - k) + blue * k
    )
)