From d6de63d3445ab10072609db2e695d67560c68692 Mon Sep 17 00:00:00 2001 From: Andrea Manzi Date: Sun, 25 Oct 2026 00:33:14 +0200 Subject: [PATCH] =?UTF-8?q?Le=20nuvole=20che=20scorrono=20non=20spariscono?= =?UTF-8?q?=20pi=C3=B9=20passando=20sopra=20quelle=20dipinte=20nello=20sfo?= =?UTF-8?q?ndo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01ApqNBvNbNCwXqR2RLo8QJh --- src/engine/render.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/engine/render.js b/src/engine/render.js index 0636e24..18c5fa1 100644 --- a/src/engine/render.js +++ b/src/engine/render.js @@ -210,11 +210,20 @@ function skyMask(bg) { c.width = WIDTH; c.height = HEIGHT; const x = c.getContext('2d'); x.drawImage(bg, 0, 0, WIDTH, HEIGHT); - const img = x.getImageData(0, 0, WIDTH, HEIGHT), d = img.data; - for (let p = 0; p < d.length; p += 4) { - const sky = d[p + 2] > 150 && d[p + 2] - d[p] > 60 && d[p + 2] - d[p + 1] > 15; - d[p + 3] = sky ? 255 : 0; + const img = x.getImageData(0, 0, WIDTH, HEIGHT), d = img.data, W = WIDTH, H = HEIGHT; + const sky = new Uint8Array(W * H); + for (let i = 0; i < W * H; i++) sky[i] = d[i * 4 + 2] > 150 && d[i * 4 + 2] - d[i * 4] > 60 && d[i * 4 + 2] - d[i * 4 + 1] > 15 ? 1 : 0; + // Le nuvole dipinte nello sfondo sono cielo anche loro (sennĂ² le nuvole nuove ci spariscono dietro): pixel chiari + // con del cielo azzurro vicino a sinistra, a destra, sopra e sotto. Un muro chiaro sotto non ha cielo: resta fuori. + const near = (i, step, n) => { for (let k = 1, j = i; k <= n; k++) { j += step; if (j < 0 || j >= W * H) return false; if (sky[j]) return true; } return false; }; + const out = sky.slice(); + for (let i = 0; i < W * H; i++) { + if (sky[i]) continue; + const r = d[i * 4], g = d[i * 4 + 1], bl = d[i * 4 + 2], col = i % W; + if (r + g + bl < 540 || bl < 140) continue; + if (near(i, -1, Math.min(40, col)) && near(i, 1, Math.min(40, W - 1 - col)) && near(i, -W, 24) && near(i, W, 24)) out[i] = 1; } + for (let i = 0; i < W * H; i++) d[i * 4 + 3] = out[i] ? 255 : 0; x.putImageData(img, 0, 0); mask = c; } catch { /* senza canvas (test) niente nuvole */ }