Skip to content

Commit 55c69c2

Browse files
committed
proj 19: display chroma key value next to input.
1 parent e87a874 commit 55c69c2

File tree

3 files changed

+41
-25
lines changed

3 files changed

+41
-25
lines changed

19--Webcam_Fun/css/controls.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,18 @@
7272
#table-chroma .red input {
7373
/* background-color:#f00; */
7474
}
75-
#table-chroma .red:before {
76-
/* content:'R'; *//* color:#f00; */
75+
#table-chroma .red label:before {
76+
content:'R';/* color:#f00; */
7777
}
7878
#table-chroma .green input {
7979
/* background-color:#0f0; */
8080
}
81-
#table-chroma .green:before {
82-
/* content:'G'; *//* color:#0f0; */
81+
#table-chroma .green label:before {
82+
content:'G';/* color:#0f0; */
8383
}
8484
#table-chroma .blue input {
8585
/* background-color:#00f; */
8686
}
87-
#table-chroma .blue:before {
88-
/* content:'B'; *//* color:#00f; */
87+
#table-chroma .blue label:before {
88+
content:'B';/* color:#00f; */
8989
}

19--Webcam_Fun/index-jds.html

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,47 +88,53 @@ <h1>webcam fun</h1>
8888
<tr>
8989
<td class="red min">
9090
<label for="rmin">
91-
<span>dark:</span>
91+
<span>min: <code>0</code></span>
9292
<input type="range" value=0 min=0 max=255 name="rmin">
9393
</label>
9494
</td>
9595
<td class="green min">
9696
<label for="gmin">
97-
<span>dark:</span>
97+
<span>min: <code>0</code></span>
9898
<input type="range" value=0 min=0 max=255 name="gmin">
9999
</label>
100100
</td>
101101
<td class="blue min">
102102
<label for="bmin">
103-
<span>dark:</span>
103+
<span>min: <code>0</code></span>
104104
<input type="range" value=0 min=0 max=255 name="bmin">
105105
</label>
106106
</td>
107107
<td class="rgb min">
108-
<div id="">this is the min color</div>
108+
<label id="">
109+
<span>min color</span>
110+
<!-- <input type="color"> -->
111+
</label>
109112
</td>
110113
</tr>
111114
<tr>
112115
<td class="red max">
113116
<label for="rmax">
114-
<span>light:</span>
117+
<span>max: <code>0</code></span>
115118
<input type="range" value=0 min=0 max=255 name="rmax">
116119
</label>
117120
</td>
118121
<td class="green max">
119122
<label for="gmax">
120-
<span>light:</span>
123+
<span>max: <code>0</code></span>
121124
<input type="range" value=0 min=0 max=255 name="gmax">
122125
</label>
123126
</td>
124127
<td class="blue max">
125128
<label for="bmax">
126-
<span>light:</span>
129+
<span>max: <code>0</code></span>
127130
<input type="range" value=0 min=0 max=255 name="bmax">
128131
</label>
129132
</td>
130133
<td class="rgb max">
131-
<div id="">this is the max color</div>
134+
<label id="">
135+
<span>max color</span>
136+
<!-- <input type="color"> -->
137+
</label>
132138
</td>
133139
</tr>
134140
<tr>

19--Webcam_Fun/js/scripts.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ const selectSplit = document.querySelector('#split');
3737

3838
/* video croma key controls */
3939
const ctrlChroma = document.querySelector('#table-chroma');
40-
const inputsChroma = document.querySelectorAll('#table-chroma input')
40+
const inputsChroma = document.querySelectorAll('#table-chroma input[type=range]')
41+
const rgbMin = document.querySelector('.rgb.min label');
42+
// console.log(rgbMin);
43+
const rgbMax = document.querySelector('.rgb.max label');
44+
// console.log(rgbMax);
4145

4246
/* buttons */
4347
const btnsApply = document.querySelectorAll('.btn_apply');
@@ -72,27 +76,33 @@ hide(video);
7276
document.querySelector('.ctrl_strip label span').innerHTML = `Limit? (${stripMax})`;
7377
function fChromaInputs () {
7478
console.log('START fChromaInputs');
75-
inputsChroma.forEach(range => {
76-
const label = range.parentElement;
79+
const levels = {};
80+
inputsChroma.forEach((input) => {
81+
levels[input.name] = input.value;
82+
const label = input.parentElement;
83+
label.querySelector("span").querySelector("code").innerHTML = input.value;
7784
const cell = label.parentElement;
7885
let bg;
79-
console.log(cell.classList[0]+' '+cell.classList[1]+': '+range.value);
86+
// console.log(cell.classList[0]+' '+cell.classList[1]+': '+input.value);
8087
if (cell.classList.contains("red")) {
81-
bg = `rgb(${range.value},0,0)`;
88+
bg = `rgb(${input.value},0,0)`;
8289
} else if (cell.classList.contains("green")) {
83-
bg = `rgb(0,${range.value},0)`;
90+
bg = `rgb(0,${input.value},0)`;
8491
} else {
85-
bg = `rgb(0,0,${range.value})`;
92+
bg = `rgb(0,0,${input.value})`;
8693
}
8794
label.style.backgroundColor = bg;
88-
if (range.value < 200) {
95+
if (input.value < 204) {
8996
label.style.color = "white";
9097
} else {
91-
label.style.color = "black";
98+
label.style.color = "white";
9299
}
93100
// e.target.parentElement.style.backgroundColor = `rgb(0,${e.target.value},0)`;
94101
// e.target.parentElement.innerHTML = `${e.target.value}`;
95102
});
103+
// console.log('levels: ', levels);
104+
rgbMin.style.backgroundColor = `rgb(${levels["rmin"]},${levels["gmin"]},${levels["bmin"]})`;
105+
rgbMax.style.backgroundColor = `rgb(${levels["rmax"]},${levels["gmax"]},${levels["bmax"]})`;
96106
}
97107
fChromaInputs();
98108

@@ -486,8 +496,8 @@ if (navigator.mediaDevices) {
486496
})
487497
});
488498

489-
inputsChroma.forEach(range => {
490-
range.addEventListener('change',(e)=>{
499+
inputsChroma.forEach(input => {
500+
input.addEventListener('change',(e)=>{
491501
fChromaInputs();
492502
})
493503
});

0 commit comments

Comments
 (0)