-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
114 lines (88 loc) · 3.99 KB
/
script.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
let CURRENT_COLOR;
let mouseDown = false;
const slider = document.getElementById('mySlider');
const currentSize = document.getElementById('currentSize');
const grid = document.getElementById('grid');
const removeGridBtn = document.getElementById('removeGrid');
const resetBtn = document.getElementById('reset').addEventListener('click', () => resetGrid());
document.body.onmousedown = () => mouseDown = true;
document.body.onmouseup = () => mouseDown = false;
// Colours
const black = document.getElementById('black').addEventListener('click', () => CURRENT_COLOR = 'black');
const yellow = document.getElementById('yellow').addEventListener('click', () => CURRENT_COLOR = '#fad643');
const white = document.getElementById('white').addEventListener('click', () => CURRENT_COLOR = 'white');
const orange = document.getElementById('orange').addEventListener('click', () => CURRENT_COLOR = '#f8961e');
const purple = document.getElementById('purple').addEventListener('click', () => CURRENT_COLOR = '#b185db');
const blue = document.getElementById('blue').addEventListener('click', () => CURRENT_COLOR = '#4ea8de');
const green = document.getElementById('green').addEventListener('click', () => CURRENT_COLOR = '#5fad56');
const red = document.getElementById('red').addEventListener('click', () => CURRENT_COLOR = '#c81d25');
const rainbow = document.getElementById('rainbow').addEventListener('click', () => CURRENT_COLOR = rainbowColors);
const pastel = document.getElementById('pastel').addEventListener('click', () => CURRENT_COLOR = pastelColors);
const mono = document.getElementById('mono').addEventListener('click', () => CURRENT_COLOR = monoColors);
const vintage = document.getElementById('vintage').addEventListener('click', () => CURRENT_COLOR = vintageColors);
const pastelColors = ['#FBF8CC', '#FDE4CF', '#FFCFD2', 'F1C0E8', '#CFBAF0',
'#A3C4F3', '#90DBF4', '#8EECF5', '#98F5E1', '#B9FBC0'
];
const rainbowColors = ['#54478C', '#2C699A', '#048BA8', '#0DB39E', '#16DB93',
'#83E377', '#B9E769', '#EFEA5A', '#F1C453', '#F29E4C'
];
const monoColors = ['#F8F9FA', '#E9ECEF', '#DEE2E6', '#CED4DA', '#ADB5BD',
'#6C757D', '#495057', '#343A40', '#212529'
];
const vintageColors = ['#797D62', '#9B9B7A', '#BAA587', '#D9AE94', '#F1DCA7',
'#FFCB69', '#E8AC65', '#D08C60', '#B58463', '#997B66'
];
// Colour square if mouse is clicked
function addHoverColor() {
const squares = document.querySelectorAll('.pixel');
squares.forEach(square => square.addEventListener('mouseover', () => {
if (mouseDown) {
if (typeof (CURRENT_COLOR) === "string") {
square.style.backgroundColor = CURRENT_COLOR;
} else {
square.style.backgroundColor = CURRENT_COLOR[Math.floor(Math.random() * CURRENT_COLOR.length)]
};
}
}))
};
function makeGrid(size) {
for (let i = 0; i < size; i++) {
const row = document.createElement('div');
row.classList.add('row');
for (let j = 0; j < size; j++) {
const pixel = document.createElement('div');
pixel.classList.add('pixel');
row.appendChild(pixel);
}
grid.appendChild(row);
}
addHoverColor();
}
function deleteGrid() {
grid.textContent = '';
}
function resetGrid() {
CURRENT_COLOR = "";
const squares = document.querySelectorAll('.pixel');
squares.forEach(function (element) {
element.style = "null";
})
}
function gridOnOff() {
}
removeGridBtn.addEventListener('click', () => {
const squares = document.querySelectorAll('.pixel');
if (removeGridBtn.textContent === 'grid: ON') {
squares.forEach(square => square.style.borderStyle = "none");
removeGridBtn.textContent = "grid: OFF";
} else {
squares.forEach(square => square.style.borderStyle = "solid");
removeGridBtn.textContent = "grid: ON";
}
});
slider.oninput = function () {
currentSize.textContent = `${slider.value} x ${slider.value}`;
deleteGrid();
makeGrid(slider.value);
}
makeGrid(slider.value);