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 TimesColorService { /** * 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[] getTimeHex() { Calendar calendar = Calendar.getInstance(); int cHour = calendar.get(Calendar.HOUR); int cMin = calendar.get(Calendar.MINUTE); int cSec = calendar.get(Calendar.SECOND); // Calculate the angle of the hour, minute, and second hands double chouri = 360 - ((cHour - 3) * 30); if (chouri > 360) { chouri = chouri - 360; } double cmini = 360 - ((cMin - 15) * 6); if (cmini > 360) { cmini = cmini - 360; } double cseci = 360 - ((cSec - 15) * 6); if (cseci > 360) { cseci = cseci - 360; } int chrome = 100; int Lh = getLh(chouri); int Lm = getLm(cmini); int Ls = getLs(cseci); // Convert degrees to radians double degreeH = Math.toRadians(chouri); double degreeM = Math.toRadians(cmini); double degreeS = Math.toRadians(cseci); double ah, bh, am, bm, as, bs; // Calculate 'a' and 'b' ah = Math.cos(degreeH) * chrome; bh = Math.sin(degreeH) * chrome; // Calculate 'a' and 'b' am = Math.cos(degreeM) * chrome; bm = Math.sin(degreeM) * chrome; // Calculate 'a' and 'b' as = Math.cos(degreeS) * chrome; bs = Math.sin(degreeS) * chrome; //System.out.println("Hour L,a,b : " + Lh +"," + ah + "," + bh); //System.out.println("min L,a,b : " + Lm +"," + am + "," + bm); // System.out.println("sec L,a,b : " + Ls +"," + as + "," + bs); double xh = lab2xyz("x", Lh, ah, bh) * 0.01; double yh = lab2xyz("y", Lh, ah, bh) * 0.01; double zh = lab2xyz("z", Lh, ah, bh) * 0.01; /* System.out.println("xh : " + xh); System.out.println("yh : " + yh); System.out.println("zh : " + zh); */ double xm = lab2xyz("x", Lm, am, bm) * 0.01; double ym = lab2xyz("y", Lm, am, bm) * 0.01; double zm = lab2xyz("z", Lm, am, bm) * 0.01; double xs = lab2xyz("x", Ls, as, bs) * 0.01; double ys = lab2xyz("y", Ls, as, bs) * 0.01; double zs = lab2xyz("z", Ls, as, bs) * 0.01; /* System.out.println("xs : " + xs); System.out.println("ys : " + ys); System.out.println("zs : " + zs);*/ int[] hRGB = cieXYZtoSRGB(xh, yh, zh); int[] mRGB = cieXYZtoSRGB(xm, ym, zm); int[] sRGB = cieXYZtoSRGB(xs, ys, zs); //System.out.println("sRGB : " + sRGB[0] + "," + sRGB[1] + "," + sRGB[2]); return new String[] { String.format("#%02x%02x%02x", hRGB[0], hRGB[1], hRGB[2]), String.format("#%02x%02x%02x", mRGB[0], mRGB[1], mRGB[2]), String.format("#%02x%02x%02x", sRGB[0], sRGB[1], sRGB[2]), String.valueOf(Color.rgb(hRGB[0], hRGB[1], hRGB[2])), String.valueOf(Color.rgb(mRGB[0], mRGB[1], mRGB[2])), String.valueOf(Color.rgb(sRGB[0], sRGB[1], sRGB[2])) }; } private static int getLs(double cseci) { int Ls = 55; if (cseci > 53) { Ls = 60; } if (cseci > 59) { Ls = 65; } if (cseci > 65) { Ls = 70; } if (cseci > 71) { Ls = 75; } if (cseci > 77) { Ls = 80; } if (cseci > 83) { Ls = 85; // chrome = 87; } if (cseci > 89) { Ls = 93; // chrome = 90; } if (cseci > 101) { Ls = 92; } if (cseci > 107) { Ls = 90; } if (cseci > 113) { Ls = 88; } if (cseci > 119) { Ls = 85; } if (cseci > 125) { Ls = 83; } if (cseci > 131) { Ls = 80; } if (cseci > 137) { Ls = 78; } if (cseci > 143) { Ls = 75; } if (cseci > 149) { Ls = 70; // chrome = 80; } if (cseci > 155) { Ls = 68; // chrome = 80; } if (cseci > 161) { Ls = 65; // chrome = 80; } if (cseci > 167) { Ls = 63; // chrome = 80; } if (cseci > 173) { Ls = 60; // chrome = 80; } if (cseci > 179) { Ls = 58; // chrome = 80; } if (cseci > 185) { Ls = 55; // chrome = 80; } return Ls; } private static int getLm(double cmini) { int Lm = 55; if (cmini > 53) { Lm = 60; } if (cmini > 59) { Lm = 65; } if (cmini > 65) { Lm = 70; } if (cmini > 71) { Lm = 75; } if (cmini > 77) { Lm = 80; } if (cmini > 83) { Lm = 85; // chrome = 87; } if (cmini > 89) { Lm = 93; // chrome = 90; } if (cmini > 101) { Lm = 92; } if (cmini > 107) { Lm = 90; } if (cmini > 113) { Lm = 88; } if (cmini > 119) { Lm = 85; } if (cmini > 125) { Lm = 83; } if (cmini > 131) { Lm = 80; } if (cmini > 137) { Lm = 78; } if (cmini > 143) { Lm = 75; } if (cmini > 149) { Lm = 70; // chrome = 80; } if (cmini > 155) { Lm = 68; // chrome = 80; } if (cmini > 161) { Lm = 65; // chrome = 80; } if (cmini > 167) { Lm = 63; // chrome = 80; } if (cmini > 173) { Lm = 60; // chrome = 80; } if (cmini > 179) { Lm = 58; // chrome = 80; } if (cmini > 185) { Lm = 55; // chrome = 80; } return Lm; } private static int getLh(double chouri) { int Lh = 55; if (chouri > 53) { Lh = 60; } if (chouri > 59) { Lh = 65; } if (chouri > 65) { Lh = 70; } if (chouri > 71) { Lh = 75; } if (chouri > 77) { Lh = 80; } if (chouri > 83) { Lh = 85; // chrome = 87; } if (chouri > 89) { Lh = 93; // chrome = 90; } if (chouri > 101) { Lh = 92; } if (chouri > 107) { Lh = 90; } if (chouri > 113) { Lh = 88; } if (chouri > 119) { Lh = 85; } if (chouri > 125) { Lh = 83; } if (chouri > 131) { Lh = 80; } if (chouri > 137) { Lh = 78; } if (chouri > 143) { Lh = 75; } if (chouri > 149) { Lh = 70; // chrome = 80; } if (chouri > 155) { Lh = 68; // chrome = 80; } if (chouri > 161) { Lh = 65; // chrome = 80; } if (chouri > 167) { Lh = 63; // chrome = 80; } if (chouri > 173) { Lh = 60; // chrome = 80; } if (chouri > 179) { Lh = 58; // chrome = 80; } if (chouri > 185) { Lh = 55; // chrome = 80; } return Lh; } }