Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ // Canvas drawing functionality
+ const canvas = document.getElementById('favicon-canvas');
+ const ctx = canvas.getContext('2d');
+ let isDrawing = false;
+
+ // Set initial canvas background
+ ctx.fillStyle = '#ffffff';
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
+
+ // Drawing tools
+ const colors = ['#4361ee', '#3f37c9', '#4cc9f0', '#f72585', '#4895ef'];
+ let currentColor = colors[0];
+ let brushSize = 4;
+
+ // Event listeners for drawing
+ canvas.addEventListener('mousedown', startDrawing);
+ canvas.addEventListener('mousemove', draw);
+ canvas.addEventListener('mouseup', stopDrawing);
+ canvas.addEventListener('mouseout', stopDrawing);
+
+ // Touch support
+ canvas.addEventListener('touchstart', handleTouch);
+ canvas.addEventListener('touchmove', handleTouch);
+ canvas.addEventListener('touchend', stopDrawing);
+
+ // Button functionality
+ document.getElementById('clear-btn').addEventListener('click', clearCanvas);
+ document.getElementById('save-btn').addEventListener('click', downloadFavicon);
+
+ function startDrawing(e) {
+ isDrawing = true;
+ draw(e);
+ }
+
+ function draw(e) {
+ if (!isDrawing) return;
+
+ // Get position
+ const rect = canvas.getBoundingClientRect();
+ let x, y;
+
+ if (e.type.includes('touch')) {
+ x = e.touches[0].clientX - rect.left;
+ y = e.touches[0].clientY - rect.top;
+ } else {
+ x = e.clientX - rect.left;
+ y = e.clientY - rect.top;
+ }
+
+ // Draw circle
+ ctx.fillStyle = currentColor;
+ ctx.beginPath();
+ ctx.arc(x, y, brushSize, 0, Math.PI * 2);
+ ctx.fill();
+ }
+
+ function stopDrawing() {
+ isDrawing = false;
+ }
+
+ function handleTouch(e) {
+ e.preventDefault();
+ if (e.type === 'touchstart') {
+ startDrawing(e);
+ } else if (e.type === 'touchmove') {
+ draw(e);
+ }
+ }
+
+ function clearCanvas() {
+ ctx.fillStyle = '#ffffff';
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
+ }
+
+ function downloadFavicon() {
+ const link = document.createElement('a');
+ link.download = 'favicon.png';
+ link.href = canvas.toDataURL('image/png');
+ link.click();
+ }
+
+ // Randomly change color every few seconds
+ setInterval(() => {
+ currentColor = colors[Math.floor(Math.random() * colors.length)];
+ }, 3000);
+
+ // Smooth scrolling for anchor links
+ document.querySelectorAll('a[href^="#"]').forEach(anchor => {
+ anchor.addEventListener('click', function(e) {
+ e.preventDefault();
+ const targetId = this.getAttribute('href');
+ if (targetId === '#') return;
+
+ const targetElement = document.querySelector(targetId);
+ if (targetElement) {
+ targetElement.scrollIntoView({
+ behavior: 'smooth'
+ });
+ }
+ });
+ });
+ });