Errori di decodifica: p5.glitch
All'interno di uno sketch p5.js si può usare la libreria p5.glitch che permette di simulare e combinare molti degli effetti dei glitch reali, anche tenendo conto delle differenze fra i principali formati di compressione:
// width=464 height=195
let glitch, typeCounter = 0;
function setup() {
createCanvas(windowWidth, windowHeight);
// background(0);
// imageMode(CENTER);
textAlign(RIGHT, BOTTOM);
cursor(HAND);
glitch = new Glitch();
setupGlitch(); // load image w/ random type
}
function draw() {
glitch.resetBytes();
glitch.randomBytes(1); // add one random byte for movement
glitch.buildImage(function() {
//background(0); // clear background once image is ready
clear();
// displayType(); // show text
});
// image(glitch.image, width / 2, height / 2)
image(glitch.image, 0, 10);
fill(0);
textSize(12);
// display type
text(glitch.types[typeCounter % glitch.types.length],width,height);
}
function mousePressed() {
typeCounter++;
setupGlitch(); // grab another random format
}
function setupGlitch() {
loadImage('assets/fish.png', function(im) {
glitch.loadType(glitch.types[typeCounter%glitch.types.length]); // use random type
glitch.loadImage(im);
});
}
function displayType() {
fill(255);
// textAlign(CENTER, CENTER);
textSize(20);
// text('press mouse to walkthrough image types \n' + glitch.types[typeCounter%glitch.types.length], 0, 0, width, height/2);
text(glitch.types[typeCounter % glitch.types.length],20,20);
}
Sul profilo del p5.js Web Editor di Ted Davis (l'autore della libreria) si può trovare anche il sorgente originale dell'esempio di questa pagina.