(function(){ const canvas = document.createElement('canvas'); canvas.id = 'sakuraCanvas'; canvas.style.position = 'fixed'; canvas.style.top = '0'; canvas.style.left = '0'; canvas.style.width = '100vw'; canvas.style.height = '100vh'; canvas.style.pointerEvents = 'none'; canvas.style.zIndex = '9999'; document.body.appendChild(canvas); const ctx = canvas.getContext('2d'); let width,height; let petals = []; function resize(){ width = canvas.width = window.innerWidth; height = canvas.height = window.innerHeight; } resize(); window.addEventListener('resize',resize); class Petal { constructor(){ this.reset(); } reset(){ this.x = Math.random() * width; this.y = Math.random() * -height; this.radius = Math.random() * 8 + 4; this.speedY = Math.random() * 1.5 + 0.8; this.speedX = Math.random() * 1 - 0.5; this.rotation = Math.random() * Math.PI * 2; this.rotateSpeed = (Math.random()-0.5)*0.02; this.opacity = Math.random()*0.4 + 0.6; } draw(){ ctx.save(); ctx.translate(this.x,this.y); ctx.rotate(this.rotation); ctx.beginPath(); ctx.ellipse(0, 0, this.radius, this.radius/2, 0, 0, Math.PI*2); ctx.fillStyle = `rgba(255,183,200,${this.opacity})`; ctx.fill(); ctx.restore(); } update(){ this.y += this.speedY; this.x += this.speedX; this.rotation += this.rotateSpeed; if(this.y > height + 10){ this.reset(); } } } const petalCount = 220; for(let i=0;i