Add tint and shading functions
This commit is contained in:
parent
b7666e1ca8
commit
354bc7c4d0
1 changed files with 29 additions and 1 deletions
30
script.js
30
script.js
|
|
@ -53,7 +53,9 @@ function colorGrid() {
|
||||||
if (isRgb) {
|
if (isRgb) {
|
||||||
this.style.background = randomizeColor();
|
this.style.background = randomizeColor();
|
||||||
} else if (isTint) {
|
} else if (isTint) {
|
||||||
|
this.style.background = tintColor(this.style.background);
|
||||||
|
} else if (isShade) {
|
||||||
|
this.style.background = shadeColor(this.style.background);
|
||||||
} else {
|
} else {
|
||||||
this.style.background = colorValue;
|
this.style.background = colorValue;
|
||||||
}
|
}
|
||||||
|
|
@ -74,6 +76,12 @@ function changeColor() {
|
||||||
isTint = false
|
isTint = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (buttonID === "shade") {
|
||||||
|
isShade = true;
|
||||||
|
} else {
|
||||||
|
isShade = false
|
||||||
|
}
|
||||||
|
|
||||||
switch (buttonID) {
|
switch (buttonID) {
|
||||||
case "whiteColor":
|
case "whiteColor":
|
||||||
colorValue = "white";
|
colorValue = "white";
|
||||||
|
|
@ -102,7 +110,27 @@ function randomizeColor() {
|
||||||
let b = Math.floor(Math.random() * 255);
|
let b = Math.floor(Math.random() * 255);
|
||||||
|
|
||||||
return `rgb(${r},${g},${b})`;
|
return `rgb(${r},${g},${b})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function tintColor(value) {
|
||||||
|
let num = value.match(/\d+/g);
|
||||||
|
r = num[0] + num[0] * 1/10;
|
||||||
|
g = num[1] + num[1] * 1/10;
|
||||||
|
b = num[2] + num[2] * 1/10;
|
||||||
|
console.log(r, g, b);
|
||||||
|
|
||||||
|
return`rgb(${r},${g},${b})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function shadeColor(value) {
|
||||||
|
let num = value.match(/\d+/g);
|
||||||
|
r = num[0] - num[0] * 1/10;
|
||||||
|
g = num[1] - num[1] * 1/10;
|
||||||
|
b = num[2] - num[2] * 1/10;
|
||||||
|
console.log(r, g, b);
|
||||||
|
|
||||||
|
return`rgb(${r},${g},${b})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
createGrid();
|
createGrid();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue