Skip to content

Commit c3adc67

Browse files
committed
proj 19: add UI indicator for saturation and pixelation.
1 parent c66f56c commit c3adc67

File tree

4 files changed

+57
-13
lines changed

4 files changed

+57
-13
lines changed

19--Webcam_Fun/css/controls.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
#ctrl_fx .ctrl_group .rgb label span {display: none;}
3737

38-
.max label span .value, .min label span .value {
38+
label span .value {
3939
padding:0.25em 0.5rem;
4040
color:white;
4141
line-height:1.4;

19--Webcam_Fun/index-jds.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ <h1>webcam fun</h1>
163163
<tr>
164164
<td>
165165
<label>
166-
<span>saturate: <code class="value">0</code></span>
166+
<span>saturation (%): <code class="value">0</code></span>
167167
<input id="saturate" type="range" class="input-range" value=100 min=0 max=200>
168168
</label>
169169
</td>

19--Webcam_Fun/js/mirror.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ function fMirror(pixels) {
3131
// }
3232

3333

34+
/**
35+
* https://jsbin.com/gufizu/edit?html,js,console
36+
*/
37+
3438
/* THE FOLLOWING RESULTS IN AN ERROR. SEE BELOW. */
3539
var arr = pixels.data;
3640
// console.log(arr);

19--Webcam_Fun/js/scripts.js

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

4040
/* video croma key controls */
4141
// const ctrlChromaKey = document.querySelector('#ctrl_fx_chroma');
42-
const inputAllChromaKey = document.querySelectorAll('#ctrl_fx_chroma input');
42+
const inputAllChromaKey = document.querySelectorAll('#ctrl_fx_chroma .input-range');
4343
const rgbMin = document.querySelector('.min .rgb');
4444
const rgbMax = document.querySelector('.max .rgb');
4545

@@ -128,6 +128,39 @@ function fChromaKeyInputs (group) {
128128
}
129129
fChromaKeyInputs(inputAllChromaKey);
130130

131+
/**
132+
* set background color of chroma range input labels. also put value number
133+
* in the UI.
134+
* @return {[type]} [description]
135+
*/
136+
function fUpdateInput (input) {
137+
console.group('START fUpdateInput: ', input);
138+
console.log('input.value: ', input.value);
139+
console.log('input.min: ', input.min);
140+
console.log('input.max: ', input.max);
141+
console.log('input.diff: ', Math.abs(input.min-input.max));
142+
const valRange = Math.abs(input.min-input.max);
143+
if (input.type === 'range'||input.type === 'number') {
144+
const label = input.parentElement;
145+
label.querySelector("span").querySelector("code").innerHTML = input.value;
146+
// const cell = label.parentElement;
147+
let bg, br;
148+
if (input.id==='saturate') {
149+
bg = `hsla(0,${input.value/2}%,50%,1)`;
150+
} else if (input.id==='pixelate') {
151+
bg = `#808080`;
152+
br = `${1/input.value}rem`;
153+
}
154+
label.querySelector("code").style.backgroundColor = bg;
155+
label.querySelector("code").style.borderRadius = br;
156+
// label.querySelector("input").style.backgroundColor = bg;
157+
}
158+
console.groupEnd();
159+
}
160+
inputAllRange.forEach((input)=>{
161+
fUpdateInput(input);
162+
});
163+
131164
/**
132165
* [toggleFxControls description]
133166
* @return {[type]} [description]
@@ -313,9 +346,7 @@ if (navigator.mediaDevices) {
313346
for (var i = 0; i < randoms.length; i++) {
314347
randoms[i] *= Math.floor(Math.random()*2) == 1 ? 1 : -1;
315348
}
316-
console.group('randoms: ', randoms);
317-
// console.log('randoms: ', randoms);
318-
console.groupEnd();
349+
console.log('randoms: ', randoms);
319350

320351
/* values for F/X function */
321352
console.group('selectSplit.value: ', selectSplit.value);
@@ -598,23 +629,32 @@ if (navigator.mediaDevices) {
598629
/* listen for change on deeper F/X select/option */
599630
inputAllSelect.forEach(btn => {
600631
btn.addEventListener('change',(e)=>{
601-
console.log('inputAllSelect: ',e.target);
632+
// console.log('inputAllSelect: ',e.target);
602633
startStream();
603634
})
604635
});
605636

606-
inputAllChromaKey.forEach(input => {
607-
input.addEventListener('change',(e)=>{
608-
fChromaKeyInputs(inputAllChromaKey);
609-
})
637+
inputSaturate.addEventListener('change',(e)=>{
638+
fUpdateInput(inputSaturate);
639+
});
640+
641+
inputPixelate.addEventListener('change',(e)=>{
642+
fUpdateInput(inputPixelate);
610643
});
611644

612645
inputAllChromaKey.forEach(input => {
613-
input.addEventListener('mousemove',(e)=>{
646+
input.addEventListener('change',(e)=>{
614647
fChromaKeyInputs(inputAllChromaKey);
615648
})
616649
});
617650

651+
/* update UI on mousemove */
652+
// inputAllChromaKey.forEach(input => {
653+
// input.addEventListener('mousemove',(e)=>{
654+
// fChromaKeyInputs(inputAllChromaKey);
655+
// })
656+
// });
657+
618658
let flagSaturate = false;
619659
inputSaturate.addEventListener('change',startStream);
620660
// inputSaturate.addEventListener('mousedown',(e)=>{
@@ -647,6 +687,6 @@ window.addEventListener('resize', fMediaQueries);
647687

648688
/* fake UI clicks to open controls */
649689
startStream();
650-
selectFx.selectedIndex = 4;
690+
selectFx.selectedIndex = 5;
651691
toggleFxControls();
652692

0 commit comments

Comments
 (0)