parent
e7deb660cb
commit
d703db5bac
@ -1,124 +1,124 @@ |
|||||||
'use strict'; |
(function() { |
||||||
|
'use strict'; |
||||||
|
|
||||||
let brushClass = 'drab-black'; |
let brushClass = 'drab-black'; |
||||||
|
|
||||||
const paintPixel = function(pixel) { |
const paintPixel = function(pixel) { |
||||||
pixel.classList.remove(pixel.classList.item(1)); |
pixel.classList.remove(pixel.classList.item(1)); |
||||||
pixel.classList.add(brushClass); |
pixel.classList.add(brushClass); |
||||||
} |
|
||||||
|
|
||||||
const drawCanvas = function() { |
|
||||||
const canvas = document.querySelector('#canvas'); |
|
||||||
let pixel; |
|
||||||
|
|
||||||
for (let i = 0; i < 2013; i++) { |
|
||||||
pixel = document.createElement('div'); |
|
||||||
pixel.classList.add('pixel'); |
|
||||||
canvas.appendChild(pixel); |
|
||||||
} |
} |
||||||
|
|
||||||
canvas.addEventListener('click', (event) => { |
const drawCanvas = function() { |
||||||
if (event.target === canvas) { |
const canvas = document.querySelector('#canvas'); |
||||||
return; |
|
||||||
|
for (let i = 0; i < 2013; i++) { |
||||||
|
const pixel = document.createElement('div'); |
||||||
|
pixel.classList.add('pixel'); |
||||||
|
canvas.appendChild(pixel); |
||||||
} |
} |
||||||
|
|
||||||
paintPixel(event.target); |
canvas.addEventListener('click', (event) => { |
||||||
}); |
if (event.target === canvas) { |
||||||
|
return; |
||||||
// or...
|
} |
||||||
// let isPainting = false;
|
|
||||||
//
|
paintPixel(event.target); |
||||||
// canvas.addEventListener('mousedown', () => {
|
}); |
||||||
// isPainting = true;
|
|
||||||
//
|
// Bonus 1 - paintbrush
|
||||||
// if (event.target === canvas) {
|
//
|
||||||
// return;
|
// let isPainting = false;
|
||||||
// }
|
//
|
||||||
//
|
// canvas.addEventListener('mousedown', () => {
|
||||||
// paintPixel(event.target);
|
// isPainting = true;
|
||||||
// });
|
//
|
||||||
//
|
// if (event.target === canvas) {
|
||||||
// canvas.addEventListener('mouseup', () => {
|
// return;
|
||||||
// isPainting = false;
|
// }
|
||||||
// });
|
//
|
||||||
//
|
// paintPixel(event.target);
|
||||||
// const pixels = document.querySelectorAll('.pixel');
|
// });
|
||||||
//
|
//
|
||||||
// for (const pixel of pixels) {
|
// document.addEventListener('mouseup', () => {
|
||||||
// pixel.addEventListener('mouseenter', () => {
|
// isPainting = false;
|
||||||
// if (isPainting) {
|
// });
|
||||||
// paintPixel(event.target);
|
//
|
||||||
// }
|
// const pixels = document.querySelectorAll('.pixel');
|
||||||
// });
|
//
|
||||||
// }
|
// for (const pixel of pixels) {
|
||||||
} |
// pixel.addEventListener('mouseenter', () => {
|
||||||
|
// if (isPainting) {
|
||||||
const drawPalette = function() { |
// paintPixel(event.target);
|
||||||
const palette = document.querySelector('#palette'); |
// }
|
||||||
|
// });
|
||||||
const colorClasses = [ |
// }
|
||||||
'carmine-red', |
|
||||||
'coral-red', |
|
||||||
'pastel-red', |
|
||||||
'tigers-eye-orange', |
|
||||||
'pastel-orange', |
|
||||||
'topaz-orange', |
|
||||||
'sandstorm-yellow', |
|
||||||
'lemon-yellow', |
|
||||||
'pastel-yellow', |
|
||||||
'lime-green', |
|
||||||
'ufo-green', |
|
||||||
'mint-green', |
|
||||||
'cerulean-blue', |
|
||||||
'ultramarine-blue', |
|
||||||
'carolina-blue', |
|
||||||
'purple-heart', |
|
||||||
'lavender-indigo', |
|
||||||
'bright-lavender', |
|
||||||
'bruise-purple', |
|
||||||
'heliotrope-purple', |
|
||||||
'lavender-magenta', |
|
||||||
'black-black', |
|
||||||
'drab-black', |
|
||||||
'dim-gray', |
|
||||||
'manatee-gray', |
|
||||||
'pastel-gray', |
|
||||||
'white-white', |
|
||||||
'bistre-brown', |
|
||||||
'noir-brown', |
|
||||||
'bole-brown', |
|
||||||
'chestnut-brown', |
|
||||||
'grullo-brown' |
|
||||||
]; |
|
||||||
|
|
||||||
let color; |
|
||||||
|
|
||||||
for (const colorClass of colorClasses) { |
|
||||||
color = document.createElement('div'); |
|
||||||
color.classList.add('color', colorClass); |
|
||||||
palette.appendChild(color); |
|
||||||
} |
} |
||||||
|
|
||||||
const heading = document.createElement('h2'); |
const drawPalette = function() { |
||||||
heading.textContent = 'BRUSH COLOR >'; |
const palette = document.querySelector('#palette'); |
||||||
|
|
||||||
|
const colorClasses = [ |
||||||
|
'carmine-red', |
||||||
|
'coral-red', |
||||||
|
'pastel-red', |
||||||
|
'tigers-eye-orange', |
||||||
|
'pastel-orange', |
||||||
|
'topaz-orange', |
||||||
|
'sandstorm-yellow', |
||||||
|
'lemon-yellow', |
||||||
|
'pastel-yellow', |
||||||
|
'lime-green', |
||||||
|
'ufo-green', |
||||||
|
'mint-green', |
||||||
|
'cerulean-blue', |
||||||
|
'ultramarine-blue', |
||||||
|
'carolina-blue', |
||||||
|
'purple-heart', |
||||||
|
'lavender-indigo', |
||||||
|
'bright-lavender', |
||||||
|
'bruise-purple', |
||||||
|
'heliotrope-purple', |
||||||
|
'lavender-magenta', |
||||||
|
'black-black', |
||||||
|
'drab-black', |
||||||
|
'dim-gray', |
||||||
|
'manatee-gray', |
||||||
|
'pastel-gray', |
||||||
|
'white-white', |
||||||
|
'bistre-brown', |
||||||
|
'noir-brown', |
||||||
|
'bole-brown', |
||||||
|
'chestnut-brown', |
||||||
|
'grullo-brown' |
||||||
|
]; |
||||||
|
|
||||||
|
for (const colorClass of colorClasses) { |
||||||
|
const color = document.createElement('div'); |
||||||
|
color.classList.add('color', colorClass); |
||||||
|
palette.appendChild(color); |
||||||
|
} |
||||||
|
|
||||||
const brush = document.createElement('div'); |
const heading = document.createElement('h2'); |
||||||
brush.classList.add('brush', brushClass); |
heading.textContent = 'BRUSH COLOR >'; |
||||||
|
|
||||||
palette.appendChild(heading); |
const brushIndicator = document.createElement('div'); |
||||||
palette.appendChild(brush); |
brushIndicator.classList.add('brushIndicator', brushClass); |
||||||
|
|
||||||
palette.addEventListener('click', (event) => { |
palette.appendChild(heading); |
||||||
if (event.target === palette) { |
palette.appendChild(brushIndicator); |
||||||
return; |
|
||||||
} |
palette.addEventListener('click', (event) => { |
||||||
|
if (event.target === palette) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
brushClass = event.target.classList.item(1); |
brushClass = event.target.classList.item(1); |
||||||
|
|
||||||
brush.classList.remove(brush.classList.item(1)); |
brushIndicator.classList.remove(brushIndicator.classList.item(1)); |
||||||
brush.classList.add(brushClass); |
brushIndicator.classList.add(brushClass); |
||||||
}); |
}); |
||||||
} |
} |
||||||
|
|
||||||
drawCanvas(); |
drawCanvas(); |
||||||
drawPalette(); |
drawPalette(); |
||||||
|
})(); |
||||||
|
Loading…
Reference in new issue