Math Problem: set up matrix math to create hex codes programmatically.

stares at error messages

Readn' Tea Leaves
kiwifarms.net
Joined
Dec 7, 2020
In stages
  1. Use provided data set to create a matrix. --gb and --fg are inputs. All other values are derivative outputs. Create matrix that generalises the relationships in the data set.
  2. Create a function that produces all --$varname values as a dictionary-map-JSON with the $varname as the key and the derived colour as the value.
  3. Post source code on kiwifarms in this thread.
You may have questions.
The answer is yes.

Data set is attached.
 

Attachments

Why exactly do you think "Ayu", "Coal", and so on are generalizable functions? If these are forum themes, they were probably just colors manually picked because someone thought they looked good together.
 
  • Winner
Reactions: Knight of the Rope
Create a function that produces all --$varname values as a dictionary-map-JSON with the $varname as the key and the derived colour as the value.
This is why people hate undergrads, even the mathematics ones.

Sure, you've gotten through your linear transformations lectures and you're feeling pretty stoked, right? "Wow, you can represent an awful lot of things as the mapping between vector spaces! I wonder if that's useful for autistic shit like ricing/theming?" And then you go full retard with it: "Ah, of course. Just map a 2x1 (or a 6x1, realistically, since you probably want to represent the hex colors as triples in [0,1] intervals to keep thing nice and continuous) vector to a 26x1 (or again, 78x1 for [0,1] continuity) vector that tells you what the colors should be. And all of my lectures tell me that such a matrix exists and ways to find it. Of course, I'm a genius!"

You never stop to actually think this shit through without your textbook. Here's the question you've missed in your autism: if the only inputs are the background and foreground color, why would that be sufficient to determine an entire theme? Can you think of any case where someone's created themes with the same background and foreground colors, but with different decoration colors that still work well together? Then congratulations, you've just realized the futility of your 'generalization' exercise. No fancy math needed, just non-faggotry.

tl;dr: git gud.
 
JavaScript -- the only programming language less accurate then Wikipedia.

Presumably used in software that exists​

JavaScript:
function hsl_to_rgb(hsl)
{
    let [h, s, l] = hsl;
    let r, g, b;
    if (s == 0.0) {
        r = g = b = l; // achromatic
    } else {
        function hue2rgb(p, q, t)
    {
            if (t < 0) t += 1;
            if (t > 1) t -= 1;
            if (t < 1/6) return p + (q - p) * 6 * t;
            if (t < 1/2) return q;
            if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
            return p;
        };
        let q = l < 0.5 ? l * (1 + s) : l + s - l * s;
        let p = 2 * l - q;
        r = hue2rgb(p, q, h + 1/3);
        g = hue2rgb(p, q, h);
        b = hue2rgb(p, q, h - 1/3);
    }
    return [r * 255, g* 255, b * 255];
}

Copying Wiki​

JavaScript:
function hsl_to_rgb(hsl)
{
    let [h, s, l] = hsl;
    h = H.clamp(h);
    // continue for each
    let c = (1 - Math.abs(2 * l - 1)) * s;
    let hprime = h / 60;
    let x = c * (1 - Math.abs(hprime % 2 - 1));
    let z;
    if (!hprime) {
    z = [0, 0, 0];
    } else if (0 <= hprime && hprime < 1) {
    z = [c, x, 0];
    } else if (1 <= hprime && hprime < 2) {
    z = [x, c, 0];
    } else if (2 <= hprime && hprime < 3) {
    z = [0, c, x];
    } else if (3 <= hprime && hprime < 4) {
    z = [0, x, c];
    } else if (4 <= hprime && hprime < 5) {
    z = [x, 0, c];
    } else if (5 <= hprime && hprime < 6) {
    z = [c, 0, x];
    } else {
    throw "Impossible error in hsl_to_rgb";
    }
    let m = l - (c / 2);
    return z.map(e => Math.round(255 * (e + m)));
}
Guess which version works and which does not.
 
Why exactly do you think "Ayu", "Coal", and so on are generalizable functions? If these are forum themes, they were probably just colors manually picked because someone thought they looked good together.
They are themes. I want to put in just the background (bg) and foreground (fg) and get back all the other values. The source data is artistically selected, but it still abides an artistic principle, a principle that can be observed mathematically.
JSON:
  {
    '--bg': [ 226, 0.23, 0.11 ],
    '--fg': [ 180, 0.18, 0.78 ],
    '--sidebar-bg': [ 180, 0.22, 0.2 ],
    '--sidebar-fg': [ 180, 0.21, 0.82 ],
    '--sidebar-non-existant': [ 180, 0.18, 0.38 ],
    '--sidebar-active': [ 180, 0.58, 0.4 ],
    '--sidebar-spacer': [ 180, 0.27, 0.24 ],
    '--scrollbar': [ 180, 0.21, 0.82 ],
    '--icons': [ 180, 0.05, 0.48 ],
    '--icons-hover': [ 180, 0.17, 0.76 ],
    '--links': [ 180, 0.58, 0.4 ],
    '--inline-code-color': [ 140, 0.03, 0.78 ],
    '--theme-popup-bg': [ 180, 0.23, 0.11 ],
    '--theme-popup-border': [ 180, 0.05, 0.48 ],
    '--theme-hover': [ 180, 0.23, 0.2 ],
    '--quote-bg': [ 226, 0.15, 0.17 ],
    '--quote-border': [ 226, 0.15, 0.22 ],
    '--table-border-color': [ 226, 0.23, 0.16 ],
    '--table-header-bg': [ 226, 0.23, 0.31 ],
    '--table-alternate-bg': [ 226, 0.23, 0.14 ],
    '--searchbar-border-color': [ 0, 0, 0.67 ],
    '--searchbar-bg': [ 180, 0.17, 0.73 ],
    '--searchbar-fg': [ 0, 0, 0 ],
    '--searchbar-shadow-color': [ 0, 0, 0.67 ],
    '--searchresults-header-fg': [ 180, 0.09, 0.41 ],
    '--searchresults-border-color': [ 180, 0.06, 0.38 ],
    '--searchresults-li-bg': [ 180, 0.14, 0.16 ],
    '--search-mark-bg': [ 180, 0.81, 0.8 ]
  },
The above colour values are HSL scale in array objects.

If this were the only theme in the source data, it could be trivial to create a function that replaces the H and keeps the S and L values the same. When all the themes are examined, the H and L values also very with the different themes. There needs to be a more complicated function to find the relationship between bg and fg that can be generalised to all themes.
 
  • Dumb
Reactions: Knight of the Rope
  • Like
Reactions: Knight of the Rope
Anyway, why do you even need two colors? Windows 10 can pick the mathematically optimal theme based on only one color - try it and see.
  1. Maybe it would be a neat feature to let users pick what they want for text and background and then have all the other colours that are for special UI stuff like highlight and menu colour chosen automatically.
  2. The text and background colours look lousily related to the other colours in the themes from the data set. eg.
  3. I have incomplete themes that only have the text and background colours and don't want to be artistic when choosing the other colours to complete the themes.
  4. It seemed like a neat reason to implement matrix division algorithm in JavaScript (yuck).
  5. Labor in the enemy of capital, so an action that takes human skill and talent per instance of production can never be profitable.
  6. I could not think of a different solution to the problem.
 
Last edited:
Back