From da3c0239d08f1e18cc216ccb67464a4e3a2844b9 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 11 Oct 2021 16:28:39 +0200 Subject: liam --- index.html | 226 +++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 153 insertions(+), 73 deletions(-) (limited to 'index.html') diff --git a/index.html b/index.html index df5cd21..e5c659e 100644 --- a/index.html +++ b/index.html @@ -1,75 +1,155 @@ - - - + function choice(a) { + return a[randint(a.length)]; + } + var count = 20; + var dy = 1; + var a = [], + w, + h; + window.addEventListener("resize", resize); + resize(); + for (var i = 0; i < count; i++) { + a.push({ + img: choice(imgs), + x: randint(w), + s: randrange(0.5, 1.0), + y: randrange((-h * 1) / 3, (h * 2) / 3) | 0, + r: randrange(0, Math.PI * 2), + dr: randrange(-2, 2) * 0.0002, + scale: randrange(0.5, 2.0), + flip: choice([-1, 1]), + opacity: 0, + }); + } + function resize() { + canvas.width = w = window.innerWidth; + canvas.height = h = window.innerHeight; + } + function animate() { + requestAnimationFrame(animate); + ctx.fillStyle = "rgba(255,255,255,0.00005)"; + ctx.fillRect(0, 0, w, h); + for (var i = 0; i < count; i++) { + var img = a[i].img; + a[i].y += dy * a[i].s; + // if (i == 0) console.log(a[i]); + if (img.complete) { + if (a[i].y > h) { + a[i].img = choice(imgs); + a[i].x = randint(w); + a[i].s = randrange(0.5, 1.0); + a[i].y = randrange((-h * 1) / 3, (h * 2) / 3) | 0; + a[i].r = randrange(0, Math.PI * 2); + a[i].dr = randrange(-2, 2) * 0.0002; + a[i].scale = randrange(0.8, 1.2); + a[i].flip = choice([-1, 1]); + a[i].opacity = 0; + } + var rat = img.c.width / img.c.height; + var ww = img.c.width * a[i].s; + var hh = img.c.height * a[i].s; + ctx.save(); + ctx.globalAlpha = Math.min((a[i].opacity += 0.0005), 1); + ctx.translate(w / 2, h / 2); + ctx.rotate((a[i].r += a[i].dr)); + ctx.translate(-w / 2, -h / 2); + ctx.translate(ww, hh); + ctx.scale(a[i].scale * a[i].flip, a[i].scale); + ctx.drawImage(img.c, a[i].x, a[i].y, ww, hh); + ctx.restore(); + } + } + } + animate(); + + -- cgit v1.2.3-70-g09d2