-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
68 lines (51 loc) · 1.61 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
let grid = document.querySelector(".container");
let colorPick = document.getElementById("myColor").value;
grid.style.display = "grid";
gridItem = document.getElementsByClassName("grid-item");
let cells = [...gridItem];
//make grids
function makeGrids(gridSize = 16){
for (i=0;i<gridSize**2;i++){
grid.style.gridTemplateColumns = "repeat("+gridSize+",auto)";
grid.style.gridTemplateRows = "repeat("+gridSize+",auto)";
let cell = document.createElement("div");
grid.appendChild(cell).className = "grid-item";
};
gridItem = document.getElementsByClassName("grid-item");
let cells = [...gridItem];
let mouse;
//trail
for (let i = 0;i<cells.length;i++){
cells[i].addEventListener("dblclick",startPainting);
cells[i].addEventListener("mouseout",trail);
cells[i].addEventListener("click",stopPainting);
function startPainting(){
mouse = "drawing";
}
function trail(e){
if (mouse == "drawing"){
cells[i].style.backgroundColor = colorPick;
}
}
function stopPainting(e){
mouse = "notDrawing"
cells[i].style.backgroundColor = colorPick;
}
cells[i].addEventListener("mouseover",currentpos);
function currentpos(){
if (mouse == "drawing"){
cells[i].style.backgroundColor = "cyan";
}
}
}
}
let size = prompt("how big grid do you want?");
makeGrids(size);
let body = document.querySelector("body");
body.addEventListener("mousemove",function(e){
body.style.backgroundColor = "rgb("+e.layerX+","+e.layerY+",123)";
})
function changeColor(){
colorPick = document.getElementById("myColor").value;
console.log(colorPick);
}