-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
434 lines (385 loc) · 15.8 KB
/
index.html
File metadata and controls
434 lines (385 loc) · 15.8 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@3.4.1/dist/tailwind.min.css" rel="stylesheet">
<title>Interactive Cartesian Plane with Lines</title>
<link rel="stylesheet" href="styles.css" />
<style>
/* Simple tab styles */
.tabs {
display: flex;
border-bottom: 2px solid #ccc;
margin-bottom: 1rem;
margin-top: 1rem;
justify-content: center; /* center the tabs */
}
.tab {
padding: 10px 20px;
border: 2px solid transparent;
border-bottom: none;
cursor: pointer;
margin-right: 0.5rem;
user-select: none;
}
.tab.active {
border-color: #3b82f6 #3b82f6 white; /* Tailwind blue-500 */
font-weight: bold;
color: #3b82f6;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
#instructions {
text-align: left;
max-width: 800px;
margin: 0 auto;
margin-top: 20px;
}
#controls {
text-align: center;
margin-bottom: 1rem;
}
#controlsAutomatic {
align-items: center;
text-align: center;
margin-bottom: 1rem;
}
#canvas {
display: block;
margin: 0 auto;
border: 1px solid #ccc;
background: #fff;
}
#canvasAutomatic {
display: block;
margin: 0 auto;
border: 1px solid #ccc;
background: #fff;
}
</style>
</head>
<body>
<div class="flex flex-col items-center">
<div id="instructions">
<strong>Instructions:</strong><br>
- Use <b>Draw Line</b> button to draw lines.<br>
- Toggle <b>Arrow Lines</b> for arrows.<br>
- Right-click a line to delete it.<br>
- Drag endpoints or whole line to move it.<br>
- Pan by touch drag, or with right/middle mouse drag.<br>
- Zoom with mouse wheel.<br>
- Press Ctrl+Z to undo.
</div>
<!-- Tabs placed right after instructions -->
<div class="tabs">
<div id="tabManual" class="tab active">Manual</div>
<div id="tabAutomatic" class="tab">Automatic</div>
</div>
<!-- Manual Tab Content -->
<div id="contentManual" class="tab-content active">
<div id="controls">
<button id="drawModeBtn">Draw Line</button>
<button id="arrowToggleBtn">Arrow Lines: OFF</button>
<label>Line Color: <input type="color" id="colorPicker" value="#008000"></label>
<button id="fullscreenBtn" title="Toggle Fullscreen" aria-label="Toggle Fullscreen">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M8 3H5a2 2 0 0 0-2 2v3"/>
<path d="M16 3h3a2 2 0 0 1 2 2v3"/>
<path d="M8 21H5a2 2 0 0 1-2-2v-3"/>
<path d="M16 21h3a2 2 0 0 0 2-2v-3"/>
</svg>
</button>
<!-- ADD THIS BUTTON FOR DRAWING TRIANGLE -->
<button id="drawTriangleBtn">Draw Triangle</button>
<label>Triangle Color: <input type="color" id="triangleColorPicker" value="#ff0000"></label>
<button id="spaceOptBtn">Space Optimization</button>
</div>
<canvas id="canvas" width="800" height="800"></canvas>
<div id="triangleError" style="color:#900; margin-top:10px;"></div>
<div id="enjoy" style="text-align: center;">
<p>Savour!</p>
</div>
<ul id="triangleContextMenu" style="
display: none;
position: absolute;
background: white;
border: 1px solid #ccc;
box-shadow: 2px 2px 8px rgba(0,0,0,0.2);
list-style: none;
padding: 0;
margin: 0;
z-index: 1000;
font-family: sans-serif;
">
<li id="copyTriangle" style="padding: 8px 12px; cursor: pointer; border-bottom: 1px solid #eee;">📋 Copy & Paste</li>
<li id="deleteTriangle" style="padding: 8px 12px; cursor: pointer;">🗑️ Delete</li>
</ul>
<!-- MODAL FOR TRIANGLE SIDES INPUT -->
<div id="triangleModal" style="display:none; position:fixed; top:20%; left:50%; transform:translateX(-50%); background:#fff; border:1px solid #ccc; padding:20px; z-index:2000; width:300px; box-shadow:0 4px 10px rgba(0,0,0,0.2);">
<h3>Create Triangle</h3>
<label>
Method:
<select id="triangleMethod">
<option value="SSS">SSS (3 sides)</option>
<option value="SAS">SAS (2 sides + angle)</option>
<option value="AAS">AAS (2 angles + side)</option>
</select>
</label>
<div id="triangleInputs" style="margin-top:10px;"></div>
<div style="margin-top:10px; text-align:right;">
<button id="createTriangleBtn">Create</button>
<button id="cancelTriangleBtn">Cancel</button>
</div>
</div>
<div id="coordTooltip"></div>
<div id="contextMenu">
<button id="deleteLineBtn">Delete Line</button>
</div>
<div id="errorContainer"></div>
</div>
<!-- Automatic Tab Content -->
<div id="contentAutomatic" class="tab-content">
<div id="controlsAutomatic">
<button id="drawModeBtnAutomatic">Draw Line</button>
<button id="arrowToggleBtnAutomatic">Arrow Lines: OFF</button>
<label>Line Color: <input type="color" id="colorPickerAutomatic" value="#008000"></label>
<button id="fullscreenBtnAutomatic" title="Toggle Fullscreen" aria-label="Toggle Fullscreen">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M8 3H5a2 2 0 0 0-2 2v3"/>
<path d="M16 3h3a2 2 0 0 1 2 2v3"/>
<path d="M8 21H5a2 2 0 0 1-2-2v-3"/>
<path d="M16 21h3a2 2 0 0 0 2-2v-3"/>
</svg>
</button>
<!-- ADD THIS BUTTON FOR DRAWING TRIANGLE -->
<button id="drawTriangleAutomaticBtn">Draw Triangle</button>
<label>Triangle Color: <input type="color" id="triangleColorPickerAutomatic" value="#ff0000"></label>
<button id="spaceOptBtnAutomatic">Space Optimization</button>
</div>
<canvas id="canvasAutomatic" width="800" height="800"></canvas>
<div id="triangleErrorAutomatic" style="color:#900; margin-top:10px;"></div>
<div id="enjoyAutomatic" style="text-align: center;">
<p>Savour!</p>
</div>
<ul id="triangleContextMenuAutomatic" style="
display: none;
position: absolute;
background: white;
border: 1px solid #ccc;
box-shadow: 2px 2px 8px rgba(0,0,0,0.2);
list-style: none;
padding: 0;
margin: 0;
z-index: 1000;
font-family: sans-serif;
">
<li id="copyTriangleAutomatic" style="padding: 8px 12px; cursor: pointer; border-bottom: 1px solid #eee;">📋 Copy & Paste</li>
<li id="deleteTriangleAutomatic" style="padding: 8px 12px; cursor: pointer;">🗑️ Delete</li>
</ul>
<!-- MODAL FOR TRIANGLE SIDES INPUT -->
<div id="triangleModalAutomatic" style="display:none; position:fixed; top:20%; left:50%; transform:translateX(-50%); background:#fff; border:1px solid #ccc; padding:20px; z-index:2000; width:300px; box-shadow:0 4px 10px rgba(0,0,0,0.2);">
<!-- Triangle Type Choice Modal -->
<div id="triangleTypeModal" style="display:none; position:fixed; top:25%; left:50%; transform:translateX(-50%); background:#fff; border:1px solid #ccc; padding:20px; z-index:3000; width:320px; box-shadow:0 4px 10px rgba(0,0,0,0.2);">
<h3>Triangle Type</h3>
<p>Are your triangles homogeneous or heterogeneous?</p>
<div style="display:flex; justify-content:space-between; margin-top:15px;">
<button id="homogeneousBtn" class="px-4 py-2 bg-blue-500 text-white rounded">Homogeneous</button>
<button id="heterogeneousBtn" class="px-4 py-2 bg-green-500 text-white rounded">Heterogeneous</button>
</div>
</div>
<!-- Heterogeneous Triangle Count Input -->
<div id="heteroTriangleCountModal" style="display:none; position:fixed; top:25%; left:50%; transform:translateX(-50%); background:#fff; border:1px solid #ccc; padding:20px; z-index:3000; width:300px; box-shadow:0 4px 10px rgba(0,0,0,0.2);">
<h3>How many triangles?</h3>
<input type="number" id="heteroTriangleCountInput" min="1" class="border px-2 py-1 w-full" />
<div style="text-align:right; margin-top:10px;">
<button id="confirmTriangleCount" class="bg-blue-500 text-white px-4 py-2 rounded">Next</button>
<button id="cancelTriangleCount" class="ml-2 text-gray-600 px-4 py-2">Cancel</button>
</div>
</div>
<!-- Dynamic Triangle Entry Modal -->
<div id="heteroTriangleEntryModal" style="display:none; position:fixed; top:10%; left:50%; transform:translateX(-50%); background:#fff; border:1px solid #ccc; padding:20px; z-index:3000; width:400px; max-height:80vh; overflow-y:auto; box-shadow:0 4px 10px rgba(0,0,0,0.2);">
<h3>Enter Triangle Details</h3>
<div id="heteroTriangleInputsContainer"></div>
<div style="text-align:right; margin-top:10px;">
<button id="createHeteroTriangles" class="bg-green-600 text-white px-4 py-2 rounded">Create</button>
<button id="cancelHeteroTriangles" class="ml-2 text-gray-600 px-4 py-2">Cancel</button>
</div>
</div>
<h3>Create Triangle</h3>
<label>
Method:
<select id="triangleMethodAutomatic">
<option value="SSS">SSS (3 sides)</option>
<option value="SAS">SAS (2 sides + angle)</option>
<option value="AAS">AAS (2 angles + side)</option>
</select>
</label>
<div id="triangleInputsAutomatic" style="margin-top:10px;"></div>
<div style="margin-top:10px; text-align:right;">
<button id="createTriangleAutomaticBtn">Create</button>
<button id="cancelTriangleAutomaticBtn">Cancel</button>
</div>
</div>
<div id="coordTooltipAutomatic"></div>
<div id="contextMenuAutomatic">
<button id="deleteLineBtnAutomatic">Delete Line</button>
</div>
<div id="errorContainerAutomatic"></div>
</div>
</div>
<script>
const tabManual = document.getElementById('tabManual');
const tabAutomatic = document.getElementById('tabAutomatic');
const contentManual = document.getElementById('contentManual');
const contentAutomatic = document.getElementById('contentAutomatic');
let manualScriptLoaded = false;
let automaticScriptLoaded = false;
function loadScript(src, callback) {
const script = document.createElement('script');
script.src = src;
script.onload = callback;
document.body.appendChild(script);
}
// Manual Tab click
tabManual.addEventListener('click', () => {
tabManual.classList.add('active');
tabAutomatic.classList.remove('active');
contentManual.classList.add('active');
contentAutomatic.classList.remove('active');
if (!manualScriptLoaded) {
loadScript('shapes.js', () => {
console.log('Manual shapes.js loaded');
manualScriptLoaded = true;
loadScript('canvas.js', () => {
console.log('Manual canvas.js loaded');
});
});
}
});
// Automatic Tab click
tabAutomatic.addEventListener('click', () => {
tabAutomatic.classList.add('active');
tabManual.classList.remove('active');
contentAutomatic.classList.add('active');
contentManual.classList.remove('active');
if (!automaticScriptLoaded) {
loadScript('shapesAutomatic.js', () => {
console.log('Automatic shapesAutomatic.js loaded');
automaticScriptLoaded = true;
loadScript('canvasAutomatic.js', () => {
console.log('Automatic canvasAutomatic.js loaded');
});
});
}
});
// Optional: preload Manual tab scripts on page load
window.addEventListener('DOMContentLoaded', () => {
loadScript('shapes.js', () => {
manualScriptLoaded = true;
loadScript('canvas.js', () => {
console.log('Manual scripts preloaded');
});
});
});
</script>
<script>
document.getElementById("spaceOptBtnAutomatic").addEventListener("click", () => {
document.getElementById("triangleTypeModal").style.display = "block";
});
// Handle triangle type choice
document.getElementById("homogeneousBtn").addEventListener("click", () => {
document.getElementById("triangleTypeModal").style.display = "none";
alert("Proceeding with homogeneous triangle logic.");
// 👇 Insert or trigger your existing homogeneous logic here
});
document.getElementById("heterogeneousBtn").addEventListener("click", () => {
document.getElementById("triangleTypeModal").style.display = "none";
document.getElementById("heteroTriangleCountModal").style.display = "block";
});
// Cancel count modal
document.getElementById("cancelTriangleCount").addEventListener("click", () => {
document.getElementById("heteroTriangleCountModal").style.display = "none";
});
// Confirm triangle count input
document.getElementById("confirmTriangleCount").addEventListener("click", () => {
const count = parseInt(document.getElementById("heteroTriangleCountInput").value);
const container = document.getElementById("heteroTriangleInputsContainer");
container.innerHTML = ""; // Clear old inputs
if (count > 0) {
for (let i = 0; i < count; i++) {
const group = document.createElement("div");
group.className = "mb-4 border-b pb-4";
group.innerHTML = `
<label class="block font-bold">Triangle ${i + 1}</label>
<select class="methodSelector mb-2 w-full border p-1">
<option value="SSS">SSS (3 sides)</option>
<option value="SAS">SAS (2 sides + angle)</option>
<option value="AAS">AAS (2 angles + side)</option>
</select>
<div class="inputFields space-y-1"></div>
`;
container.appendChild(group);
}
document.querySelectorAll(".methodSelector").forEach(selector => {
selector.addEventListener("change", e => {
const inputFields = e.target.parentElement.querySelector(".inputFields");
inputFields.innerHTML = "";
switch (e.target.value) {
case "SSS":
inputFields.innerHTML = `
<input placeholder="Side a" class="w-full border p-1" />
<input placeholder="Side b" class="w-full border p-1" />
<input placeholder="Side c" class="w-full border p-1" />
`;
break;
case "SAS":
inputFields.innerHTML = `
<input placeholder="Side a" class="w-full border p-1" />
<input placeholder="Angle (deg)" class="w-full border p-1" />
<input placeholder="Side b" class="w-full border p-1" />
`;
break;
case "AAS":
inputFields.innerHTML = `
<input placeholder="Angle A (deg)" class="w-full border p-1" />
<input placeholder="Angle B (deg)" class="w-full border p-1" />
<input placeholder="Side c" class="w-full border p-1" />
`;
break;
}
});
selector.dispatchEvent(new Event("change")); // initialize
});
document.getElementById("heteroTriangleCountModal").style.display = "none";
document.getElementById("heteroTriangleEntryModal").style.display = "block";
}
});
// Cancel triangle entry
document.getElementById("cancelHeteroTriangles").addEventListener("click", () => {
document.getElementById("heteroTriangleEntryModal").style.display = "none";
});
// Collect triangle data on "Create"
document.getElementById("createHeteroTriangles").addEventListener("click", () => {
const triangles = [];
document.querySelectorAll("#heteroTriangleInputsContainer > div").forEach(group => {
const method = group.querySelector(".methodSelector").value;
const inputs = [...group.querySelectorAll(".inputFields input")].map(i => i.value.trim());
triangles.push({ method, values: inputs });
});
console.log("Entered Triangles:", triangles);
// 👇 Now pass this to your geometry engine or visualization logic
// alert("Collected triangle definitions. You can now build them or optimize layout.");
simulateAnnealingPacking(triangles).then(result => {
// display or use the result in your UI
console.log("Packing result:", result);
showPackingResult(result);
});
document.getElementById("heteroTriangleEntryModal").style.display = "none";
});
</script>
</body>
</html>