-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolors.html
226 lines (197 loc) · 8.28 KB
/
colors.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
221
222
223
224
225
226
<!DOCTYPE html>
<html lang="en">
<head>
<!-- https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta -->
<meta charset="utf-8">
<meta content="initial-scale=1, width=device-width" name="viewport">
<!-- own content -->
<link href="source/styles/styles.css" rel="stylesheet">
<title>Color mixer</title>
<script>
function Hex(val) {
return Math.round(val * 255).toString(16).padStart(2, '0')
}
function HueToRgb(p, q, t) {
if (t < 0)
t += 1
if (t > 1)
t -= 1
if (t < 1/6)
return p + (q - p) * 6 * t
if (t < 1/2)
return q
if (t < 2/3)
return p + (q - p) * (2/3 - t) * 6
return p
}
function HslToRgbText(h, s, l) {
let r, g, b
if (s == 0)
r = g = b = l // achromatic
else {
const q = l < 0.5 ? l * (1 + s) : l + s - l * s
const p = 2 * l - q
r = HueToRgb(p, q, h + 1/3)
g = HueToRgb(p, q, h)
b = HueToRgb(p, q, h - 1/3)
}
return `#${Hex(r)}${Hex(g)}${Hex(b)}`
}
function UpdateCSS(idSuffix, colorText) {
let SetElemsBackgroundColor = (selector) => {
document.querySelectorAll(selector).forEach((elem) => {
elem.style.background = colorText
})
}
if (idSuffix == 'b')
SetElemsBackgroundColor('.newColor')
else if (idSuffix == 'h')
SetElemsBackgroundColor('.newColor h1, .newColor #banner, .newColor em, .newColor thead tr')
else if (idSuffix == 'o')
SetElemsBackgroundColor('.newColor tbody tr:nth-child(odd)')
else if (idSuffix == 'e')
SetElemsBackgroundColor('.newColor tbody tr:nth-child(even)')
}
function ChangeColorGroup(idSuffix) {
let hue = document.getElementById('hue').value
let sat = document.getElementById(`sat_${idSuffix}`).value
let lum = document.getElementById(`lum_${idSuffix}`).value
let colorText = HslToRgbText(hue / 255.0, sat / 255.0, lum / 255.0)
document.getElementById(`${idSuffix}_val`).textContent = colorText
UpdateCSS(idSuffix, colorText)
}
function ShowSliderValue(sliderElem) {
document.getElementById(`${sliderElem.id}_val`).textContent = sliderElem.value
}
function ChangeColor(elem) {
ShowSliderValue(elem)
let hueChanged = elem.id == 'hue'
if (hueChanged) {
ChangeColorGroup('b')
ChangeColorGroup('h')
ChangeColorGroup('o')
ChangeColorGroup('e')
}
else {
let idSuffix = elem.id[4]
ChangeColorGroup(idSuffix)
}
}
window.addEventListener('load', () => {
document.querySelectorAll('.slider').forEach((sliderElem) => {
sliderElem.addEventListener('input', () => {
ChangeColor(sliderElem)
})
ChangeColor(sliderElem)
})
})
</script>
<style>
form {
padding: 1em;
position: sticky;
top: 0;
display: inline-block;
background-color: #ffffffa0;
white-space: nowrap;
}
form table,
form table tr,
form table td {
padding: 0px;
margin: 0px;
}
form table td {
padding: 0em 0.2em;
}
.slider {
width: 10em;
}
</style>
</head>
<body>
<form>
<table>
<tr>
<td>Hue:</td>
<td><input type="range" min="0" max="255" value="190" class="slider" id="hue"></td>
<td><span id="hue_val"></span></td>
</tr>
<tr>
<td>Sat:</td>
<td><input type="range" min="0" max="255" value="255" class="slider" id="sat_b"></td>
<td><span id="sat_b_val"></span></td>
<td>Sat:</td>
<td><input type="range" min="0" max="255" value="130" class="slider" id="sat_h"></td>
<td><span id="sat_h_val"></span></td>
<td>Sat:</td>
<td><input type="range" min="0" max="255" value="160" class="slider" id="sat_o"></td>
<td><span id="sat_o_val"></span></td>
<td>Sat:</td>
<td><input type="range" min="0" max="255" value="160" class="slider" id="sat_e"></td>
<td><span id="sat_e_val"></span></td>
</tr>
<tr>
<td>Lum:</td>
<td><input type="range" min="0" max="255" value="230" class="slider" id="lum_b"></td>
<td><span id="lum_b_val"></span></td>
<td>Lum:</td>
<td><input type="range" min="0" max="255" value="60" class="slider" id="lum_h"></td>
<td><span id="lum_h_val"></span></td>
<td>Lum:</td>
<td><input type="range" min="0" max="255" value="210" class="slider" id="lum_o"></td>
<td><span id="lum_o_val"></span></td>
<td>Lum:</td>
<td><input type="range" min="0" max="255" value="190" class="slider" id="lum_e"></td>
<td><span id="lum_e_val"></span></td>
</tr>
<tr>
<td colspan="3">--contentColor: <span id="b_val"></span></td>
<td colspan="3">--headerColor: <span id="h_val"></span></td>
<td colspan="3">--tableOddColor: <span id="o_val"></span></td>
<td colspan="3">--tableEvenColor: <span id="e_val"></span></td>
</tr>
</table>
</form>
<div class="content firstContent newColor">
<div id="banner">
<a href="index.html"><div class="letter"><img src="source/images/o1.png"></div><div class="letter"><img src="source/images/m.png"></div><div class="letter"><img src="source/images/e.png"></div><div class="letter"><img src="source/images/o2.png"></div></a><br>
<span class="subtitle">Colorized</span>
</div>
<p>Nunc arcu diam, tincidunt vel tincidunt eget, dapibus sed nisi. Fusce non libero semper, dapibus nisi varius, imperdiet neque. Nulla nibh urna, pellentesque eu faucibus id, dapibus vitae neque. Fusce auctor rutrum augue sit amet egestas. Etiam tempus aliquet laoreet. Etiam ultricies interdum velit, at lobortis magna luctus id. Quisque molestie aliquam ante a sagittis. Ut rhoncus elit vitae ante maximus laoreet. Vivamus ligula tellus, aliquam ut justo sit amet, lacinia suscipit sem. Aenean non nisl varius, facilisis eros in, hendrerit orci.</p>
<p>Maecenas et purus lacinia, sodales augue at, tincidunt ex. Praesent rutrum ultrices ex, sed vehicula est <em>molestie</em> eget. Nam diam lorem, rhoncus ut mauris porta, porta eleifend libero.</p>
</div>
<div class="content newColor">
<h1>Integer felis ex</h1>
<p>Suspendisse vestibulum turpis magna, quis laoreet dui tempor tempus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Integer venenatis imperdiet tempor.</p>
<dl>
<dt>Donec a pellentesque ante</dt>
<dd>Praesent lobortis malesuada felis, id suscipit eros luctus id. Maecenas vestibulum at felis eu sodales.
<table class="table">
<thead>
<tr>
<th>Sed est<br>felis</th><th><em>Consectetur<br>nibh</em></th>
</tr>
</thead>
<tbody>
<tr><td>0</td><td><em>0</em></td></tr>
<tr><td>1</td><td><em>1</em></td></tr>
<tr><td>2</td><td><em>3</em></td></tr>
<tr><td>3</td><td><em>7</em></td></tr>
<tr><td>4</td><td><em>15</em></td></tr>
<tr><td>5</td><td><em>31</em></td></tr>
</tbody>
</table>
</dd>
<dt>Nulla facilisi</dt>
<dd>Nulla accumsan dolor eget turpis sollicitudin tristique. Cras non faucibus enim. Donec laoreet dolor sem, id <em>tempus</em> diam fermentum tempor. Sed laoreet risus id leo vulputate, non <em>tempus</em> tellus fringilla. Nullam quis ante leo. Cras convallis mauris eu mattis porttitor;
<ul>
<li>Fusce ultrices ante quis ante maximus viverra.</li>
<li>Nam sit amet dapibus sem. Duis sodales accumsan felis, vel vestibulum magna aliquam facilisis.</li>
<li>Sed est felis, elementum venenatis neque nec, laoreet sollicitudin tortor. Sed volutpat nulla nec sapien convallis tempus.</li>
</ul>
</dd>
</dl>
</div>
</body>
</html>