-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvas.js
43 lines (35 loc) · 1009 Bytes
/
canvas.js
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
const canvas = document.getElementById("canvas_1");
const ctx = canvas.getContext("2d");
canvas.width = 800;
canvas.height = 400;
const redInput = document.getElementById("red");
const greenInput = document.getElementById("green");
const blueInput = document.getElementById("blue");
const inputs = [redInput, greenInput, blueInput];
const color = [0, 0, 0];
const scrubbingConfig = {
min: 0,
max: 255,
step: 1,
threshold: 8,
maxAcc: 3,
onScrub() {
onChange({ target: this.elm });
},
};
function onChange(e) {
const colorIndx = inputs.indexOf(e.target);
color[colorIndx] = e.target.value;
render();
}
inputs.forEach((input) => {
input.addEventListener("input", onChange);
Scrubbable(input, { ...scrubbingConfig, zone: input.previousElementSibling });
});
function render() {
let { width, height } = canvas;
ctx.clearRect(0, 0, width, height);
ctx.fillStyle = `rgb(${color.join()})`;
ctx.fillRect(0, 0, width, height);
}
render();