// Art Gallery Data const artworks = [ { id: 1, title: "Cyberpunk City Nights", artist: "NeonDreamer", category: "digital", image: "https://static.photos/technology/640x480/1", avatar: "https://static.photos/people/200x200/1", likes: 2453, views: "12.5K", comments: 89, description: "A futuristic cityscape inspired by Blade Runner and cyberpunk aesthetics. Created in Blender and Photoshop over 3 weeks.", tags: ["cyberpunk", "cityscape", "digital", "scifi"] }, { id: 2, title: "Ethereal Forest Spirit", artist: "MysticArt", category: "digital", image: "https://static.photos/nature/640x360/2", avatar: "https://static.photos/people/200x200/2", likes: 1892, views: "8.2K", comments: 56, description: "Digital painting of an ancient forest guardian. Exploring light and atmosphere in fantasy environments.", tags: ["fantasy", "forest", "spirit", "digitalpainting"] }, { id: 3, title: "Portrait Study #42", artist: "ArtStudent_99", category: "traditional", image: "https://static.photos/people/640x480/3", avatar: "https://static.photos/people/200x200/3", likes: 567, views: "2.1K", comments: 23, description: "Oil on canvas. 40x50cm. Working on skin tones and lighting from natural window light.", tags: ["oilpainting", "portrait", "traditional", "study"] }, { id: 4, title: "Abstract Emotions", artist: "ColorSplash", category: "digital", image: "https://static.photos/abstract/640x360/4", avatar: "https://static.photos/people/200x200/4", likes: 3201, views: "15K", comments: 134, description: "Exploring the relationship between color and emotion. Digital abstract composition using custom brushes.", tags: ["abstract", "colors", "emotional", "digital"] }, { id: 5, title: "Mountain Mist", artist: "NatureLens", category: "photography", image: "https://static.photos/nature/640x480/5", avatar: "https://static.photos/people/200x200/5", likes: 892, views: "4.5K", comments: 45, description: "Early morning shot in the Alps. Sony A7III with 24-70mm lens. f/8, 1/125s, ISO 100.", tags: ["photography", "landscape", "mountains", "nature"] }, { id: 6, title: "Mecha Warrior", artist: "RobotDesigner", category: "3d", image: "https://static.photos/technology/640x360/6", avatar: "https://static.photos/people/200x200/6", likes: 4521, views: "22K", comments: 201, description: "Hard surface modeling practice. Rendered in Octane. Concept inspired by Gundam and Pacific Rim.", tags: ["3d", "mecha", "robot", "scifi", "blender"] }, { id: 7, title: "Cherry Blossom Dreams", artist: "SakuraArtist", category: "anime", image: "https://static.photos/nature/640x480/7", avatar: "https://static.photos/people/200x200/7", likes: 5678, views: "28K", comments: 312, description: "Original character illustration. Clip Studio Paint. Focusing on soft lighting and spring atmosphere.", tags: ["anime", "manga", "illustration", "sakura"] }, { id: 8, title: "Urban Decay", artist: "StreetWalker", category: "photography", image: "https://static.photos/cityscape/640x360/8", avatar: "https://static.photos/people/200x200/8", likes: 1234, views: "6.7K", comments: 78, description: "Abandoned factory exploration. High contrast black and white processing to emphasize texture.", tags: ["urban", "abandoned", "blackwhite", "photography"] }, { id: 9, title: "Dragon's Lair", artist: "FantasyMaster", category: "digital", image: "https://static.photos/abstract/640x480/9", avatar: "https://static.photos/people/200x200/9", likes: 3892, views: "18K", comments: 156, description: "Epic fantasy scene. Photoshop and Wacom Cintiq. 40+ hours of work on the scales alone!", tags: ["dragon", "fantasy", "epic", "creature"] }, { id: 10, title: "Minimalist Architecture", artist: "CleanLines", category: "photography", image: "https://static.photos/minimal/640x360/10", avatar: "https://static.photos/people/200x200/10", likes: 2156, views: "9.3K", comments: 67, description: "Geometry in modern architecture. Shot in Tokyo. Minimal post-processing to maintain clean lines.", tags: ["architecture", "minimal", "geometry", "modern"] }, { id: 11, title: "Space Station Omega", artist: "StarTraveler", category: "3d", image: "https://static.photos/technology/640x480/11", avatar: "https://static.photos/people/200x200/11", likes: 1789, views: "7.8K", comments: 89, description: "Environment design for sci-fi game project. Blender and Unreal Engine 5. Real-time rendering.", tags: ["3d", "environment", "scifi", "space"] }, { id: 12, title: "Watercolor Sunset", artist: "BrushAndPaint", category: "traditional", image: "https://static.photos/nature/640x360/12", avatar: "https://static.photos/people/200x200/12", likes: 923, views: "3.4K", comments: 34, description: "Wet-on-wet technique. Winsor & Newton watercolors. Arches cold press 300gsm.", tags: ["watercolor", "traditional", "sunset", "seascape"] } ]; let currentCategory = 'all'; let currentSort = 'newest'; let likedArtworks = new Set(); // Initialize document.addEventListener('DOMContentLoaded', () => { lucide.createIcons(); renderGallery(); setupEventListeners(); checkNullUndefined(); }); // Error handling demonstration for undefined/null function checkNullUndefined() { // Simulating safe data access patterns const safeGet = (obj, path, defaultValue = null) => { try { return path.split('.').reduce((acc, part) => acc && acc[part] !== undefined ? acc[part] : defaultValue, obj); } catch (e) { console.warn('Null/Undefined value encountered:', path); return defaultValue; } }; // Example of handling potentially undefined data const testData = { artwork: { title: "Test", stats: null } }; // Safe access without errors const title = safeGet(testData, 'artwork.title', 'Untitled'); const likes = safeGet(testData, 'artwork.stats.likes', 0); console.log('Null/Undefined handling demo:', { title, likes }); } function renderGallery() { const gallery = document.getElementById('gallery'); const filtered = filterArtworks(); const sorted = sortArtworks(filtered); gallery.innerHTML = sorted.map(artwork => createArtworkCard(artwork)).join(''); lucide.createIcons(); // Update count document.getElementById('resultCount').textContent = `Showing ${sorted.length} artworks`; } function createArtworkCard(artwork) { const isLiked = likedArtworks.has(artwork.id); const likeClass = isLiked ? 'text-red-500 fill-current' : 'text-white'; return `
by ${artwork.artist}