File: C:/xampp/htdocs/cieclock/phpclock2.php
<?php
// Generate random RGB color values
$csec=date('s');
//$csec=3;
//echo "csec:".$csec;
$cseci=360-(($csec-15)*6);
$cseci0=360-(($csec-1-15)*6);
if ($cseci>360){
$cseci=$cseci-360;
}
if ($cseci0>360){
$cseci0=$cseci0-360;
}
//echo "cseci:".$cseci;
include 'de00.php';
include 'lab2xyz.php';
function RGBToHex($r, $g, $b) {
//String padding bug found and the solution put forth by Pete Williams (http://snipplr.com/users/PeteW)
$hex = "#";
$hex.= str_pad(dechex($r), 2, "0", STR_PAD_LEFT);
$hex.= str_pad(dechex($g), 2, "0", STR_PAD_LEFT);
$hex.= str_pad(dechex($b), 2, "0", STR_PAD_LEFT);
return $hex;
}
function cieXYZtoSRGB($X, $Y, $Z) {
// Normalize XYZ values
$X /= 1.0;
$Y /= 1.0;
$Z /= 1.0;
// Linear transformation from XYZ to RGB
$R = $X * 3.2406 + $Y * -1.5372 + $Z * -0.4986;
$G = $X * -0.9689 + $Y * 1.8758 + $Z * 0.0415;
$B = $X * 0.0557 + $Y * -0.2040 + $Z * 1.0570;
// Compensate for out-of-range RGB values
$R = ($R > 0.0031308) ? (1.055 * pow($R, (1 / 2.4)) - 0.055) : (12.92 * $R);
$G = ($G > 0.0031308) ? (1.055 * pow($G, (1 / 2.4)) - 0.055) : (12.92 * $G);
$B = ($B > 0.0031308) ? (1.055 * pow($B, (1 / 2.4)) - 0.055) : (12.92 * $B);
// Clamp RGB values to [0, 1] range
$R = max(0, min(1, $R));
$G = max(0, min(1, $G));
$B = max(0, min(1, $B));
// Scale to 8-bit sRGB values
$R = round($R * 255);
$G = round($G * 255);
$B = round($B * 255);
// Return sRGB color array
return [$R, $G, $B];
}
function cieXYZtoAdobeRGB($X, $Y, $Z) {
// Normalize XYZ values
$X /= 1.0;
$Y /= 1.0;
$Z /= 1.0;
// Transformation matrix from XYZ to Adobe RGB
$matrix = [
[ 2.04159, -0.56501, -0.34473],
[-0.96924, 1.87597, 0.04156],
[ 0.01344, -0.11836, 1.01517]
];
// Linear transformation from XYZ to Adobe RGB
$R = $matrix[0][0] * $X + $matrix[0][1] * $Y + $matrix[0][2] * $Z;
$G = $matrix[1][0] * $X + $matrix[1][1] * $Y + $matrix[1][2] * $Z;
$B = $matrix[2][0] * $X + $matrix[2][1] * $Y + $matrix[2][2] * $Z;
// Compensate for out-of-range RGB values
$R = ($R > 0.0031308) ? (1.055 * pow($R, (1 / 2.4)) - 0.055) : (12.92 * $R);
$G = ($G > 0.0031308) ? (1.055 * pow($G, (1 / 2.4)) - 0.055) : (12.92 * $G);
$B = ($B > 0.0031308) ? (1.055 * pow($B, (1 / 2.4)) - 0.055) : (12.92 * $B);
// Clamp RGB values to [0, 1] range
$R = max(0, min(1, $R));
$G = max(0, min(1, $G));
$B = max(0, min(1, $B));
// Scale to 8-bit Adobe RGB values
$R = round($R * 255);
$G = round($G * 255);
$B = round($B * 255);
// Return Adobe RGB color array
return [$R, $G, $B];
}
function cieXYZtoP3RGB($X, $Y, $Z) {
// Normalize XYZ values
$X /= 1.0;
$Y /= 1.0;
$Z /= 1.0;
// Transformation matrix from XYZ to Display P3 RGB
$matrix = [
[ 2.725394, -1.018662, -0.440185],
[-0.795168, 1.781022, 0.015715],
[ 0.041241, -0.126682, 1.272056]
];
// Linear transformation from XYZ to Display P3 RGB
$R = $matrix[0][0] * $X + $matrix[0][1] * $Y + $matrix[0][2] * $Z;
$G = $matrix[1][0] * $X + $matrix[1][1] * $Y + $matrix[1][2] * $Z;
$B = $matrix[2][0] * $X + $matrix[2][1] * $Y + $matrix[2][2] * $Z;
// Compensate for out-of-range RGB values
$R = ($R > 0.0031308) ? (1.055 * pow($R, (1 / 2.4)) - 0.055) : (12.92 * $R);
$G = ($G > 0.0031308) ? (1.055 * pow($G, (1 / 2.4)) - 0.055) : (12.92 * $G);
$B = ($B > 0.0031308) ? (1.055 * pow($B, (1 / 2.4)) - 0.055) : (12.92 * $B);
// Clamp RGB values to [0, 1] range
$R = max(0, min(1, $R));
$G = max(0, min(1, $G));
$B = max(0, min(1, $B));
// Scale to 8-bit Display P3 RGB values
$R = round($R * 255);
$G = round($G * 255);
$B = round($B * 255);
// Return Display P3 RGB color array
return [$R, $G, $B];
}
/////sec section////////
$chrome=100;
$L=55;
if ($cseci>47){
$L=55;
}
if ($cseci>53){
$L=60;
}
if ($cseci>59){
$L=65;
}
if ($cseci>65){
$L=70;
}
if ($cseci>71){
$L=75;
}
if ($cseci>77){
$L=80;
}
if ($cseci>83){
$L=85;
//$chrome=87;
}
if ($cseci>89){
$L=93;
//$chrome=90;
}
if ($cseci>95){
$L=93;
//$chrome=87;
}
if ($cseci>101){
$L=92;
}
if ($cseci>107){
$L=90;
}
if ($cseci>113){
$L=88;
}
if ($cseci>119){
$L=85;
}
if ($cseci>125){
$L=83;
}
if ($cseci>131){
$L=80;
}
if ($cseci>137){
$L=78;
}
if ($cseci>143){
$L=75;
}
if ($cseci>149){
$L=70;
//$chrome=80;
}
if ($cseci>155){
$L=68;
//$chrome=80;
}
if ($cseci>161){
$L=65;
//$chrome=80;
}
if ($cseci>167){
$L=63;
//$chrome=80;
}
if ($cseci>173){
$L=60;
//$chrome=80;
}
if ($cseci>179){
$L=58;
//$chrome=80;
}
if ($cseci>185){
$L=55;
//$chrome=80;
}
$degree=deg2rad($cseci);
$a=cos($degree)*$chrome;
$b=sin($degree)*$chrome;
$degree0=deg2rad($cseci0);
$a0=cos($degree0)*$chrome;
$b0=sin($degree0)*$chrome;
//echo "L a b:".$L."_".$a."_".$b;
$de00=round(de00($L,$a,$b,$L,$a0,$b0),2);
//echo "de00:".$de00;
$SXm=lab2xyz("x",$L,$a,$b);
$SYm=lab2xyz("y",$L,$a,$b);
$SZm=lab2xyz("z",$L,$a,$b);
//58.763535563754_74.164133933331_12.406893998571_
// Example usage
$cieXYZ = [$SXm/100, $SYm/100, $SZm/100]; // Example CIE XYZ values
$sRGB = cieXYZtoSRGB($cieXYZ[0], $cieXYZ[1], $cieXYZ[2]);
$sR = $sRGB[0];
$sG = $sRGB[1];
$sB = $sRGB[2];
$secHEX=RGBToHex($sR,$sG,$sB);
$aRGB = cieXYZtoAdobeRGB($cieXYZ[0], $cieXYZ[1], $cieXYZ[2]);
$aR = $aRGB[0];
$aG = $aRGB[1];
$aB = $aRGB[2];
$asecHEX=RGBToHex($aR,$aG,$aB);
$pRGB = cieXYZtoP3RGB($cieXYZ[0], $cieXYZ[1], $cieXYZ[2]);
$pR = $pRGB[0];
$pG = $pRGB[1];
$pB = $pRGB[2];
$psecHEX=RGBToHex($pR,$pG,$aB);
// Generate random RGB color values for the first clock
$clock1_color = sprintf('#%02x%02x%02x', $sR, $sG, $sB);
$hour_hand1_color = sprintf('#%02x%02x%02x', 255,0,0);
$minute_hand1_color = sprintf('#%02x%02x%02x', 0,255,0);
$second_hand1_color = sprintf('#%02x%02x%02x', 0,0,255);
///////////////////////////////////////////////////
/////////////////////////////////////////////////////////////2nd clock
$chrome=25;
$L=85;
if ($cseci>47){
$L=85;
}
if ($cseci>53){
//$L=60;
}
if ($cseci>59){
//$L=65;
}
if ($cseci>65){
//$L=70;
}
if ($cseci>71){
//$L=75;
}
if ($cseci>77){
//$L=80;
}
if ($cseci>83){
$L=85;
}
if ($cseci>89){
$L=93;
}
if ($cseci>95){
$L=93;
}
if ($cseci>101){
$L=92;
}
if ($cseci>107){
$L=90;
}
if ($cseci>113){
$L=88;
}
if ($cseci>119){
$L=85;
}
if ($cseci>125){
//$L=83;
}
if ($cseci>131){
//$L=80;
}
if ($cseci>137){
//$L=78;
}
if ($cseci>143){
//$L=75;
}
if ($cseci>149){
//$L=70;
//$chrome=80;
}
if ($cseci>155){
//$L=68;
//$chrome=80;
}
if ($cseci>161){
///$L=65;
//$chrome=80;
}
if ($cseci>167){
//$L=63;
//$chrome=80;
}
if ($cseci>173){
//$L=60;
//$chrome=80;
}
if ($cseci>179){
$L=80;
//$chrome=80;
}
if ($cseci>269){
$L=85;
//$chrome=80;
}
$degree=deg2rad($cseci);
$a=cos($degree)*$chrome;
$b=sin($degree)*$chrome;
$degree0=deg2rad($cseci0);
$a0=cos($degree0)*$chrome;
$b0=sin($degree0)*$chrome;
//echo "L a b:".$L."_".$a."_".$b;
$de00=round(de00($L,$a,$b,$L,$a0,$b0),2);
//echo "de00:".$de00;
$SXm=lab2xyz("x",$L,$a,$b);
$SYm=lab2xyz("y",$L,$a,$b);
$SZm=lab2xyz("z",$L,$a,$b);
//58.763535563754_74.164133933331_12.406893998571_
// Example usage
$cieXYZ = [$SXm/100, $SYm/100, $SZm/100]; // Example CIE XYZ values
$sRGB = cieXYZtoSRGB($cieXYZ[0], $cieXYZ[1], $cieXYZ[2]);
$sR = $sRGB[0];
$sG = $sRGB[1];
$sB = $sRGB[2];
$secHEX=RGBToHex($sR,$sG,$sB);
$aRGB = cieXYZtoAdobeRGB($cieXYZ[0], $cieXYZ[1], $cieXYZ[2]);
$aR = $aRGB[0];
$aG = $aRGB[1];
$aB = $aRGB[2];
$asecHEX=RGBToHex($aR,$aG,$aB);
$pRGB = cieXYZtoP3RGB($cieXYZ[0], $cieXYZ[1], $cieXYZ[2]);
$pR = $pRGB[0];
$pG = $pRGB[1];
$pB = $pRGB[2];
$psecHEX=RGBToHex($pR,$pG,$aB);
// Generate random RGB color values for the second clock
$clock2_color = sprintf('#%02x%02x%02x', $sR, $sG, $sB);
$hour_hand2_color = sprintf('#%02x%02x%02x', 255,0,0);
$minute_hand2_color = sprintf('#%02x%02x%02x', 0,255,0);
$second_hand2_color = sprintf('#%02x%02x%02x', 0,0,255);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Two Analog Clocks</title>
<style>
table {
margin: 0 auto; /* Center the table horizontally */
}
.clock {
position: relative;
width: 200px;
height: 200px;
border: 2px solid #000;
border-radius: 50%;
}
.hour-hand, .minute-hand, .second-hand {
position: absolute;
background-color: black; /* Default color for clock hands */
}
/* Style for the first clock */
.clock1 {
background-color: <?php echo $clock1_color; ?>; /* Use PHP variable for clock color */
}
.clock1 .hour-hand {
width: 4px;
height: 50px;
top: calc(50% - 50px);
left: calc(50% - 2px);
transform-origin: bottom center;
background-color: <?php echo $hour_hand1_color; ?>; /* Use PHP variable for hour hand color */
}
.clock1 .minute-hand {
width: 2px;
height: 70px;
top: calc(50% - 70px);
left: calc(50% - 1px);
transform-origin: bottom center;
background-color: <?php echo $minute_hand1_color; ?>; /* Use PHP variable for minute hand color */
}
.clock1 .second-hand {
width: 1px;
height: 80px;
top: calc(50% - 80px);
left: calc(50% - 0.5px);
transform-origin: bottom center;
background-color: <?php echo $second_hand1_color; ?>; /* Use PHP variable for second hand color */
}
/* Style for the second clock */
.clock2 {
background-color: <?php echo $clock2_color; ?>; /* Use PHP variable for clock color */
}
.clock2 .hour-hand {
width: 4px;
height: 50px;
top: calc(50% - 50px);
left: calc(50% - 2px);
transform-origin: bottom center;
background-color: <?php echo $hour_hand2_color; ?>; /* Use PHP variable for hour hand color */
}
.clock2 .minute-hand {
width: 2px;
height: 70px;
top: calc(50% - 70px);
left: calc(50% - 1px);
transform-origin: bottom center;
background-color: <?php echo $minute_hand2_color; ?>; /* Use PHP variable for minute hand color */
}
.clock2 .second-hand {
width: 1px;
height: 80px;
top: calc(50% - 80px);
left: calc(50% - 0.5px);
transform-origin: bottom center;
background-color: <?php echo $second_hand2_color; ?>; /* Use PHP variable for second hand color */
}
</style>
</head>
<body>
<table>
<tr>
<td>
<div class="clock clock1">
<div class="hour-hand" id="hour-hand1"></div>
<div class="minute-hand" id="minute-hand1"></div>
<div class="second-hand" id="second-hand1"></div>
</div>
</td>
</tr>
<tr>
<td>
<div class="clock clock2">
<div class="hour-hand" id="hour-hand2"></div>
<div class="minute-hand" id="minute-hand2"></div>
<div class="second-hand" id="second-hand2"></div>
</div>
</td>
</tr>
</table>
<script>
function updateClock() {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
// Calculate rotation angles for each hand
var hourDeg1 = (hours % 12) * 30 + minutes / 2;
var minuteDeg1 = minutes * 6;
var secondDeg1 = seconds * 6;
var hourDeg2 = (hours % 12) * 30 + minutes / 2;
var minuteDeg2 = minutes * 6;
var secondDeg2 = seconds * 6;
// Update the rotation of each clock hand
document.getElementById('hour-hand1').style.transform = 'rotate(' + hourDeg1 + 'deg)';
document.getElementById('minute-hand1').style.transform = 'rotate(' + minuteDeg1 + 'deg)';
document.getElementById('second-hand1').style.transform = 'rotate(' + secondDeg1 + 'deg)';
document.getElementById('hour-hand2').style.transform = 'rotate(' + hourDeg2 + 'deg)';
document.getElementById('minute-hand2').style.transform = 'rotate(' + minuteDeg2 + 'deg)';
document.getElementById('second-hand2').style.transform = 'rotate(' + secondDeg2 + 'deg)';
setTimeout(updateClock, 1000); // Update every second
}
updateClock(); // Initial call to start the clock
</script>
</body>
</html>