get color picker working properly and format code
This commit is contained in:
parent
faeeb0cd2c
commit
b1136a2875
1 changed files with 19 additions and 4 deletions
23
script.js
23
script.js
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
const container = document.querySelector(".container");
|
const container = document.querySelector(".container");
|
||||||
const conWidth = container.clientWidth;
|
const conWidth = container.clientWidth;
|
||||||
const grid = document.createElement("div");
|
const grid = document.createElement("div");
|
||||||
|
|
@ -8,7 +7,9 @@ const colorPicker = document.querySelector("#custom-color");
|
||||||
let colorValue = "black";
|
let colorValue = "black";
|
||||||
let numGrid = gridSlider.value;
|
let numGrid = gridSlider.value;
|
||||||
let sliderLabel = document.querySelector("#sliderLabel");
|
let sliderLabel = document.querySelector("#sliderLabel");
|
||||||
//the next few variables test
|
|
||||||
|
//the next few variables are set to be used to test if
|
||||||
|
//a given button has been clicked
|
||||||
let isRgb;
|
let isRgb;
|
||||||
let isTint;
|
let isTint;
|
||||||
let isShade;
|
let isShade;
|
||||||
|
|
@ -18,10 +19,17 @@ let isBlack;
|
||||||
let isWhite;
|
let isWhite;
|
||||||
let isErase;
|
let isErase;
|
||||||
|
|
||||||
|
|
||||||
buttons.forEach((button) => {
|
buttons.forEach((button) => {
|
||||||
button.addEventListener ("click", changeColor);
|
button.addEventListener ("click", changeColor);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
colorPicker.addEventListener("change", colorGrid);
|
||||||
colorPicker.addEventListener("input", colorGrid);
|
colorPicker.addEventListener("input", colorGrid);
|
||||||
|
colorPicker.addEventListener("click", colorGrid);
|
||||||
|
colorPicker.addEventListener("change", changeColor);
|
||||||
|
colorPicker.addEventListener("input", changeColor);
|
||||||
|
colorPicker.addEventListener("click", changeColor);
|
||||||
|
|
||||||
|
|
||||||
function createGrid() {
|
function createGrid() {
|
||||||
|
|
@ -57,6 +65,7 @@ function getGridDimensions() {
|
||||||
createGrid();
|
createGrid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function colorGrid() {
|
function colorGrid() {
|
||||||
if (isRgb) {
|
if (isRgb) {
|
||||||
this.style.backgroundColor = randomizeColor();
|
this.style.backgroundColor = randomizeColor();
|
||||||
|
|
@ -75,11 +84,11 @@ function colorGrid() {
|
||||||
} else if (isErase) {
|
} else if (isErase) {
|
||||||
this.style.backgroundColor = "";
|
this.style.backgroundColor = "";
|
||||||
} else {
|
} else {
|
||||||
//this.style.backgroundColor = colorPicker.value;
|
this.style.backgroundColor = colorPicker.value;
|
||||||
this.style.background = colorPicker.value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function changeColor() {
|
function changeColor() {
|
||||||
const buttonID = this.id;
|
const buttonID = this.id;
|
||||||
|
|
||||||
|
|
@ -132,6 +141,7 @@ function changeColor() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function randomizeColor() {
|
function randomizeColor() {
|
||||||
let r = Math.floor(Math.random() * 255);
|
let r = Math.floor(Math.random() * 255);
|
||||||
let g = Math.floor(Math.random() * 255);
|
let g = Math.floor(Math.random() * 255);
|
||||||
|
|
@ -140,6 +150,7 @@ function randomizeColor() {
|
||||||
return `rgb(${r},${g},${b})`;
|
return `rgb(${r},${g},${b})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function tintColor(value) {
|
function tintColor(value) {
|
||||||
let num = value.match(/\d+/g);
|
let num = value.match(/\d+/g);
|
||||||
r = +num[0] + (0.25 * (255 - +num[0]));
|
r = +num[0] + (0.25 * (255 - +num[0]));
|
||||||
|
|
@ -149,6 +160,7 @@ function tintColor(value) {
|
||||||
return`rgb(${r},${g},${b})`;
|
return`rgb(${r},${g},${b})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function shadeColor(value) {
|
function shadeColor(value) {
|
||||||
let num = value.match(/\d+/g);
|
let num = value.match(/\d+/g);
|
||||||
r = +num[0] * .75;
|
r = +num[0] * .75;
|
||||||
|
|
@ -158,6 +170,7 @@ function shadeColor(value) {
|
||||||
return`rgb(${r},${g},${b})`;
|
return`rgb(${r},${g},${b})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function makeOpaque(value) {
|
function makeOpaque(value) {
|
||||||
let num = +value;
|
let num = +value;
|
||||||
|
|
||||||
|
|
@ -168,6 +181,7 @@ function makeOpaque(value) {
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function makeTransparent(value) {
|
function makeTransparent(value) {
|
||||||
let num = +value;
|
let num = +value;
|
||||||
|
|
||||||
|
|
@ -178,4 +192,5 @@ function makeTransparent(value) {
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
createGrid();
|
createGrid();
|
||||||
Loading…
Reference in a new issue