Glitch
How do I make an glitch?
What is a glitch? How do you make a glitch? This script and codes were developed by Dima on 17 September 2022, Saturday.
Glitch - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>glitch</title> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="glitch-image"></div>
<canvas id="canvas"></canvas> <script src="js/index.js"></script>
</body>
</html>
Glitch - Script Codes CSS Codes
body { margin: 0; background: #373537; height: 100vh; overflow: hidden;
}
.glitch-image { -webkit-animation: flick 80ms linear infinite; animation: flick 80ms linear infinite;
}
.glitch-image #canvas { height: 100vh; -webkit-transform: rotateX(90deg); transform: rotateX(90deg); -webkit-animation: turnOn 100ms ease-in 500ms forwards; animation: turnOn 100ms ease-in 500ms forwards;
}
@-webkit-keyframes { 0% { opacity: 0.8; } 100% { opacity: 0.9; }
}
@keyframes { 0% { opacity: 0.8; } 100% { opacity: 0.9; }
}
@-webkit-keyframes { 0% { -webkit-transform: rotateX(90deg); transform: rotateX(90deg); -webkit-filter: brightness(5); filter: brightness(5); } 100% { -webkit-transform: rotateX(0); transform: rotateX(0); -webkit-filter: brightness(1); filter: brightness(1); }
}
@keyframes { 0% { -webkit-transform: rotateX(90deg); transform: rotateX(90deg); -webkit-filter: brightness(5); filter: brightness(5); } 100% { -webkit-transform: rotateX(0); transform: rotateX(0); -webkit-filter: brightness(1); filter: brightness(1); }
}
Glitch - Script Codes JS Codes
(function() { 'use strict'; var canvas = document.getElementById('canvas'), ctx = canvas.getContext('2d'), img = new Image(), currentFrame = 0, totalFrame = 10, offset = .01, width, height, imgData, data, pr = window.devicePixelRatio || 1, w = window.innerWidth, h = window.innerHeight, requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame; window.requestAnimationFrame = requestAnimationFrame; img.crossOrigin = "Anonymous"; img.src = 'https://zupra.github.io/test/filter.jpg'; img.onload = function() { init(); glitchAnimation(); }; var init = function() { canvas.width = width = w * pr; canvas.height = height = h * pr; //anvas.width = width = img.width; //* .5; offset = width * offset; //canvas.height = height = ~~(img.height * (width - offset * 2) / img.width); //document.querySelector('.glitch-image').style.width = width + 'px'; //document.querySelector('.glitch-image').style.height = height + 'px'; }.bind(this); var glitchAnimation = function() { if (!(currentFrame % totalFrame) || currentFrame > totalFrame) { clearCanvas(); ctx.drawImage(img, 0, 0, img.width, img.height, offset, 0, width - offset * 2, height); imgData = ctx.getImageData(0, 0, width, height); imgData = pixelProcessor(imgData, 4, pixelCooler); ctx.putImageData(imgData, 0, 0); currentFrame = 0; } if (currentFrame === randInt(0, totalFrame)) { imgData = pixelProcessor(imgData, 1, pixelFlick); ctx.putImageData(imgData, 0, 0); drawGlitch(width, height, randInt(3, 10), glitchBlock); drawGlitch(width, height, randInt(3, 30), glitchLine); } currentFrame++; window.requestAnimationFrame(glitchAnimation); }; var pixelFlick = function(i, d) { d[i] = d[i + 16]; }; var pixelCooler = function(i, d) { d[i] = 1; d[i + 1] += randInt(2, 5); d[i + 2] *= randInt(1, 3) + 8; }; var glitchBlock = function(i, x, y) { if (i > 3) { var spliceHeight = 1 + randInt(0, 10); ctx.drawImage(canvas, x, y, x, spliceHeight, randInt(0, x), y, randInt(x, width), spliceHeight); } }; var glitchLine = function(i, x, y) { var spliceHeight = 1 + randInt(1, 50); ctx.drawImage(canvas, offset, y, width - offset * 2, spliceHeight, 1 + randInt(0, offset * 2), //-offset / 3 + randInt(0, offset / 1.5), y + randInt(0, 10), width - offset, spliceHeight); }; var pixelProcessor = function(imageData, step, callback) { var data = imageData.data || [], step = step * 4 || 4; if (data.length) { var rgb = []; for (var i = 0; i < data.length; i += step) { callback && callback(i, data); } return imageData; } else { return imageData; } }; var drawGlitch = function(width, height, amount, callback) { for (var i = 0; i < (amount || 10); i++) { var x = Math.random() * width + 1, y = Math.random() * height + 1; callback(i, x, y); } }; var randInt = function(a, b) { return ~~(Math.random() * (b - a) + a); }; var clearCanvas = function() { ctx.clearRect(0, 0, width, height); };
})();
Developer | Dima |
Username | dimaZubkov |
Uploaded | September 17, 2022 |
Rating | 3.5 |
Size | 3,368 Kb |
Views | 52,624 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Codrops HoverEffectIdeas | 14,526 Kb |
Three js | 2,323 Kb |
Vue cart | 4,497 Kb |
Ken Burns Effect | 3,067 Kb |
Css masonry | 3,130 Kb |
Mega menu | 5,066 Kb |
Vue radio | 5,915 Kb |
Section scroll | 5,271 Kb |
Burger nav | 3,874 Kb |
Glitch | 2,843 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
JavaScript constructors | Simboonlong | 2,415 Kb |
Shopping List | Markmurray | 6,015 Kb |
CSS3 Snow Animation | NickyCDK | 1,695 Kb |
Velocity.js custom stagger | Tommiehansen | 4,805 Kb |
Basic template | Tomcat | 1,675 Kb |
Simple content swap | Snografx | 1,859 Kb |
Spiralator 9000 | AdmiralPotato | 4,671 Kb |
Weather App | Kw7oe | 3,162 Kb |
CSS3 Form Page Design | Rssatnam | 3,613 Kb |
Classy Blockquote Styling | Andrewwright | 3,212 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!