Canvas Falloff Test
How do I make an canvas falloff test?
What is a canvas falloff test? How do you make a canvas falloff test? This script and codes were developed by Aaron Levine on 30 January 2023, Monday.
Canvas Falloff Test - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Canvas Falloff Test</title> <script src="https://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script>
<meta name="viewport" content="width=device-width"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Canvas Falloff Test - Script Codes CSS Codes
canvas { width: 100%; height: 100%; background: rgba(0, 0, 0, 0.2);
}
html, body { width: 100%; height: 100%; padding: 0; overflow: hidden;
}
Canvas Falloff Test - Script Codes JS Codes
var App = {};
App.canvas;
App.ctx;
App.width;
App.height;
App.prevTimestamp;
App.deltaTime;
App.mouseX;
App.mouseY;
App.dots = [];
window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame;
App.Clear = function(){ App.ctx.clearRect(0, 0, App.width, App.height);
}
App.Dot = function(x, y, color){ this.x = x; this.y = y; this.offsetX = 0; this.offsetY = 0; this.width = 10; this.height = 10; this.color = color;
};
App.Dot.prototype.Draw = function(){ var ctx = App.ctx; var x = this.x + this.offsetX; var y = this.y + this.offsetY; ctx.save(); ctx.fillStyle = this.color; ctx.fillRect(x - this.width/2, y - this.height/2, this.width, this.height); ctx.restore();
};
App.InitCanvas = function(){ var canvas = App.canvas = document.createElement('canvas'); document.body.appendChild(canvas); App.UpdateDimensions(); App.ctx = canvas.getContext('2d');
};
App.UpdateDimensions = function(){ var rect = App.canvas.getBoundingClientRect(); var width = App.width = App.canvas.width = rect.width; var height = App.height = App.canvas.height = rect.height;
};
App.InitDots = function(){ for(var x=0; x<App.width; x += 20){ for(var y=0; y<App.height; y+= 20){ App.dots.push(new App.Dot(x, y, 'rgb(0, 0, 0)')); } }
}
App.InitMouseEvents = function(){ App.mouseX = App.width / 2; App.mouseY = App.height / 2; App.canvas.addEventListener('mousemove', function(e){ App.mouseX = e.offsetX; App.mouseY = e.offsetY; }); App.canvas.addEventListener('touchmove', function(e){ App.mouseX = e.touches[0].pageX; App.mouseY = e.touches[0].pageY; }); document.addEventListener('touchmove', function(e){ e.returnValue = false; if(typeof e.preventDefault === 'function') e.preventDefault(); });
}
App.MoveDots = function(){ for(var i=0, j=App.dots.length; i<j; i++){ var dot = App.dots[i]; var difX = dot.x - App.mouseX; var difY = dot.y - App.mouseY; var distanceSquared = Math.pow(difX, 2) + Math.pow(difY, 2); var distance = Math.sqrt(distanceSquared); var dirX = difX / distance; var dirY = difY / distance; dot.offsetX = dirX * Math.log(distance * 10000000); dot.offsetY = dirY * Math.log(distance * 10000000); dot.offsetX = Math.min(50, Math.max(-50, dot.offsetX)); dot.offsetY = Math.min(50, Math.max(-50, dot.offsetY)); var size = Math.max(1, Math.min(18, Math.log(distance / 15)*4 ) ); dot.width = dot.height = size; var red = 255 - (size / 18) * 255; dot.color = 'rgb('+(red.toFixed())+', 0, 0)'; }
}
App.Draw = function(){ for(var i=0, j=App.dots.length; i<j; i++){ App.dots[i].Draw(); }
}
App.Loop = function(timestamp){ App.deltaTime = timestamp - App.prevTimestamp; App.prevTimestamp = timestamp; App.Clear(); App.MoveDots(); App.Draw(); requestAnimationFrame(App.Loop);
}
App.Main = function(){ App.InitCanvas(); App.InitDots(); App.InitMouseEvents(); App.Loop();
};
App.Main();
Developer | Aaron Levine |
Username | Aldlevine |
Uploaded | January 30, 2023 |
Rating | 4 |
Size | 2,989 Kb |
Views | 4,048 |
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 |
Popup Modal | 3,696 Kb |
Touch Hover | 2,764 Kb |
Blowout Menu | 4,712 Kb |
Colored Rain | 3,190 Kb |
Faceful Cubes | 3,721 Kb |
Random Gradients - JS | 2,026 Kb |
Pure CSS Rating Scale | 2,706 Kb |
Nav-Bar and Tab-Bar Layout | 3,936 Kb |
CRT TV Page Load Animation | 2,498 Kb |
Flashy Rating Page | 4,375 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 |
Replace url via jquery | Serluk | 1,429 Kb |
Countdown Timer | Massiebn | 3,001 Kb |
Simple search using AngularJS | Haykou | 1,802 Kb |
SVG Modified with Query String | Jnowland | 1,663 Kb |
Reviews and Ratings Star | Zbnmstry | 1,591 Kb |
Sony Xperia Z3 Flat MockUp | Dapinitial | 4,379 Kb |
Smoke Shader - Frame Buffer | Omarshe7ta | 2,672 Kb |
Chuck Norris Background | Manz | 1,967 Kb |
ASCII triangle image overlay | Mitchdot | 2,200 Kb |
BSP Dungeon Generation | Xgundam05 | 5,326 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!