JSFiddle - React, Tailwind, and code Playground
by jacobmumford
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.7/p5.min.js"></script>
CSS
html,body{
margin: 0;
padding: 0;
overflow: hidden;
}
JavaScript
let windowW = window.innerWidth;
let windowH = window.innerHeight;
let isLoaded = false;
let glitch;
let imgSrc = 'https://pbs.twimg.com/profile_images/1131313105408012289/22E2KrKG.png'
function setup() {
background(0);
createCanvas(windowW, windowH);
loadImage(imgSrc, function(img) {
glitch = new Glitch(img);
isLoaded = true;
});
}
function draw() {
clear();
background(0);
if (isLoaded) {
glitch.show();
}
// fill(255, 255, 255);
// textSize(14);
// text('FPS: ' + floor(frameRate()), 20, 30);
}
class Glitch {
constructor(img) {
this.channelLen = 4;
this.imgOrigin = img;
this.imgOrigin.loadPixels();
this.copyData = [];
this.flowLineImgs = [];
this.shiftLineImgs = [];
this.shiftRGBs = [];
this.scatImgs = [];
this.throughFlag = true;
this.copyData = new Uint8ClampedArray(this.imgOrigin.pixels);
// flow line
for (let i = 0; i < 1; i++) {
let o = {
pixels: null,
t1: floor(random(0, 1000)),
speed: floor(random(4, 24)),
randX: floor(random(24, 80))
};
this.flowLineImgs.push(o);
}
// shift line
for (let i = 0; i < 6; i++) {
let o = null;
this.shiftLineImgs.push(o);
}
// shift RGB
for (let i = 0; i < 1; i++) {
let o = null;
this.shiftRGBs.push(o);
}
// scat imgs
for (let i = 0; i < 3; i++) {
let scatImg = {
img: null,
x: 0,
y: 0
};
this.scatImgs.push(scatImg);
}
}
replaceData(destImg, srcPixels) {
for (let y = 0; y < destImg.height; y++) {
for (let x = 0; x < destImg.width; x++) {
let r, g, b, a;
let index;
index =...