Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sort HSL colors
Forum Updated to NodeBB v4.3 + New Features

Sort HSL colors

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 692 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thesupershinobi
    wrote on last edited by
    #1

    Hello, I would like some help to write an algorithm to sort HSL colors from an 512 colors.

    I understood that I had to use the hue, saturation and lightness values to order the colors, but I can not get a gradient.

    Do you have an example or an indication to give me?

    Thanks in advance.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MajidKamali
      wrote on last edited by
      #2

      use std::sort with a custom Comparer that gives hsl as input
      https://en.cppreference.com/w/cpp/algorithm/sort

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thesupershinobi
        wrote on last edited by thesupershinobi
        #3

        Hello thanks for your reply.

        I alreay use this function for sort the QVector<QColor> but the result is not very good.

        The best result is this comparaison :

        int compare(const QColor &a, const QColor &b)
        {
            return a.rgb() < b.rgb();
        }
        

        I wrote this code, but the colors the sort does not give a result does not give a gradient.

        int compare(const QColor &a, const QColor &b)
        {
            if(a.hue() == b.hue())
            {
                if(a.saturation() == b.saturation())
                {
                    return (a.lightness() <= b.lightness());
                }
               return (a.saturation() <= b.saturation());
            }
            return (a.hue() < b.hue());
        }
        
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved