Compare commits
No commits in common. "ba8aa7e73b2757ac9247c86355415d6263418b5b" and "1324f424e4b12613a3c9c278f26823e093cd702a" have entirely different histories.
ba8aa7e73b
...
1324f424e4
@ -67,6 +67,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
document.body.classList.toggle('dark-theme', theme === 'dark');
|
document.body.classList.toggle('dark-theme', theme === 'dark');
|
||||||
themeToggle.checked = theme === 'dark';
|
themeToggle.checked = theme === 'dark';
|
||||||
localStorage.setItem('snakeTheme', theme);
|
localStorage.setItem('snakeTheme', theme);
|
||||||
|
draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
settingsBtn.addEventListener('click', openSettings);
|
settingsBtn.addEventListener('click', openSettings);
|
||||||
@ -112,14 +113,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
|
const accentColor = getComputedStyle(document.body).getPropertyValue('--accent-color').trim();
|
||||||
const canvasBg = getComputedStyle(document.body).getPropertyValue('--canvas-bg').trim();
|
const canvasBg = getComputedStyle(document.body).getPropertyValue('--canvas-bg').trim();
|
||||||
|
|
||||||
ctx.fillStyle = canvasBg;
|
ctx.fillStyle = canvasBg;
|
||||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
snake.forEach((segment, index) => {
|
snake.forEach((segment, index) => {
|
||||||
const hue = (segment.x * 5 + segment.y * 5) % 360;
|
ctx.fillStyle = accentColor;
|
||||||
ctx.fillStyle = `hsl(${hue}, 100%, 50%)`;
|
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
ctx.fillRect(segment.x * gridSize, segment.y * gridSize, gridSize, gridSize);
|
ctx.fillRect(segment.x * gridSize, segment.y * gridSize, gridSize, gridSize);
|
||||||
} else {
|
} else {
|
||||||
@ -237,6 +238,5 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if ((key === 'ArrowRight' || key.toLowerCase() === 'd') && direction !== 'left') direction = 'right';
|
if ((key === 'ArrowRight' || key.toLowerCase() === 'd') && direction !== 'left') direction = 'right';
|
||||||
});
|
});
|
||||||
|
|
||||||
placeFood();
|
|
||||||
draw();
|
draw();
|
||||||
});
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user