jeudi 20 juin 2019

Filtering certain colors when using a random color generator that is seeded

Currently, I have a random color generated that I am pretty pleased with. The colors, for the most part, are appealing and the seeding data portion works as intended.

The problem is, I need to prevent the colors white and black from showing up. Actually, I would love to omit any shades of white, and any colors that are teetering on being black.

Here is my function:

    seededColorGenerator = (id, delivery_id) => {
        if (delivery_id) {
          return '#' + Math.floor((Math.abs(Math.sin(delivery_id) * 16777215)) % 16777215).toString(16)
        } else{
            return '#' + Math.floor((Math.abs(Math.sin(id) * 16777215)) % 16777215).toString(16)
        }
    }

I was thinking of explicitly picking out the color values and storing them into an array, then looping through them to check to see if said color was return and if so, call the algorithm again to get another random color. I am not sure that is the best practice for this.

Any ideas? I know there are plenty of conversations about random color generators, but I have yet to seen a good filtering process involved with them.




Aucun commentaire:

Enregistrer un commentaire