xxxxxxxxxx
85
let val_sx, val_dx;
function setup() {
createCanvas(windowWidth, windowHeight);
val_sx = random(windowHeight - 0.5);
val_dx = random(windowHeight - 0.5);
background(220);
}
function draw() {
background(220);
fill(0);
stroke(0);
text("Il mouse è il lettore della LUT", 20, 20);
text("Ricarica la pagina per cambiare i punti", 20, 40);
text("Il segmento blu è l'errore da sx", 20, 60);
text("Il segmento rosso è l'errore da dx", 20, 80);
text("Il segmento viola è il range del rumore", 20, 100);
let r = 10;
fill(255);
ellipse(windowWidth * 0.25, val_sx, r, r);
line(windowWidth * 0.25, windowHeight, windowWidth * 0.25, val_sx);
ellipse(windowWidth * 0.75, val_dx, r, r);
line(windowWidth * 0.75, windowHeight, windowWidth * 0.75, val_dx);
stroke(0, 255, 0);
line(windowWidth * 0.25, val_sx, windowWidth * 0.75, val_dx);
let lettore_LUT = constrain(mouseX, windowWidth * 0.25, windowWidth * 0.75);
stroke(0, 0, 255); //err sx
line(windowWidth * 0.25, val_sx, lettore_LUT, val_sx);
stroke(255, 0, 0);
line(windowWidth * 0.75, val_dx, lettore_LUT, val_dx);
stroke(255, 0, 255, 50);
line(lettore_LUT, val_sx, lettore_LUT, val_dx);
fill(255, 255, 255, 100);
stroke(255, 255, 255, 50);
line (windowWidth * 0.5, 0, windowWidth * 0.5, windowHeight);
stroke(0);
//rumore generale
let punto_y = (val_sx + val_dx) * 0.5;
let punto_y_random = random(val_sx, val_dx);
ellipse(lettore_LUT, punto_y_random, r, r);
let scala_LUT = map(lettore_LUT, windowWidth * 0.25, windowWidth * 0.75, 0, 1);
fill(255, 0, 0, 50);
let err_sx = scala_LUT;
let err_dx = 1 - err_sx;
let gain_sx = err_sx;
let gain_dx = err_dx;
let val_random_sx = random(val_sx, val_dx * 0.5) * gain_sx;
let val_random_dx = random(val_sx * 0.5 , val_dx) * gain_dx;
//float output = sample_sx * random(1, 1.f - err) + sample_dx * random(err, 1);
let val_out_sx = val_random_sx ;
ellipse(lettore_LUT, val_out_sx, r, r);
fill(0, 0, 255, 50);
let val_out_dx = val_random_dx ;
ellipse(lettore_LUT, val_out_dx, r, r);
fill(255, 255, 255, 50);
//ellipse(lettore_LUT, err_tot, r * 2, r * 2);
}