-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
68 lines (50 loc) · 1.41 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
const canvasblock = document.querySelector(".canvasblock");
const sizeinput = document.querySelector("input");
function takeSizeInput(){
userSizeInput = +(sizeinput.value);
}
function clearBlock(){
canvasblock.innerHTML='';
}
sizeinput.addEventListener("keypress", function(e){
if (e.key ==="Enter"){
takeSizeInput();
clearBlock();
addGrid();
var allPixels = document.getElementsByClassName("pixel")
function colorPixel (){
this.className = "colored pixel";
}
for (let i=0; i<allPixels.length;i++){
allPixels[i].addEventListener("mouseover", colorPixel);
}
}});
function addGrid(){
for (let i=1 ; i<=userSizeInput ; i++){
addRow();
}
}
function addRow(){
const row = document.createElement("div");
row.className = "row";
for (let i=1; i<=userSizeInput;i++){
const pixel = document.createElement("div");
pixel.className = "pixel";
row.appendChild(pixel);
}
canvasblock.appendChild(row);
}
function clearDrawing(){
//reset pixel background colors
}
// Take user input as number
// clear current canvas
// take side length as n
// (create n divs
// add to a row
// add row to canvasblock)
// repeat n times
// [for i up to n: create one row div, create i to n divs and append to row,
// then append row to canvasblock]
// add n divs
// add n divs to each div