-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.html
220 lines (211 loc) · 8.5 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Colour Difference</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style media="screen">
html,
body {
padding: 0;
margin: 0;
}
h1 {
text-align: center;
}
.flex-column {
display: flex;
flex-direction: column;
}
.flex-column > div {
width: 100%;
}
.flex-column > div > button {
width: 100%;
font-size: 30px;
}
.min-height-200 {
min-height: 200px;
}
.min-height-80 {
min-height: 80px;
}
#log {
display: flex;
flex-direction: column;
}
#log > ol > li.c1 {
color: black;
}
#log > ol > li.c2 {
color: orange;
}
#log > ol > li.result {
color: darkgreen;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<script src="Colour.js" charset="utf-8"></script>
</head>
<body>
<header>
<h1>Colour Difference</h1>
</header>
<main>
<section class="flex-column">
<div>
Kindly Find below table for your reference
<table>
<thead>
<tr>
<th>Delta E Value</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><= 1.0</td>
<td>Not perceptible by human eyes.</td>
</tr>
<tr>
<td>1 - 2</td>
<td>Perceptible through close observation.</td>
</tr>
<tr>
<td>2 - 10</td>
<td>Perceptible at a glance.</td>
</tr>
<tr>
<td>11 - 49</td>
<td>Colors are more similar than opposite.</td>
</tr>
<tr>
<td>100</td>
<td>Colors are exact opposite.</td>
</tr>
</tbody>
</table>
</div>
<div>
<label for="first-colour">First Colour</label>
<input type="color" id="first-colour" name="first-colour" placeholder="first colour" value="#FFFFFF"/>
</div>
<div>
<label for="second-colour">Second Colour</label>
<input type="color" id="second-colour" name="second-colour" placeholder="second colour" value="#FFFFFF"/>
</div>
<div>
<button type="button" id="Compare" name="Compare">Compare</button>
</div>
<!-- get darker colour -->
<div>
<label for="get-darker-colour">Get Darker colour of this colour</label>
<input type="color" id="get-darker-colour" name="colour" placeholder="colour" value="#000000"/>
</div>
<div>
<button type="button" id="getDarkerColour" name="getDarkerColour">Get Darker Colour</button>
</div>
<div>
<button type="button" id="getBrighterColour" name="getBrighterColour">Get Brighter Colour</button>
</div>
</section>
<section class="flex-column">
<div id="fcolour" class="first-colour min-height-80">
</div>
<div id="scolour" class="second-colour min-height-80">
</div>
</section>
<section id="log">
<ol></ol>
</section>
</main>
<footer>
</footer>
<script type="text/javascript">
'use strict';
// Values
let FirstColourInHEX, SecondColourInHEX;
// Elements
let FirstColourElement, SecondColourElement;
let FirstColourShowElement, SecondColourShowElement;
let logElement;
let compareButton;
// new feature
let getDarkerColourButton;
let getBrighterColourButton;
let getDarkerColourColor;
window.onload = function() {
init();
compareFeature();
getDarkerColourFeature();
getBrighterColourFeature();
};
function init() {
// init elements
FirstColourElement = document.getElementById("first-colour");
FirstColourShowElement = document.getElementById("fcolour");
SecondColourElement = document.getElementById("second-colour");
SecondColourShowElement = document.getElementById("scolour");
getDarkerColourColor = document.getElementById("get-darker-colour");
// init compare button
compareButton = document.getElementById("Compare");
// init darket colour button
getDarkerColourButton = document.getElementById("getDarkerColour");
// init brighter colour button
getBrighterColourButton = document.getElementById("getBrighterColour");
// log element
logElement = document.getElementById("log").children[0];
}
function getDarkerColourFeature() {
getDarkerColourButton.addEventListener("click", function() {
FirstColourShowElement.style.backgroundColor = getDarkerColourColor.value;
let [R1, G1, B1, A1] = Colour.hex2rgba(getDarkerColourColor.value);
let [R2, G2, B2, A2] = Colour.getDarkerColour(R1, G1, B1, A1);
SecondColourShowElement.style.backgroundColor = `rgba(${R2}, ${G2}, ${B2}, ${A2})`;
});
}
function getBrighterColourFeature() {
getBrighterColourButton.addEventListener("click", function(){
FirstColourShowElement.style.backgroundColor = getDarkerColourColor.value;
let [R1, G1, B1, A1] = Colour.hex2rgba(getDarkerColourColor.value);
let [R2, G2, B2, A2] = Colour.getBrighterColour(R1, G1, B1, A1);
SecondColourShowElement.style.backgroundColor = `rgba(${R2}, ${G2}, ${B2}, ${A2})`;
});
}
function compareFeature() {
// init the default value for element, variables and show element
FirstColourInHEX = FirstColourElement.value;
SecondColourInHEX = SecondColourElement.value;
// init the on change value functions
FirstColourElement.onchange = function() {
FirstColourInHEX = this.value;
FirstColourShowElement.style.backgroundColor = this.value;
};
SecondColourElement.onchange = function() {
SecondColourInHEX = this.value;
SecondColourShowElement.style.backgroundColor = this.value;
};
// init on click
compareButton.addEventListener("click", function() {
// convert HEX to LAB
const [L1, A1, B1] = Colour.hex2lab(FirstColourInHEX, 1);
const [L2, A2, B2] = Colour.hex2lab(SecondColourInHEX, 2);
const deltaE = Colour.deltaE00(L1, A1, B1, L2, A2, B2);
logElement.innerHTML += `<li class="result">DetlaE00: ${deltaE}</li>`;
});
}
</script>
</body>
</html>