-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
273 lines (251 loc) · 7.99 KB
/
index.html
File metadata and controls
273 lines (251 loc) · 7.99 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PATH GUI</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #333;
color: white;
padding: 1em;
text-align: center;
}
#app {
display: flex;
height: 100vh;
overflow: hidden;
}
#canvas-container {
flex: 3;
position: relative;
background: #f0f0f0;
}
canvas {
display: block;
border: 1px solid #ccc;
margin: auto;
}
#controls {
flex: 1;
padding: 1em;
background: #eaeaea;
overflow-y: auto;
}
button {
margin: 0.5em 0;
padding: 0.5em 1em;
cursor: pointer;
background: #007bff;
color: white;
border: none;
border-radius: 4px;
}
button:hover {
background: #0056b3;
}
#output {
margin-top: 1em;
font-family: monospace;
white-space: pre-wrap;
background: #fff;
padding: 0.5em;
border: 1px solid #ccc;
border-radius: 4px;
max-height: 100px;
overflow-y: auto;
}
#waypoint-code {
margin-top: 1em;
font-family: monospace;
white-space: pre-wrap;
background: #fff;
padding: 0.5em;
border: 1px solid #ccc;
border-radius: 4px;
max-height: 200px;
overflow-y: auto;
}
</style>
</head>
<body>
<header>
<h1>Montclair FRC Path GUI</h1>
</header>
<div id="app">
<div id="canvas-container">
<canvas id="plannerCanvas" width="1200" height="600"></canvas>
</div>
<div id="controls">
<h2>Controls</h2>
<button id="toggle-tweak">Enable Tweaking Mode</button>
<button id="clear">Clear Selection</button>
<button onclick=sendAutoString()>PUSH</button>
<h3>Waypoint Sequence</h3>
<div id="output"></div>
<h3>Generated Code for Waypoints</h3>
<button id="generate-code">Generate Waypoint Code</button>
<div id="waypoint-code"></div>
</div>
</div>
<script>
function sendAutoString() {
let autoString = selectedWaypoints.join('');
fetch("http://localhost:8000", {
method: "POST",
headers: { "Content-Type": "text/plain" },
body: autoString
})
.then(response => response.text())
.then(data => console.log("Response:", data))
.catch(error => console.error("Error:", error));
}
</script>
<script>
const canvas = document.getElementById('plannerCanvas');
const ctx = canvas.getContext('2d');
const output = document.getElementById('output');
const waypointCode = document.getElementById('waypoint-code');
const predefinedWaypoints = [
{ id: "1", x: 121, y: 130.125 },
{ id: "2", x: 150, y: 113.125 },
{ id: "3", x: 181, y: 92.125 },
{ id: "4", x: 118, y: 468.125 },
{ id: "5", x: 145, y: 488.125 },
{ id: "6", x: 175, y: 507.125 },
{ id: "S1", x: 518, y: 107.125 },
{ id: "S2", x: 516, y: 245.125 },
{ id: "S3", x: 516, y: 298.125 },
{ id: "S4", x: 518, y: 352.125 },
{ id: "S5", x: 518, y: 497.125 },
{ id: "a", x: 301, y: 311.125 },
{ id: "A", x: 300, y: 287.125 },
{ id: "b", x: 320, y: 256.125 },
{ id: "B", x: 340, y: 247.125 },
{ id: "c", x: 375, y: 246.125 },
{ id: "C", x: 398, y: 258.125 },
{ id: "d", x: 418, y: 285.125 },
{ id: "D", x: 416, y: 313.125 },
{ id: "e", x: 402, y: 341.125 },
{ id: "E", x: 378, y: 354.125 },
{ id: "f", x: 342, y: 356.125 },
{ id: "F", x: 320, y: 344.125 },
];
let selectedWaypoints = [];
let renderWaypoints = [];
let tweakingMode = false;
let draggingWaypoint = null;
const fieldImage = new Image();
fieldImage.src = 'https://lh3.googleusercontent.com/pw/AP1GczNS3jp1GGMGcutugRuk_jJedvIXzUh-UtLmJmfoOnhEgrTC6iVNxFFsqYrgR6Oj-hFmqTxG4fMMHV5PVP9dfTklGLayMINvMEM4bFH7WHLBEHw_ZwPw=w600-h315-p-k';
fieldImage.onload = () => redrawCanvas();
function drawCircle(x, y, color = 'blue', label = '') {
ctx.beginPath();
ctx.arc(x, y, 10, 0, Math.PI * 2);
ctx.fillStyle = color;
ctx.fill();
ctx.closePath();
if (label) {
ctx.font = '12px Arial';
ctx.fillStyle = 'white';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(label, x, y);
}
}
function drawLine(x1, y1, x2, y2) {
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.strokeStyle = 'green';
ctx.lineWidth = 2;
ctx.stroke();
ctx.closePath();
}
function redrawCanvas() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(fieldImage, 0, 0, canvas.width, canvas.height);
for (let i = 0; i < renderWaypoints.length - 1; i++) {
const wp1 = predefinedWaypoints.find(wp => wp.id === renderWaypoints[i]);
const wp2 = predefinedWaypoints.find(wp => wp.id === renderWaypoints[i + 1]);
if (wp1 && wp2) drawLine(wp1.x, wp1.y, wp2.x, wp2.y);
}
predefinedWaypoints.forEach(wp => {
const color = renderWaypoints.includes(wp.id) ? 'green' : 'blue';
drawCircle(wp.x, wp.y, color, wp.id);
});
}
function getClickedWaypoint(x, y) {
return predefinedWaypoints.find(wp => Math.hypot(wp.x - x, wp.y - y) <= 10);
}
function updateOutput() {
output.textContent = selectedWaypoints.join('');
}
function generateWaypointCode() {
const code = `const predefinedWaypoints = ${JSON.stringify(predefinedWaypoints, null, 2)};`;
waypointCode.textContent = code;
}
canvas.addEventListener('mousedown', e => {
if (!tweakingMode) return;
const rect = canvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
draggingWaypoint = getClickedWaypoint(x, y);
});
canvas.addEventListener('mousemove', e => {
if (draggingWaypoint) {
const rect = canvas.getBoundingClientRect();
draggingWaypoint.x = e.clientX - rect.left;
draggingWaypoint.y = e.clientY - rect.top;
redrawCanvas();
}
});
canvas.addEventListener('mouseup', () => (draggingWaypoint = null));
canvas.addEventListener('click', e => {
if (tweakingMode) return;
const rect = canvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const clickedWaypoint = getClickedWaypoint(x, y);
if (clickedWaypoint) {
if (['a', 'A', 'b', 'B', 'c', 'C', 'd', 'D', 'e', 'E', 'f', 'F'].includes(clickedWaypoint.id)) {
let level = prompt(`Enter a level for ${clickedWaypoint.id} (1-4):`);
level = parseInt(level, 10);
if (level >= 1 && level <= 4) {
selectedWaypoints.push(`${clickedWaypoint.id}${level}`);
renderWaypoints.push(clickedWaypoint.id);
} else {
alert('Invalid level! Please enter a number between 1 and 4.');
return;
}
} else {
selectedWaypoints.push(clickedWaypoint.id);
renderWaypoints.push(clickedWaypoint.id);
}
redrawCanvas();
updateOutput();
}
});
document.getElementById('clear').addEventListener('click', () => {
selectedWaypoints = [];
renderWaypoints = [];
redrawCanvas();
updateOutput();
});
document.getElementById('copy').addEventListener('click', () => {
navigator.clipboard
.writeText(selectedWaypoints.join(''))
.catch(() => alert('Failed to copy!'));
});
document.getElementById('toggle-tweak').addEventListener('click', () => {
tweakingMode = !tweakingMode;
alert(tweakingMode ? 'Tweaking mode enabled.' : 'Tweaking mode disabled.');
});
document.getElementById('generate-code').addEventListener('click', generateWaypointCode);
</script>
</body>
</html>