-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
149 lines (131 loc) · 4.22 KB
/
index.html
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Script Template</title>
<link rel="stylesheet" type="text/css" href="styles/style.css">
</head>
<body>
<div class="leftEtch">
</div>
<div class="bottomEtch">
</div>
<div class="rightEtch">
</div>
<div class="topEtch">
</div>
<div class="nob1">
<p class="up1">↑</p>
</div>
<div class="nob2">
<p class="up2">↓</p>
</div>
<div class="etch etchGrid">
</div>
<div class="button">
<button id="button1">Clear Etch-N-Sketch</button>
</div>
<div class="button">
<button id="button2">Color Mode</button>
</div>
<script>
let gridRef = 0; //how the size of the etch and sketch is kept track of
let x = 1; //our grid size multiplier
let y = ((16*x)*(18*x));
let z = 0; //keeps track of which nob was pressed. -1 for down and +1 for up
let counter = 0;
let mode = 0;
let increaseRow = ("repeat(" + 18*x + ", " + 3.625 /x + "vh);");
let increaseColumn = ("repeat(" + 16*x + ", " + 1.8125 /x + "vw);");
for (let i = 0; i < 288; i++) {
let box = document.createElement('div');
box.classList.add("boxAll");
document.querySelector(".etch").appendChild(box);
}
let scratchPad = document.querySelector(".etch")
scratchPad.onmouseover = function(event) {
let target = event.target;
increaseCounter();
if (mode == 0) {
target.style.background = "black";
} else if (mode == 1) {
if (counter % 10 == 0) {
target.style.background = "black";
} else if (counter % 10 !== 0) {
let a = Math.round((Math.random() * 255));
let b = Math.round((Math.random() * 255));
let c = Math.round((Math.random() * 255));
target.style.backgroundColor = "rgb(" + a + ", " + b + ", " + c + ")";
}
}
}
//code to keep track of whether in color or black mode
document.getElementById("button2").addEventListener("click", function() {
if (mode == 1) {
mode--;
document.getElementById("button2").innerText = "Color Mode";
} else if (mode == 0) {
mode++;
document.getElementById("button2").innerText = "Black Mode";
}
});
//end of code
function increaseCounter() {
counter++;
}
document.getElementById("button1").addEventListener("click", clear);
let boxAll = document.getElementsByClassName('boxAll');
function clear() {
for(let i = 0; i < boxAll.length; i++) {
boxAll[i].style.background = "white";
}
}
function changeGrid() {
while (scratchPad.firstChild) {
scratchPad.removeChild(scratchPad.firstChild);
}
if (z == "nob1") {
gridSizeInc();
} else if (z == "nob2") {
gridSizeDec();
}
gridMultiplier();
increaseCSS();
for (let i = 0; i < y; i++) {
let box = document.createElement('div');
box.classList.add("boxAll");
document.querySelector(".etch").appendChild(box);
}
}
//A way to keep track of current grid multiplier
function gridSizeInc() {
if (gridRef <= 2) {
gridRef++;
}
}
function gridSizeDec() {
if (gridRef >= 0) {
gridRef--;
}
}
function gridMultiplier() {
x = Math.pow(2, gridRef);
increaseRow = ("repeat(" + 18*x + ", " + 3.625 /x + "vh);");
increaseColumn = ("repeat(" + 16*x + ", " + 1.8125 /x + "vw);");
y = ((16*x)*(18*x));
}
//End of grid multiplier
document.querySelector(".nob1").addEventListener("click", function() {
z = this.className;
changeGrid();
});
document.querySelector(".nob2").addEventListener("click", function() {
z = this.className;
changeGrid();
});
function increaseCSS() {
document.querySelector(".etchGrid").style.cssText = ("display: grid; grid-template-rows: " + increaseRow + "; grid-template-columns: " + increaseColumn + ";");
}
</script>
</body>
</html>