From 86cca7b52b224df9c3c1c0151b3424ad09ab1e57 Mon Sep 17 00:00:00 2001 From: lainsce Date: Sun, 5 Feb 2023 23:00:09 -0300 Subject: [PATCH] best we can get --- lib/Models/Application.vala | 12 ++++++------ lib/Utils/Color.vala | 29 +++++++++-------------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/lib/Models/Application.vala b/lib/Models/Application.vala index 68023b9e..54653d07 100644 --- a/lib/Models/Application.vala +++ b/lib/Models/Application.vala @@ -148,23 +148,23 @@ public class He.Application : Gtk.Application { // ___ ____ _ _ _ ____ ____ _ _ // |__] |__/ | |\/| |__| |__/ \_/ // | | \ | | | | | | \ | - Color.HCTColor primary = {hct_color.h, Math.fmax(48.0, hct_color.c), Desktop.ColorScheme.DARK == desktop.prefers_color_scheme ? 80.0 : 40.0, hct_color.a}; + Color.HCTColor primary = {hct_color.h, hct_color.c, Desktop.ColorScheme.DARK == desktop.prefers_color_scheme ? 80.0 : 40.0, hct_color.a}; var primary_hex = Color.hct_to_hex (primary); print ("Primary: %s\n".printf(primary_hex)); - Color.HCTColor on_primary = {hct_color.h, Math.fmax(48.0, hct_color.c), Desktop.ColorScheme.DARK == desktop.prefers_color_scheme ? 20.0 : 100.0, hct_color.a}; + Color.HCTColor on_primary = {hct_color.h, hct_color.c, Desktop.ColorScheme.DARK == desktop.prefers_color_scheme ? 20.0 : 100.0, hct_color.a}; var on_primary_hex = Color.hct_to_hex (on_primary); print ("On Primary: %s\n".printf(on_primary_hex)); - Color.HCTColor primary_container = {hct_color.h, Math.fmax(48.0, hct_color.c), Desktop.ColorScheme.DARK == desktop.prefers_color_scheme ? 30.0 : 90.0, hct_color.a}; + Color.HCTColor primary_container = {hct_color.h, hct_color.c, Desktop.ColorScheme.DARK == desktop.prefers_color_scheme ? 30.0 : 90.0, hct_color.a}; var primary_container_hex = Color.hct_to_hex (primary_container); print ("Primary Container: %s\n".printf(primary_container_hex)); - Color.HCTColor on_primary_container = {hct_color.h, Math.fmax(48.0, hct_color.c), Desktop.ColorScheme.DARK == desktop.prefers_color_scheme ? 90.0 : 10.0, hct_color.a}; + Color.HCTColor on_primary_container = {hct_color.h, hct_color.c, Desktop.ColorScheme.DARK == desktop.prefers_color_scheme ? 90.0 : 10.0, hct_color.a}; var on_primary_container_hex = Color.hct_to_hex (on_primary_container); print ("On Primary Container: %s\n".printf(on_primary_container_hex)); - Color.HCTColor inverse_accent = {hct_color.h, Math.fmax(48.0, hct_color.c), Desktop.ColorScheme.DARK == desktop.prefers_color_scheme ? 40.0 : 80.0, hct_color.a}; + Color.HCTColor inverse_accent = {hct_color.h, hct_color.c, Desktop.ColorScheme.DARK == desktop.prefers_color_scheme ? 40.0 : 80.0, hct_color.a}; var inverse_primary_hex = Color.hct_to_hex (inverse_accent); print ("Inverse Primary: %s\n".printf(inverse_primary_hex)); @@ -208,7 +208,7 @@ public class He.Application : Gtk.Application { // ___ ____ ____ ___ _ ____ ____ _ _ // | |___ |__/ | | |__| |__/ \_/ // | |___ | \ | | | | | \ | - var tertiary_hue = (hct_color.h + 60.0) % 360; // Fix tertiary hue going places it shouldn't. + var tertiary_hue = (hct_color.h + 60.0 >= 360) ? (hct_color.h + 60.0) - 360 : (hct_color.h + 60.0); // Fix tertiary hue going places it shouldn't. Color.HCTColor tertiary = {tertiary_hue, 24.0, Desktop.ColorScheme.DARK == desktop.prefers_color_scheme ? 80.0 : 40.0, hct_color.a}; var tertiary_hex = Color.hct_to_hex (tertiary); diff --git a/lib/Utils/Color.vala b/lib/Utils/Color.vala index b341b4d5..48e3fd8e 100644 --- a/lib/Utils/Color.vala +++ b/lib/Utils/Color.vala @@ -297,11 +297,7 @@ namespace He.Color { // hue var hr = Math.atan2(b, a); var atanDegrees = hr * 180.0 / Math.PI; - var h = atanDegrees < 0.0 - ? atanDegrees + 360.0 - : atanDegrees >= 360.0 - ? atanDegrees - 360.0 - : atanDegrees; + var h = atanDegrees < 0.0 ? atanDegrees + 360.0 : atanDegrees >= 360.0 ? atanDegrees - 360.0 : atanDegrees; // achromatic response to color var ac = p2 * 1.00030400455938070; @@ -313,16 +309,10 @@ namespace He.Color { var eh = 0.250 * (Math.cos(e_t * Math.PI / 180.0 + 2.0) + 3.8); var p1 = 50000.0 / 13.0 * eh * 1 * 1.00030400455938070; var t = p1 * Math.sqrt(a * a + b * b) / (u + 0.3050); - var alpha = Math.pow(t, 0.90) * - Math.pow( - 1.640 - Math.pow(0.290, 0.20), - 0.730); + var alpha = Math.pow(t, 0.90) * Math.pow(1.640 - Math.pow(0.290, 0.20), 0.730); + // CAM16 chroma - var C = (alpha * Math.sqrt(J / 100.0)); - - // Fixing bad props - C = (C * 5.59441826980).clamp(0, 150); - h = (h * 2.205267957220).clamp(0, 360); + var C = ((alpha * Math.pow(ac / 34.8662440467686640, 0.5 * 0.690 * 1.92721359549995790)) * 10).clamp(0, 150); print("\nCAM16 CHROMA VALUE:\n%f\n".printf(C)); print("\nCAM16 HUE VALUE:\n%f\n".printf(h)); @@ -351,7 +341,6 @@ namespace He.Color { // Now, we're not just gonna accept what comes to us via CAM16 and LCH, // because it generates bad HCT colors. So we're gonna test the color and // fix it for UI usage. - // Test color for bad props // A hue between 90.0 and 111.0 is body deject-colored so we can't use it. // A tone less than 70.0 is unsuitable for UI as it's too dark. @@ -359,16 +348,16 @@ namespace He.Color { bool toneNotPass = result.t < 70.0; if (hueNotPass || toneNotPass) { - print("\nTHIS IS YOUR HCT VALUES FIXED:\nH %f / C %f / T %f\n".printf(Math.fabs(result.h), Math.fabs(result.c), 70.0)); - return {Math.fabs(result.h), Math.fabs(result.c), 70.0, result.a}; // Fix color for UI, based on Psychology + print("\nTHIS IS YOUR HCT VALUES FIXED:\nH %f / C %f / T %f\n".printf(result.h, result.c, 70.0)); + return {result.h, result.c, 70.0, result.a}; // Fix color for UI, based on Psychology } else { - print("\nTHIS IS YOUR HCT VALUES THAT PASSED:\nH %f / C %f / T %f\n".printf(Math.fabs(result.h), Math.fabs(result.c), Math.fabs(result.t))); - return {Math.fabs(result.h), Math.fabs(result.c), Math.fabs(result.t), result.a}; + print("\nTHIS IS YOUR HCT VALUES THAT PASSED:\nH %f / C %f / T %f\n".printf(result.h, result.c, result.t)); + return {result.h, result.c, result.t, result.a}; } } public string hct_to_hex (HCTColor color) { // If color is mono - if (color.c < 0.0001 || color.t < 0.0001 || color.t > 99.9999) { + if (color.c < 1.0001 || color.t < 0.0001 || color.t > 99.9999) { double y = 100.0 * lab_invf((color.t + 16.0) / 116.0); double normalized = y / 100.0; double delinearized = 0.0;