-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
333 lines (289 loc) · 14.2 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sliced Colorspace Picker</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=yes">
<link rel="icon" type="image/x-icon" href="./favicon.png">
<!-- CSS -->
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="track.css">
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Libre+Franklin&family=Lora:wght@400;700&family=Source+Code+Pro:ital,wght@0,500;1,300&display=swap"
rel="stylesheet">
<!-- Three.js and D3.js -->
<script src="https://cdn.jsdelivr.net/gh/mrdoob/three.js@r95/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/mrdoob/three.js@r95/examples/js/Detector.js"></script>
<script src="./javascript/orbit-controls.js"></script>
<script src="https://d3js.org/d3.v7.min.js"></script>
<script type="text/javascript" src="./javascript/color-analysis-logic.js"></script>
<script type="text/javascript" src="./javascript/slider.js"></script>
</head>
<body>
<div>
<h1>Sliced Colorspace Color Picker</h1>
<div id="canvas-formatter">
<div id="canvas-container">
<input id="cs3" type="range" min="0.0001" max="99.9" step="0.01">
<svg id="_gray" style="position: absolute;">
<g id="gray" transform="translate(0,0)">
<circle id="invisibleCircle" cx="0" cy="0" stroke-width="2" stroke="none" fill="transparent" />
<line x1="2" y1="2" x2="3" y2="3" stroke-width="2" stroke="white" />
<line x1="-2" y1="-2" x2="-3" y2="-3" stroke-width="2" stroke="white" />
<line x1="-2" y1="2" x2="-3" y2="3" stroke-width="2" stroke="white" />
<line x1="2" y1="-2" x2="3" y2="-3" stroke-width="2" stroke="white" />
<line x1="0" y1="2.7" x2="0" y2="4.4" stroke-width="2" stroke="black" />
<line x1="0" y1="-2.7" x2="0" y2="-4.4" stroke-width="2" stroke="black" />
<line x1="2.7" y1="0" x2="4.4" y2="0" stroke-width="2" stroke="black" />
<line x1="-2.7" y1="0" x2="-4.4" y2="0" stroke-width="2" stroke="black" />
</g>
</svg>
<svg id="_xhair" style="position: absolute;">
<g id="xhair" transform="translate(0,0)">
<circle cx="0" cy="0" r="5" stroke-width="1" stroke="white" fill="none" />
<circle cx="0" cy="0" r="6" stroke-width="1" stroke="black" fill="none" />
</g>
</svg>
<canvas id="theCanvas">Your browser does not support the HTML5 canvas tag.</canvas>
</div>
<div id="text-container">
<div class="flexRow">
<div id=" out">
<svg id="_outRect">
<rect id="outRect"></rect>
</svg>
<div id="outText"></div>
</div>
<div id="currentValues">
<div class="flexRow">
<svg class="clickable" xmlns="http://www.w3.org/2000/svg" width="22" height="22"
viewBox="0 0 22 22" style="fill: rgb(118, 118, 118);">
<path
d="M20 2H10c-1.103 0-2 .897-2 2v4H4c-1.103 0-2 .897-2 2v10c0 1.103.897 2 2 2h10c1.103 0 2-.897 2-2v-4h4c1.103 0 2-.897 2-2V4c0-1.103-.897-2-2-2zM4 20V10h10l.002 10H4zm16-6h-4v-4c0-1.103-.897-2-2-2h-4V4h10v10z">
</path>
</svg>
<span id="rgbVal">rgb(0,0,0)</span>
</div>
<div class="flexRow">
<svg class="clickable" xmlns="http://www.w3.org/2000/svg" width="22" height="22"
viewBox="0 0 22 22" style="fill: rgb(118, 118, 118);">
<path
d="M20 2H10c-1.103 0-2 .897-2 2v4H4c-1.103 0-2 .897-2 2v10c0 1.103.897 2 2 2h10c1.103 0 2-.897 2-2v-4h4c1.103 0 2-.897 2-2V4c0-1.103-.897-2-2-2zM4 20V10h10l.002 10H4zm16-6h-4v-4c0-1.103-.897-2-2-2h-4V4h10v10z">
</path>
</svg>
<span id="hslVal">hsl(0,0,0)</span>
</div>
<div class="flexRow">
<svg class="clickable" xmlns="http://www.w3.org/2000/svg" width="22" height="22"
viewBox="0 0 22 22" style="fill: rgb(118, 118, 118);">
<path
d="M20 2H10c-1.103 0-2 .897-2 2v4H4c-1.103 0-2 .897-2 2v10c0 1.103.897 2 2 2h10c1.103 0 2-.897 2-2v-4h4c1.103 0 2-.897 2-2V4c0-1.103-.897-2-2-2zM4 20V10h10l.002 10H4zm16-6h-4v-4c0-1.103-.897-2-2-2h-4V4h10v10z">
</path>
</svg>
<span id="hclVal">lch(0,0,0)</span>
</div>
<div class="flexRow">
<svg class="clickable" xmlns="http://www.w3.org/2000/svg" width="22" height="22"
viewBox="0 0 22 22" style="fill: rgb(118, 118, 118);">
<path
d="M20 2H10c-1.103 0-2 .897-2 2v4H4c-1.103 0-2 .897-2 2v10c0 1.103.897 2 2 2h10c1.103 0 2-.897 2-2v-4h4c1.103 0 2-.897 2-2V4c0-1.103-.897-2-2-2zM4 20V10h10l.002 10H4zm16-6h-4v-4c0-1.103-.897-2-2-2h-4V4h10v10z">
</path>
</svg>
<span id="hexVal">#ffffff</span>
</div>
</div>
</div>
<div id="color-picker">
<div>
<input type="radio" id="rb-drgb" name="color-space" value="dRGB" checked="checked">
<label for="rb-drgb">RGB: red-green-blue</label><br>
</div>
<div>
<input type="radio" id="rb-hsl" name="color-space" value="HSL">
<label for="rb-hsl">HSL: hue-saturation-lightness</label><br>
</div>
<div>
<input type="radio" id="rb-hcl" name="color-space" value="HCL">
<label for="rb-hcl">LCH: hue-chroma-perceptual-luminance</label><br>
</div>
<div id="t3">
<input type="text" id="tx3">
=
<label for="tx3" id="tl3">
<span class="fraction">
<span class="numerator">mean(R,G,B) * 100</span>
<span class="division">/</span>
<span class="denominator">255</span>
</span>
</label>
</div>
</div>
</div>
<div id="threeCanvasContainer">
<div id = "threeButtonContainer">
<button id="shapeToggle">Show Faces</button>
<button id="pauseToggle">⏸︎</button>
</div>
</div>
</div>
</div>
<script src="./javascript/copy-logic.js"></script>
<script>
// Copyright (C) 2023 University of Chicago. All rights reserved.
d3.select("#cdesc").html(theCDesc[theSpace]);
var theSize = 335;
// set theSize as a css variable
document.documentElement.style.setProperty('--theSize', theSize + "px");
var theCanvas = document.getElementById("theCanvas");
var dragging = false;
document.addEventListener("DOMContentLoaded", function () {
setColorSlider();
setColorText();
d3.select("#cs3").on("input", function () {
inputColorSlider(), handleSliderChange()
});
d3.select("#tx3").on("change", inputColorText);
d3.select("#rb-drgb").on("click", function () { radio("dRGB"); handleModeChange(); });
d3.select("#rb-hsl").on("click", function () { radio("HSL"); handleModeChange(); });
d3.select("#rb-hcl").on("click", function () { radio("HCL"); handleModeChange(); });
// d3.select("#rb-hsv").on("click", function () { radio("HSV"); });
d3.select("#mouse").on("touchstart", pick);
});
// For Desktop
document.querySelector("#invisibleCircle").onmousedown = function (e) {
dragging = true;
pick(undefined, undefined, e);
};
document.onmouseup = function () {
dragging = false;
if (!isPaused){
cameraSpinRate = 0.0025;
window.gamutRenderer.cameraSpinRate = 0.0025;
}
};
document.onmousemove = function (e) {
if (dragging) pick(undefined, undefined, e);
};
// For Mobile
document.querySelector("#invisibleCircle").addEventListener('touchstart', function (e) {
e.preventDefault();
dragging = true;
pick(undefined, undefined, e.touches[0]);
}, { passive: false });
document.addEventListener('touchend', function () {
dragging = false;
if (!isPaused){
cameraSpinRate = 0.0025;
window.gamutRenderer.cameraSpinRate = 0.0025;
}
}, { passive: false });
document.addEventListener('touchmove', function (e) {
if (dragging) {
e.preventDefault();
pick(undefined, undefined, e.touches[0]);
}
}, { passive: false });
d3.select("#invisibleCircle").attr("r", 0.95 * (theSize / 2));
document.querySelector("#cs3").onmousedown = function () { cameraSpinRate = 0; window.gamutRenderer.cameraSpinRate = 0; };
document.querySelector("#cs3").style.width = theSize + "px"
d3.select("#theCanvas").attr("width", theSize).attr("height", theSize);
document.querySelector("#canvas-container").style.width = theSize + "px"
document.querySelector("#canvas-container").style.height = theSize + "px"
d3.select("#_xhair").attr("width", theSize).attr("height", theSize)
d3.select("#_gray").attr("width", theSize).attr("height", theSize)
d3.select("#gray").attr("transform", "translate(" + theSize / 2 + "," + theSize / 2 + ")");
var theContext = theCanvas.getContext("2d");
var theImage = theContext.createImageData(theSize, theSize);
pick(theSize / 2, theSize / 2);
refreshCanvas();
d3.select("#_outRect").attr("width", 132).attr("height", 132)
d3.select("#outRect").attr("width", 132).attr("height", 132)
</script>
<script src="./javascript/scene-handler.js"></script>
<script src="./javascript/rgbcube.js"></script>
<script src="./javascript/hsldoublecone.js"></script>
<script src="./javascript/gamut.js"></script>
<script>
// This is used to prevent multiple animate loops from running
var isAnimating = true
// Slider and Colorspace changing handling
function handleModeChange() {
if (theSpace == 'HCL') {
gamutCanvas.style.display = "flex";
threeCanvas.style.display = "none";
isAnimating = false
}
else {
gamutCanvas.style.display = "none";
threeCanvas.style.display = "flex";
if (!isAnimating) {
animate();
}
isAnimating = true
}
}
function handleSliderChange() {
if (theSpace == 'dRGB') {
updateRGB()
}
else if (theSpace == 'HSL') {
updateHSL()
}
else if (theSpace == 'HCL') {
updateHCL()
}
}
const shapeToggle = document.getElementById("shapeToggle");
var isShapeVisible = false;
shapeToggle.addEventListener("click", function () {
isShapeVisible = !isShapeVisible;
handleRGBShape(isShapeVisible)
handleHSLShape(isShapeVisible)
handleHCLShape(isShapeVisible)
});
const pauseToggle = document.getElementById("pauseToggle");
var isPaused = false;
pauseToggle.addEventListener("click", function () {
isPaused = !isPaused;
if (isPaused) {
pauseToggle.innerHTML = "⏵"
cameraSpinRate = 0;
window.gamutRenderer.cameraSpinRate = 0;
}
else {
cameraSpinRate = 0.0025;
window.gamutRenderer.cameraSpinRate = 0.0025;
pauseToggle.innerHTML = "⏸"
}
});
// Animation Loop for RGB Cube and HSL Cone
var theta = 0;
var cameraSpinRate = 0.0025;
function animate() {
theta += cameraSpinRate;
camera.position.x = 50 * Math.sin(theta);
camera.position.z = 50 * Math.cos(theta);
camera.lookAt(new THREE.Vector3(0, longDiagonal / 2, 0)); // Look at the center of the scene
if (theSpace == "dRGB") {
renderer.render(rgbScene, camera);
drawIntersectionPoints();
} else if (theSpace == "HSL") {
renderer.render(hslScene, camera);
}
else {
return
}
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>