html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>[Redacted Person] Konverter</title>
<style>
body {
font-family: Arial, sans-serif;
}
.container {
width: 80%;
margin: 40px auto;
text-align: center;
}
.color-preview {
width: 50px;
height: 50px;
border: 1px solid #ccc;
display: inline-block;
margin: 10px;
}
.slider-container {
margin-bottom: 20px;
}
.slider-container label {
display: block;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>Warna Konverter</h1>
<div class="color-preview" id="rgb-preview"></div>
<div class="color-preview" id="hct-preview"></div>
<div class="slider-container">
<label>RGB</label>
<input type="range" id="rgb-r" min="0" max="255" value="0">
<input type="range" id="rgb-g" min="0" max="255" value="0">
<input type="range" id="rgb-b" min="0" max="255" value="0">
<input type="text" id="rgb-input" value="#000000">
</div>
<div class="slider-container">
<label>HCT</label>
<input type="range" id="hct-h" min="0" max="360" value="0">
<input type="range" id="hct-c" min="0" max="100" value="0">
<input type="range" id="hct-t" min="0" max="100" value="0">
<input type="text" id="hct-input" value="H0 C0 T0">
</div>
</div>
<script>
const rgbR = document.getElementById('rgb-r');
const rgbG = document.getElementById('rgb-g');
const rgbB = document.getElementById('rgb-b');
const rgbInput = document.getElementById('rgb-input');
const rgbPreview = document.getElementById('rgb-preview');
const hctH = document.getElementById('hct-h');
const hctC = document.getElementById('hct-c');
const hctT = document.getElementById('hct-t');
const hctInput = document.getElementById('hct-input');
const hctPreview = document.getElementById('hct-preview');
rgbR.addEventListener('input', updateRgb);
rgbG.addEventListener('input', updateRgb);
rgbB.addEventListener('input', updateRgb);
hctH.addEventListener('input', updateHct);
hctC.addEventListener('input', updateHct);
hctT.addEventListener('input', updateHct);
function updateRgb() {
const r = parseInt(rgbR.value);
const g = parseInt(rgbG.value);
const b = parseInt(rgbB.value);
rgbInput.value = `#${r.[Redacted InternationalBankingAccountNumber].padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;
rgbPreview.style.backgroundColor = `rgb(${r}, ${g}, ${b})`;
// Konversi RGB ke HCT
const hct = rgbToHct(r, g, b);
hctH.value = hct.h;
hctC.value = hct.c;
hctT.value = hct.t;
hctInput.value = `H${hct.h} C${hct.c} T${hct.t}`;
hctPreview.style.backgroundColor = `hsl(${hct.h}, ${hct.c}%, ${hct.t}%)`;
}
function updateHct() {
const h = parseInt(hctH.value);
const c = parseInt(hctC.value);
const t = parseInt(hctT.value);
hctInput.value = `H${h} C${c} T${t}`;
hctPreview.style.backgroundColor = `hsl(${h}, ${c}%, ${t}%)`;
// Konversi HCT ke RGB
const rgb = hctToRgb(h, c, t);
rgbR.value = rgb.r;
rgbG.value = rgb.g;
rgbB.value = rgb.b;
rgbInput.value = `#${rgb.r.toString(16).padStart(2, '0')}${rgb.g.toString(16).padStart(2, '0')}${rgb.b.toString(16).padStart(2, '0')}`;
rgbPreview.style.backgroundColor = `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`;
}
// Fungsi konversi RGB ke HCT
function rgbToHct(r, g, b) {
r /= 255;
g /= 255;
b /= 255;
const max = Math.max(r, g, b);
const min = Math.min(r, g, b);
const delta = max - min;
let h;
if (delta === 0) {
h = 0;
} else if (max === r) {
h = (g - b) / delta;
} else if (max === g) {
h = 2 + (b - r) / delta;
} else {
h = 4 + (r - g) / delta;
}
h *= 60;
if (h < 0) {
h += 360;
}
const c = delta / (1 - Math.abs(max + min - 1));
const t = (max + min) / 2;
return { h, c: c * 100, t: t * 100 };
}
// Fungsi konversi HCT ke RGB
function hctToRgb(h, c, t) {
h /= 360;
c /= 100;
t /= 100;
const q = (t < 0.5) ? t * (1 + c) : t + c - t * c;
const p = 2 * t - q;
const r = Math.max(0, hueToRgb(p, q, h + 1/3));
const g = Math.max(0, hueToRgb(p, q, h));
const b = Math.max(0, hueToRgb(p, q, h - 1/3));
return { r: Math.round(r * 255), g: Math.round(g * 255), b: Math.round(b * 255) };
}
// Fungsi bantu untuk konversi HCT ke RGB
function hueToRgb(p, q, t) {
if (t < 0) {
t += 1;
} else if (t > 1) {
t -= 1;
}
if (t < 1/6) {
return p + (q - p) * 6 * t;
} else if (t < 1/2) {
return q;
} else if (t < 2/3) {
return p + (q - p) * (2/3 - t) * 6;
} else {
return p;
}
}
</script>
</body>
</html>