html Copy code
<!DOCTYPE html>
<html>
<head>
<title>[Redacted Person] Konverter</title>
<style>
body {
font-family: Arial, sans-serif;
}
#container {
width: 500px;
margin: 40px auto;
text-align: center;
}
#preview {
width: 100px;
height: 100px;
border: 1px solid #ccc;
margin: 20px auto;
display: block;
}
.slider {
width: 300px;
margin: 20px auto;
}
</style>
</head>
<body>
<div id="container">
<h1>Waktu Konverter</h1>
<div id="preview"></div>
<div>
<label>RGB</label>
<input type="range" id="red" min="0" max="255" value="0" class="slider">
<input type="range" id="green" min="0" max="255" value="0" class="slider">
<input type="range" id="blue" min="0" max="255" value="0" class="slider">
<span id="rgb-value"></span>
</div>
<div>
<label>HEX</label>
<input type="text" id="hex" value="#000000">
</div>
<div>
<label>HCT</label>
<input type="range" id="hue" min="0" max="360" value="0" class="slider">
<input type="range" id="chroma" min="0" max="100" value="0" class="slider">
<input type="range" id="tone" min="0" max="100" value="0" class="slider">
<span id="hct-value"></span>
</div>
</div>
<script>
const preview = document.getElementById('preview');
const rgbValue = document.getElementById('rgb-value');
const hexInput = document.getElementById('hex');
const hctValue = document.getElementById('hct-value');
const redInput = document.getElementById('red');
const greenInput = document.getElementById('green');
const blueInput = document.getElementById('blue');
const hueInput = document.getElementById('hue');
const chromaInput = document.getElementById('chroma');
const toneInput = document.getElementById('tone');
function updatePreview() {
const r = parseInt(redInput.value);
const g = parseInt(greenInput.value);
const b = parseInt(blueInput.value);
preview.style.backgroundColor = `rgb(${r}, ${g}, ${b})`;
rgbValue.textContent = `RGB: ${r}, ${g}, ${b}`;
hexInput.value = rgbToHex(r, g, b);
const hct = rgbToHct(r, g, b);
hueInput.value = hct.hue;
chromaInput.value = hct.chroma;
toneInput.value = hct.tone;
hctValue.textContent = `HCT: ${hct.hue.toFixed(2)}, ${hct.chroma.toFixed(2)}, ${hct.tone.toFixed(2)}`;
}
function updateHct() {
const h = parseFloat(hueInput.value);
const c = parseFloat(chromaInput.value);
const t = parseFloat(toneInput.value);
const rgb = hctToRgb(h, c, t);
redInput.value = rgb.r;
greenInput.value = rgb.g;
blueInput.value = rgb.b;
updatePreview();
}
function rgbToHex(r, g, b) {
return `#${r.[Redacted InternationalBankingAccountNumber]{g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`;
}
function rgbToHct(r, g, b) {
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 / 255;
const t = (max + min) / 2 / 255 * 100;
return { hue: h, chroma: c, tone: t };
}
function hctToRgb(h, c, t) {
const max = t + c;
const min = t - c;
let r, g, b;
if (h < 60) {
r = max;
g = (h / 60) * (max - min) + min;
b = min;
} else if (h < 120) {
r = ((120 - h) / 60) * (max - min) + min;
g = max;
b = min;
} else if (h < 180) {
r = min;
g = max;
b = ((h - 120) / 60) * (max - min) + min;
} else if (h < 240) {
r = min;
g = ((240 - h) / 60) * (max - min) + min;
b = max;
} else if (h < 300) {
r = ((h - 240) / 60) * (max - min) + min;
g = min;
b = max;
} else {
r = max;
g = min;
b = ((360 - h) / 60) * (max - min) + min;
}
return {
r: Math.round(r * 255),
g: Math.round(g * 255),
b: Math.round(b * 255),
};
}
redInput.addEventListener('input', updatePreview);
greenInput.addEventListener('input', updatePreview);
blueInput.addEventListener('input', updatePreview);
hexInput.addEventListener('input', () => {
const hex = hexInput.value;
const rgb = hexToRgb(hex);
redInput.value = rgb.r;
greenInput.value = rgb.g;
blueInput.value = rgb.b;
updatePreview();
});
hueInput.addEventListener('input', updateHct);
chromaInput.addEventListener('input', updateHct);
toneInput.addEventListener('input', updateHct);
function hexToRgb(hex) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16),
} : null;
}
updatePreview();
</script>
</body>
</html>