|
|
|
@ -1,3 +1,4 @@ |
|
|
|
|
(function() { |
|
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
let brushClass = 'drab-black'; |
|
|
|
@ -9,10 +10,9 @@ const paintPixel = function(pixel) { |
|
|
|
|
|
|
|
|
|
const drawCanvas = function() { |
|
|
|
|
const canvas = document.querySelector('#canvas'); |
|
|
|
|
let pixel; |
|
|
|
|
|
|
|
|
|
for (let i = 0; i < 2013; i++) { |
|
|
|
|
pixel = document.createElement('div'); |
|
|
|
|
const pixel = document.createElement('div'); |
|
|
|
|
pixel.classList.add('pixel'); |
|
|
|
|
canvas.appendChild(pixel); |
|
|
|
|
} |
|
|
|
@ -25,7 +25,8 @@ const drawCanvas = function() { |
|
|
|
|
paintPixel(event.target); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// or...
|
|
|
|
|
// Bonus 1 - paintbrush
|
|
|
|
|
//
|
|
|
|
|
// let isPainting = false;
|
|
|
|
|
//
|
|
|
|
|
// canvas.addEventListener('mousedown', () => {
|
|
|
|
@ -38,7 +39,7 @@ const drawCanvas = function() { |
|
|
|
|
// paintPixel(event.target);
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
|
// canvas.addEventListener('mouseup', () => {
|
|
|
|
|
// document.addEventListener('mouseup', () => {
|
|
|
|
|
// isPainting = false;
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
@ -91,10 +92,8 @@ const drawPalette = function() { |
|
|
|
|
'grullo-brown' |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
let color; |
|
|
|
|
|
|
|
|
|
for (const colorClass of colorClasses) { |
|
|
|
|
color = document.createElement('div'); |
|
|
|
|
const color = document.createElement('div'); |
|
|
|
|
color.classList.add('color', colorClass); |
|
|
|
|
palette.appendChild(color); |
|
|
|
|
} |
|
|
|
@ -102,11 +101,11 @@ const drawPalette = function() { |
|
|
|
|
const heading = document.createElement('h2'); |
|
|
|
|
heading.textContent = 'BRUSH COLOR >'; |
|
|
|
|
|
|
|
|
|
const brush = document.createElement('div'); |
|
|
|
|
brush.classList.add('brush', brushClass); |
|
|
|
|
const brushIndicator = document.createElement('div'); |
|
|
|
|
brushIndicator.classList.add('brushIndicator', brushClass); |
|
|
|
|
|
|
|
|
|
palette.appendChild(heading); |
|
|
|
|
palette.appendChild(brush); |
|
|
|
|
palette.appendChild(brushIndicator); |
|
|
|
|
|
|
|
|
|
palette.addEventListener('click', (event) => { |
|
|
|
|
if (event.target === palette) { |
|
|
|
@ -115,10 +114,11 @@ const drawPalette = function() { |
|
|
|
|
|
|
|
|
|
brushClass = event.target.classList.item(1); |
|
|
|
|
|
|
|
|
|
brush.classList.remove(brush.classList.item(1)); |
|
|
|
|
brush.classList.add(brushClass); |
|
|
|
|
brushIndicator.classList.remove(brushIndicator.classList.item(1)); |
|
|
|
|
brushIndicator.classList.add(brushClass); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
drawCanvas(); |
|
|
|
|
drawPalette(); |
|
|
|
|
})(); |
|
|
|
|