Gregorio Gambini – Generative Landscape

let tutteLeFinestre = [];
function setup() {
createCanvas(800, 600);
let edifici = [
{ x: 100, yB: 150, w: 180, h: 450 },
{ x: 310, yB: 50, w: 180, h: 550 },
{ x: 520, yB: 200, w: 180, h: 400 }
];
let coloriNeon = [
{ r: 255, g: 0, b: 255 }, // Magenta
{ r: 0, g: 255, b: 255 }, // Ciano
{ r: 50, g: 255, b: 50 } // Lime
];
// Inizializzazione
for (let ed of edifici) {
let colonne = 4;
let righe = floor(ed.h / 50);
for (let r = 0; r < righe; r++) {
for (let c = 0; c < colonne; c++) {
tutteLeFinestre.push({
x: ed.x + 25 + c * 40,
y: ed.yB + 20 + r * 45,
w: 25,
h: 30,
luminosita: 0, // Parte da spenta
coloreBase: random(coloriNeon)
});
}
}
}
}
function draw() {
background(10, 10, 20);
drawStars();
// Blocchi edifici
fill(25);
noStroke();
rect(100, 150, 180, 450);
rect(310, 50, 180, 550);
rect(520, 200, 180, 400);
renderLuci();
}
// — FUNZIONE CUSTOM — ( supporto AI)
function renderLuci() {
for (let f of tutteLeFinestre) {
// 1. LOGICA HOVER (Passaggio del mouse) if (mouseX > f.x && mouseX < f.x + f.w && mouseY > f.y && mouseY < f.y + f.h) { f.luminosita = 255; // Accensione immediata } else { // 2. LOGICA FADE (Spegnimento graduale) if (f.luminosita > 0) { f.luminosita -= 5; // Velocità dello spegnimento } } // 3. DISEGNO CON GRADIENTE DI COLORE if (f.luminosita > 0) { let c = f.coloreBase; fill(c.r, c.g, c.b, f.luminosita); // Bagliore dinamico basato sulla luminosità drawingContext.shadowBlur = map(f.luminosita, 0, 255, 0, 20); drawingContext.shadowColor = `rgba(${c.r}, ${c.g}, ${c.b}, 0.8)`; } else { fill(40); // Luce spenta drawingContext.shadowBlur = 0; } noStroke(); rect(f.x, f.y, f.w, f.h);
}
drawingContext.shadowBlur = 0;
}
function drawStars() {
randomSeed(10);
fill(255, 255, 255, 180);
for(let i=0; i<100; i++) {
ellipse(random(width), random(height), 1.5);
}
}

Commenti

Lascia un commento