Glazing ribbon screensaver effect in HTML5 canvas
How do I make an glazing ribbon screensaver effect in html5 canvas?
Randomly moving invisible particles connected with colored lines(strokes) produces this cool effect.Blending the colors using globa lComposite Operation gives the glaze to the ribbons. What is a glazing ribbon screensaver effect in html5 canvas? How do you make a glazing ribbon screensaver effect in html5 canvas? This script and codes were developed by Stan Williams on 08 September 2022, Thursday.
Glazing ribbon screensaver effect in HTML5 canvas - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Glazing ribbon screensaver effect in HTML5 canvas</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <!-- Lets make some ribbon effects -->
<canvas id="canvas"></canvas> <script src="js/index.js"></script>
</body>
</html>
Glazing ribbon screensaver effect in HTML5 canvas - Script Codes CSS Codes
HTML CSS JS
/*Some basic styles*/
* { margin: 0; padding: 0;}
#canvas { display: block; /*Fill canvas with black by default*/ background: #f00;
}
Glazing ribbon screensaver effect in HTML5 canvas - Script Codes JS Codes
window.onload = function(){ var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); //Lets make the canvas occupy the full page var W = window.innerWidth, H = window.innerHeight; canvas.width = W; canvas.height = H; //Lets make some particles var particles = []; for(var i = 0; i < 25; i++) { particles.push(new particle()); } function particle() { //location on the canvas this.location = {x: Math.random()*W, y: Math.random()*H}; //radius - lets make this 0 this.radius = 0; //speed this.speed = 3; //steering angle in degrees range = 0 to 360 this.angle = Math.random()*360; //colors var r = Math.round(Math.random()*255); var g = Math.round(Math.random()*255); var b = Math.round(Math.random()*255); var a = Math.random(); this.rgba = "rgba("+r+", "+g+", "+b+", "+a+")"; } //Lets draw the particles function draw() { //re-paint the BG //Lets fill the canvas black //reduce opacity of bg fill. //blending time ctx.globalCompositeOperation = "source-over"; ctx.fillStyle = "rgba(0, 0, 0, 0.02)"; ctx.fillRect(0, 0, W, H); ctx.globalCompositeOperation = "lighter"; for(var i = 0; i < particles.length; i++) { var p = particles[i]; ctx.fillStyle = "white"; ctx.fillRect(p.location.x, p.location.y, p.radius, p.radius); //Lets move the particles //So we basically created a set of particles moving in random direction //at the same speed //Time to add ribbon effect for(var n = 0; n < particles.length; n++) { var p2 = particles[n]; //calculating distance of particle with all other particles var yd = p2.location.y - p.location.y; var xd = p2.location.x - p.location.x; var distance = Math.sqrt(xd*xd + yd*yd); //draw a line between both particles if they are in 200px range if(distance < 200) { ctx.beginPath(); ctx.lineWidth = 1; ctx.moveTo(p.location.x, p.location.y); ctx.lineTo(p2.location.x, p2.location.y); ctx.strokeStyle = p.rgba; ctx.stroke(); //The ribbons appear now. } } //We are using simple vectors here //New x = old x + speed * cos(angle) p.location.x = p.location.x + p.speed*Math.cos(p.angle*Math.PI/180); //New y = old y + speed * sin(angle) p.location.y = p.location.y + p.speed*Math.sin(p.angle*Math.PI/180); //You can read about vectors here: //http://physics.about.com/od/mathematics/a/VectorMath.htm if(p.location.x < 0) p.location.x = W; if(p.location.x > W) p.location.x = 0; if(p.location.y < 0) p.location.y = H; if(p.location.y > H) p.location.y = 0; } } setInterval(draw, 30);
}
//original author: https://twitter.com/thecodeplayer
Developer | Stan Williams |
Username | Stanssongs |
Uploaded | September 08, 2022 |
Rating | 3.5 |
Size | 2,841 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 |
HTML5 Player with Flash fallback for non supporting browsers. | 3,484 Kb |
3D Hover Effect for Images | 4,341 Kb |
Background Image Slideshow Menu | 2,226 Kb |
Jquery and CSS3 powered Lightbox Gallery | 4,834 Kb |
CSS social buttons and icons | 43,459 Kb |
Pure CSS3 breadcrumb navigation, pixel perfect | 3,958 Kb |
Animated button effects using jquery, css, javascript and effeckts.js | 2,862 Kb |
Record Player with CSS3 Anims and HTML5 Audio | 3,404 Kb |
Circular rotating music player with menu on back with html5 javascript and css3 | 5,572 Kb |
Draggy Bits | 3,551 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 |
Freecodecamp - Tribute Page | Samoht513 | 3,583 Kb |
C.Rowe Button | Brownerd | 2,473 Kb |
Box-sizing | Elad2412 | 1,572 Kb |
Button Option Group | Honchoman | 1,859 Kb |
Obligatory CSS3 UI Nav | Romandiaz | 9,017 Kb |
Header Line Issue | Charlie-volpe | 1,768 Kb |
How to add Css Fold Notes In Blogger By Askwithloud.com | Askwithloud | 2,280 Kb |
A Pen by Jess | Jessamyne | 5,100 Kb |
SVG Playground | Roygwells | 1,834 Kb |
Flexbox Grid - equal height | DaveOrDead | 2,855 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!