Login - Create Account
Bookmark and Share

Sorting a Gradient using table.sort(t,comp)

Login or Register to post new topics or replies
xirja
xirja.com

Posts: 198
Filters: 1
Trying to sort a gradient based on perceptual brightness and then selecting the darkest color.

The script included in the attachment does not give the expected result. Getting values from
the associative table doesn't seem to be working properly, as dark blue should be the result.

Most likely there is a problem with getting values from the table after the sort. a nil issue?

Any other ideas on how to use perceptual(Lab L) values to sort/reorder colors?

???

GradientTestDark.ffxml
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1344
Filters: 38
try this replacement:
Code
function get_sample(x, y)
   local c = {}
   for i = 1, 4 do
      c[i] = {}
      c[i].li = get_sample_grayscale(x, y, _G["I"..i])
      c[i].r,c[i].g,c[i].b,c[i].a = get_sample_map(x, y, _G["C"..i])
   end;
   local function compare(a,b)
      return (a.li < b.li)
   end
   table.sort(c, compare)
   return c[1].r, c[1].g, c[1].b, c[1].a
end;
Njyldgarkn sample cache!
  Details E-Mail
xirja
xirja.com

Posts: 198
Filters: 1
Oh great, that _G["I"..i ] for multiple inputs! Thank you! It works, and much more elegantly than my baseball glove hands approach. smile:D

If there was a more general case of sorting a spectrum using OUTPUT_WIDTH though?

SpectrumTestCode.ffxml
  Details E-Mail

Join Our Community!

Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!

15,374 Registered Users
+7 new last day!

112,620 Posts
+101 new in 7 days!

10,102 Topics
+16 new in 7 days!

Online Users Last 15 minutes:

17 unregistered users.

Recent Wiki Edits:

Follow filterforge on Twitter