Animation added

This commit is contained in:
2025-11-20 23:38:31 -05:00
parent 9197e464a5
commit cf010974dd
8 changed files with 304 additions and 22 deletions

View File

@@ -131,9 +131,39 @@ async function downloadMaze() {
}
try {
window.open(`${API_BASE}/download/${currentMazeId}?solution=false`, '_blank');
showSuccess('Downloading maze image...');
// Create a temporary link and trigger download
const downloadUrl = `${API_BASE}/download/${currentMazeId}?solution=false&format=png`;
const response = await fetch(downloadUrl);
if (!response.ok) {
const errorData = await response.json().catch(() => ({ error: 'Download failed' }));
throw new Error(errorData.error || `Server returned ${response.status}`);
}
const blob = await response.blob();
// Verify we got an image
if (!blob.type.startsWith('image/')) {
throw new Error('Invalid response: not an image');
}
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `maze_${currentMazeId}_${currentMazeData.algorithm.replace(/[^a-z0-9]/gi, '_')}.png`;
document.body.appendChild(a);
a.click();
// Clean up after a short delay
setTimeout(() => {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 100);
showSuccess('Maze image downloaded!');
} catch (error) {
console.error('Download error:', error);
showError('Failed to download: ' + error.message);
}
}

View File

@@ -53,15 +53,15 @@
</div>
<button id="generateBtn" class="btn btn-primary">
1. GENERATE MAZE
GENERATE MAZE
</button>
<!-- Solving Controls -->
<button id="solveDfsBtn" class="btn btn-secondary">
6. SOLVE (DFS)
SOLVE (DFS)
</button>
<button id="solveBfsBtn" class="btn btn-secondary">
7. SOLVE (BFS)
SOLVE (BFS)
</button>
<!-- Animation Controls -->
@@ -83,22 +83,22 @@
<!-- Action Buttons -->
<button id="visualizeBtn" class="btn btn-accent">
2. VISUALIZE
VISUALIZE
</button>
<button id="downloadBtn" class="btn btn-accent">
3. DOWNLOAD IMAGE
DOWNLOAD IMAGE
</button>
<button id="saveBtn" class="btn btn-accent">
4. SAVE TO FILE
SAVE TO FILE
</button>
<button id="loadBtn" class="btn btn-accent">
5. LOAD FROM FILE
LOAD FROM FILE
</button>
<button id="analyzeBtn" class="btn btn-accent">
8. ANALYZE MAZE
ANALYZE MAZE
</button>
<button id="benchmarkBtn" class="btn btn-accent">
9. BENCHMARK
BENCHMARK
</button>
</div>