-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualizer.js
175 lines (142 loc) · 6.23 KB
/
visualizer.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
let running = false;
const ib = document.querySelector(".importButton");
const exb = document.querySelector(".exportButton");
const sb = document.querySelector(".run");
const rb = document.querySelector(".reset");
const tb = document.querySelector(".test");
const pb = document.querySelector(".stop");
const plb = document.querySelector(".resume");
const canvas = document.querySelector("canvas");
const ctx = canvas.getContext('2d');
const score = document.querySelector(".scoreAmount");
const tableDiv = document.querySelector(".table")
const editor = document.querySelector(".editor")
const table = document.querySelector(".agentTable tbody")
const agentStuff = document.querySelector(".agentStuff")
const simulationNum = document.querySelector(".simulationNum")
const frameTimeInput = document.querySelector("input.frameTime")
const frameTimeHeader = document.querySelector("span.frameTime")
const renderButton = document.querySelector(".rCanvas")
const getTimeBetweenFrames = () => { return frameTimeInput.value }
frameTimeInput.addEventListener("input", () => { frameTimeHeader.textContent = getTimeBetweenFrames() })
const setScore = (amount) => { score.textContent = amount }
const clearCanvas = () => { ctx.clearRect(0, 0, canvas.width, canvas.height); }
const frameSetting = document.querySelector("span.frameSetting")
frameSetting.textContent = "0";
const iterationSetting = document.querySelector("span.iterationSetting")
iterationSetting.textContent = "0";
const bestAgentSetting = document.querySelector("span.bestAgentSetting")
bestAgentSetting.textContent = "0";
const avgFrameSetting = document.querySelector("span.avgFrameSetting")
avgFrameSetting.textContent = "0";
const avgScoreSetting = document.querySelector("span.avgScoreSetting")
let paused = false;
avgScoreSetting.textContent = "0";
canvas.width = Number(window.getComputedStyle(canvas).getPropertyValue('width').split("px")[0])
canvas.height = Number(window.getComputedStyle(canvas).getPropertyValue('height').split("px")[0])
tableDiv.style.height = canvas.height + "px"
const showFrame = document.querySelector(".rFrames")
showFrame.addEventListener("change", () => {
if (frameSetting.parentElement.style.display === "none") frameSetting.parentElement.style.display = "block";
else frameSetting.parentElement.style.display = "none";
})
const showIterations = document.querySelector(".rIterations")
showIterations.addEventListener("change", () => {
if (iterationSetting.parentElement.style.display === "none") iterationSetting.parentElement.style.display = "block";
else iterationSetting.parentElement.style.display = "none";
})
const showAvgFrame = document.querySelector(".rAvgFrames")
showAvgFrame.addEventListener("change", () => {
if (avgFrameSetting.parentElement.style.display === "none") avgFrameSetting.parentElement.style.display = "block";
else avgFrameSetting.parentElement.style.display = "none";
})
const showBestAgent = document.querySelector(".rBestAgent")
showBestAgent.addEventListener("change", () => {
if (bestAgentSetting.parentElement.style.display === "none") bestAgentSetting.parentElement.style.display = "block";
else bestAgentSetting.parentElement.style.display = "none";
})
const showAvgScore = document.querySelector(".rAvgScore")
showAvgScore.addEventListener("change", () => {
console.log(avgScoreSetting.parentElement.style.display)
if (avgScoreSetting.parentElement.style.display === "none") avgScoreSetting.parentElement.style.display = "block";
else avgScoreSetting.parentElement.style.display = "none";
})
const renderCanvas = document.querySelector(".rCanvas")
const eye = document.querySelector(".eye")
console.log(eye.style.width)
renderCanvas.addEventListener('click', () => {
if (renderCanvas.checked) {
eye.style.display = "none"
canvas.classList.remove("disabled")
}
else {
eye.style.display = "block"
canvas.classList.add("disabled")
eye.style.left = canvas.offsetLeft + (canvas.width / 2) - 150 / 2 + "px"
eye.style.top = canvas.offsetTop + (canvas.height / 2) - 150 / 2 + "px"
}
})
console.log(tf.getBackend())
function autoExpand(textarea) {
textarea.style.height = 'auto';
textarea.style.height = textarea.scrollHeight + 'px';
}
document.getElementById("defaultOpen").click();
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
const modal = document.getElementById("createNew");
const btn = document.querySelector(".modal-button");
const span = document.querySelector(".close");
const cancel = document.querySelector(".close-modal")
cancel.onclick = function() {
modal.style.display = "none";
}
btn.onclick = function() {
modal.style.display = "block";
}
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
const select = document.getElementById("types");
const edit = document.querySelector(".editor");
const confirmBtn = document.querySelector(".confirm-modal");
confirmBtn.addEventListener("click", () => {
modal.style.display = "none";
createBlock(select.value,edit.childElementCount);
})
function createBlock(type, num) {
let block = document.createElement("div")
block.classList.add("block")
block.classList.add(type)
block.classList.add(num)
let text = document.createElement("div")
text.classList.add("text")
block.appendChild(text)
let header = document.createElement("h1");
header.textContent = type.toUpperCase();
let textArea = document.createElement("textarea")
textArea.setAttribute("oninput","autoExpand(this)")
text.appendChild(header);
text.appendChild(textArea)
editor.appendChild(block)
block.addEventListener("contextmenu", () => {
block.removeChild(block.firstChild);
block.remove();
})
}