🍽️ 今天吃点啥
基于杭州市区真实餐厅数据,一键随机推荐,收藏你爱的那一口
筛选条件
餐品类型
当前候选: 1382 家餐厅
我的收藏 (0)
还没有收藏任何餐厅,快去随机推荐吧~
🍳 专为杭州吃货打造,前端离线随机小工具 · 数据来自杭州市区真实餐厅
// ===== 今天吃点啥 - 核心逻辑 =====
// 1. 加权随机算法
function weightedRandom(items) {
const totalWeight = items.reduce((sum, it) => sum + it.weight, 0);
let rand = Math.random() * totalWeight;
for (const item of items) {
rand -= item.weight;
if (rand <= 0) return item;
}
return items[items.length - 1];
}
// 2. 多条件筛选
function filterFoods(foods, filters) {
return foods.filter(f => {
if (filters.types.length && !filters.types.includes(f.type)) return false;
return true;
});
}
// 3. LocalStorage 持久化
function saveFavorites(list) {
localStorage.setItem('eat_favorites', JSON.stringify(list));
}
function loadFavorites() {
return JSON.parse(localStorage.getItem('eat_favorites') || '[]');
}
// 4. Canvas 食物线条动画
function initCanvas() {
const canvas = document.getElementById('eat-bg-canvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let foods = ['🍜','🍕','🍔','🥘','🍱','🍣','🍩','🍪'];
let particles = foods.map((emoji, i) => ({
x: Math.random() * canvas.width, y: Math.random() * canvas.height,
vx: (Math.random() - 0.5) * 0.8, vy: -0.3 - Math.random() * 0.5,
emoji, size: 20 + Math.random() * 16
}));
function loop() { /* requestAnimationFrame 驱动粒子漂浮 */ }
}