xxxxxxxxxx
123
let video;
let scl= 7;
let vScale = scl;
let cols, rows;
let flowfield;
var particles = [];
let xoff = 0;
let yoff = 0;
let shouldGlitch = false;
let randomVector = {x:0,y:0};
let glitchCount = 0;
const glitchFrames = 50;
let letterRes= 16;
const randomSparse = 50;
//from less bright to more bright
let letterArr = ['#','$','&','%','R','O','U','c','*','t','!','|',':','-','.',''];
letterArr ='#$&%ROUc*t!|:-.';
let word;
function setup() {
word = createInput(letterArr);
letterRes = letterArr.length;
createCanvas(600, 400);
pixelDensity(1);
textSize(10);
cols = floor(width / scl);
rows = floor(height / scl);
video = createCapture(VIDEO);
video.size(width/vScale, height/vScale);
flowfield = new Array(rows * cols);
for (var i = 0; i < 1000; i++) {
particles[i] = new Particle();
}
}
function getLetter(b){
if(letterArr[Math.floor((letterRes/256)*b)]){
return letterArr[Math.floor((letterRes/256)*b)];
} else {
return '';
}
}
function draw() {
background(255, 190);
strokeWeight(0)
letterArr=word.value();
letterRes = letterArr.length;
video.loadPixels();
loadPixels();
if(!Math.floor(Math.random()*randomSparse)){
// text(getLetter(bright), x * scl, y * scl);
glitchCount = 1;
randomVector.x = Math.floor(Math.random()*video.width);
randomVector.y = Math.floor(Math.random()*video.height);
}
if(glitchCount===glitchFrames){
glitchCount =0;
}
for (let y = 0; y < video.height; y++) {
for (let x = 0; x < video.width; x++) {
let index = (video.width - x + 1 + (y * video.width))*4;
var indexF = x + y * cols;
let r = video.pixels[index+0];
let g = video.pixels[index+1];
let b = video.pixels[index+2];
let bright = (r+g+b)/3;
// fill(0, bright, 0)
text(getLetter(bright), x * scl, y * scl);
// let angle = w
// var v = p5.Vector.fromAngle(angle);
// // let flowForce = createVector(w, w);
// // this.acceleration.add(mouseForce);
// v.setMag(1);
// flowfield[indexF] = v;
// // xoff += inc;
// stroke(250);
// push();
// translate(x * scl, y * scl);
// rotate(v.heading());
// strokeWeight(1);
// line(0, 0, scl, 0);
// pop();
}
}
if(glitchCount<glitchFrames && glitchCount !== 0){
glitchCount++;
let index = (video.width - randomVector.x + 1 + (randomVector.y * video.width))*4;
let r = video.pixels[index+0];
let g = video.pixels[index+1];
let b = video.pixels[index+2];
let bright = (r+g+b)/3;
// fill(Math.random()*255,10,Math.random()*255);
// stroke(255,0,255);
// textSize(10+glitchCount);
text(getLetter(bright), randomVector.x*scl+(glitchCount%glitchFrames), randomVector.y*scl+(glitchCount%glitchFrames));
textSize(10);
// fill(0)
} else {
// stroke(0);
}
// for (var i = 0; i < particles.length; i++) {
// particles[i].follow(flowfield);
// particles[i].update();
// particles[i].edges();
// particles[i].show();
// }
// fr.html(floor(frameRate()));
}