Compare commits

..

2 Commits

Author SHA1 Message Date
Flatlogic Bot
ba8aa7e73b snake final 2025-09-17 20:47:11 +00:00
Flatlogic Bot
68527227eb feat: snake color now changes dynamically based on position 2025-09-17 20:45:31 +00:00

View File

@ -67,7 +67,6 @@ document.addEventListener('DOMContentLoaded', () => {
document.body.classList.toggle('dark-theme', theme === 'dark');
themeToggle.checked = theme === 'dark';
localStorage.setItem('snakeTheme', theme);
draw();
}
settingsBtn.addEventListener('click', openSettings);
@ -113,14 +112,14 @@ document.addEventListener('DOMContentLoaded', () => {
}
function draw() {
const accentColor = getComputedStyle(document.body).getPropertyValue('--accent-color').trim();
const canvasBg = getComputedStyle(document.body).getPropertyValue('--canvas-bg').trim();
ctx.fillStyle = canvasBg;
ctx.fillRect(0, 0, canvas.width, canvas.height);
snake.forEach((segment, index) => {
ctx.fillStyle = accentColor;
const hue = (segment.x * 5 + segment.y * 5) % 360;
ctx.fillStyle = `hsl(${hue}, 100%, 50%)`;
if (index === 0) {
ctx.fillRect(segment.x * gridSize, segment.y * gridSize, gridSize, gridSize);
} else {
@ -238,5 +237,6 @@ document.addEventListener('DOMContentLoaded', () => {
if ((key === 'ArrowRight' || key.toLowerCase() === 'd') && direction !== 'left') direction = 'right';
});
placeFood();
draw();
});