Le nuvole che scorrono non spariscono più passando sopra quelle dipinte nello sfondo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ApqNBvNbNCwXqR2RLo8QJh
This commit is contained in:
+13
-4
@@ -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 */ }
|
||||
|
||||
Reference in New Issue
Block a user