-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (40 loc) · 1.38 KB
/
Copy pathscript.js
File metadata and controls
48 lines (40 loc) · 1.38 KB
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
var colors=[]
let slider = document.getElementById("myRange");
let root = document.documentElement;
const turnButton = document.getElementById('turnButton')
function rangeValue(){
root.style.setProperty ('--uc-col2', slider.value)
}
turnButton.addEventListener('click', ()=>{
userColor=[]
userColor=[colors[0], Number(slider.value), colors[2]]
console.log(userColor)
console.log(colors)
colorAccuracy(userColor)
slider.value=125
})
function colorAccuracy(){
deltaR = colors[0]-userColor[0]
deltaG = colors[1]-userColor[1]
deltaB = colors[2]-userColor[2]
deltaE = Math.sqrt(Math.pow(deltaR, 2) + Math.pow(deltaG, 2) + Math.pow(deltaB, 2))
colAcc= (1- deltaE/441.67)*100
document.getElementById('color-accuracy').value=colAcc.toFixed(2);
newColor()
}
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1) + min);
}
function newColor(){
for(i=0; i<3; i++){
colors[i]=getRandomIntInclusive(0,255)
}
root.style.setProperty ('--ref-col1', colors[0])
root.style.setProperty ('--ref-col2', colors[1])
root.style.setProperty ('--ref-col3', colors[2])
root.style.setProperty ('--uc-col1', colors[0])
root.style.setProperty ('--uc-col2', slider.value)
root.style.setProperty ('--uc-col3', colors[2])
}