-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
74 lines (59 loc) · 2.21 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hex to rgb and cmyk</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="fapposlogo">
<img src="logo.png" alt="Fappos logo">
<p class="text1">NØDEL ENTERPRISES</p>
<p class="text2">HEX TO RGB AND CMYK</p>
</div>
<div class="container">
<h1>Hex to rgb and cmyk</h1>
<input type="text" id="hexInput" placeholder="Enter HEX value (#FFFFFF)">
<button id="convertBtn">Convert</button>
<div id="result"></div>
</div>
</body>
<script>
const hexInput = document.getElementById('hexInput');
const convertButton = document.getElementById('convertBtn');
const result = document.getElementById('result');
const content = document.getElementById('content');
convertButton.addEventListener('click', () => {
const hex = hexInput.value;
const rgb = hexToRgb(hex);
const cmyk = rgbToCmyk(rgb);
result.innerHTML = `RGB: ${rgb.join(', ')}<br>CMYK: ${cmyk.join(', ')}`;
});
hexInput.addEventListener('input', () => {
const hex = hexInput.value;
if (hex.charAt(0) != '#') {
hexInput.value = "#" + hex;
} else if (hex.charAt(1) == '#') {
hexInput.value = hex.replace('#', '');
}
});
function hexToRgb(hex) {
const r = parseInt(hex.slice(1, 3), 16);
const g = parseInt(hex.slice(3, 5), 16);
const b = parseInt(hex.slice(5, 7), 16);
return [r, g, b];
}
function rgbToCmyk(rgb) {
let [r, g, b] = rgb.map(x => x / 255);
const k = 1 - Math.max(r, g, b);
if (k === 1) return [0, 0, 0, 1];
const c = (1 - r - k) / (1 - k);
const m = (1 - g - k) / (1 - k);
const y = (1 - b - k) / (1 - k);
return [c.toFixed(2), m.toFixed(2), y.toFixed(2), k.toFixed(2)];
}
</script>
<div class="footer">is this useful? idk maybe?</div>
<div class="footer"><p class="footertext"></p>© <script>document.write(new Date().getFullYear())</script>. All rights reserved: <a href="https://github.com/PhantomGamingdevelopment">https://github.com/PhantomGamingdevelopment ©</a></p></div>
</html>