HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/xampp/htdocs/cieclock/daycolor.txt
package com.example.pbnspectro.service;

import static com.example.pbnspectro.utls.ColorTool.cieXYZtoSRGB;
import static com.example.pbnspectro.utls.ColorTool.lab2xyz;

import android.graphics.Color;

import java.util.Calendar;

public class DayColor {
    /**
     * Get the current time and convert it to a color hex code
     * @return String[]  Returns an array of Strings containing the hexadecimal and integer representations of the RGB color values for the hour, minute, and second.
     *                 The first three elements are the hexadecimal values for the hour, minute, and second colors, respectively.
     *                 The last three elements are the integer values for the hour, minute, and second colors, respectively.
     */
    public static String[] getDayHex() {
        Calendar calendar = Calendar.getInstance();

        int cDay = calendar.get(Calendar.DAY_OF_YEAR);

        //System.out.println("cDay : " + cDay);

        double cDayi = (cDay / 365.00 )*360;

        //System.out.println("cDayi : " + cDayi);

        int chrome = 100;

        int Ld = getLd(cDayi);

        // Convert degrees to radians

        double degreed = Math.toRadians(cDayi);
        double ad, bd;



        ad = Math.cos(degreed) * chrome;
        bd = Math.sin(degreed) * chrome;

        //System.out.println("Day L,a,b : " + Ld +"," + ad + "," + bd);



        double xd = lab2xyz("x", Ld, ad, bd) * 0.01;
        double yd = lab2xyz("y", Ld, ad, bd) * 0.01;
        double zd = lab2xyz("z", Ld, ad, bd) * 0.01;

           //    System.out.println("xs : " + xd);
            //    System.out.println("ys : " + yd);
            //    System.out.println("zs : " + zd);

        int[] dRGB = cieXYZtoSRGB(xd, yd, zd);

        //System.out.println("sRGB : " + dRGB[0] + "," + dRGB[1] + "," + dRGB[2]);

        return new String[] {
                String.format("#%02x%02x%02x", dRGB[0], dRGB[1], dRGB[2]),
                String.valueOf(Color.rgb(dRGB[0], dRGB[1], dRGB[2]))
        };
    }

    private static int getLd(double cDayi) {
        int Ld = 55;
        if (cDayi > 53) {
            Ld =  60;
        }
        if (cDayi > 59) {
            Ld = 65;
        }
        if (cDayi > 65) {
            Ld = 70;
        }
        if (cDayi > 71) {
            Ld = 75;
        }
        if (cDayi > 77) {
            Ld = 80;
        }
        if (cDayi > 83) {
            Ld = 85;
            // chrome = 87;
        }
        if (cDayi > 89) {
            Ld = 93;
            // chrome = 90;
        }
        if (cDayi > 101) {
            Ld = 92;
        }
        if (cDayi > 107) {
            Ld = 90;
        }
        if (cDayi > 113) {
            Ld = 88;
        }
        if (cDayi > 119) {
            Ld = 85;
        }
        if (cDayi > 125) {
            Ld = 83;
        }
        if (cDayi > 131) {
            Ld = 80;
        }
        if (cDayi > 137) {
            Ld = 78;
        }
        if (cDayi > 143) {
            Ld = 75;
        }
        if (cDayi > 149) {
            Ld = 70;
            // chrome = 80;
        }
        if (cDayi > 155) {
            Ld = 68;
            // chrome = 80;
        }
        if (cDayi > 161) {
            Ld = 65;
            // chrome = 80;
        }
        if (cDayi > 167) {
            Ld = 63;
            // chrome = 80;
        }
        if (cDayi > 173) {
            Ld = 60;
            // chrome = 80;
        }
        if (cDayi > 179) {
            Ld = 58;
            // chrome = 80;
        }
        if (cDayi > 185) {
            Ld = 55;
            // chrome = 80;
        }
        return Ld;
    }

}