Notifications
Clear all

[Closed] Sort by Color

Do you have any idea of better “sort by color” method:


fn sortbycolor n1 n2 = 
(
   c1 = n1.wirecolor
   c2 = n2.wirecolor
   
   if (c1.h < c2.h) then -1 else if (c1.h > c2.h) then 1 else 
   if (c1.v > c2.v) then -1 else if (c1.v < c2.v) then 1 else 0  
)


with redraw off
(
   delete objects
   seed 1
   bb = for k=1 to 100 collect (box wirecolor:(random black white)) 
   qsort bb sortbycolor


   for k=1 to bb.count do 
   (
      bb[k].pos = point3 ((k-1) * 30) 0 0 
   )
)   

it could be better for sure

1 Reply

Here’s a nice article about color sorting:
https://www.alanzucconi.com/2015/09/30/colour-sorting/