Instable Connection
How do I make an instable connection?
What is a instable connection? How do you make a instable connection? This script and codes were developed by André Michelle on 18 October 2022, Tuesday.
Instable Connection - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Instable Connection</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="demo"> <canvas id="canvas" width="512" height="512">no canvas, no shlanvas</canvas>
</div> <script src="js/index.js"></script>
</body>
</html>
Instable Connection - Script Codes CSS Codes
html, body { background:black; color: #FFCC20; font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#demo { padding-left: 0; padding-right: 0; margin-left: auto; margin-right: auto; display: block; width: 512px;
}
Instable Connection - Script Codes JS Codes
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var width = canvas.width;
var height = canvas.height;
// Design
var circleFill = "rgba(255,160,30,1)";
var Particle = function (sx, sy) { this.sx = sx; this.sy = sy; this.vx = 0.0; this.vy = 0.0;
};
// create particles
var n = 255;
var particles = [];
for (var i = 0; i < n; ++i) { var sx = Math.random() * canvas.width; var sy = Math.random() * canvas.height; particles[i] = new Particle(sx, sy);
}
var drawLine = function (x0, y0, x1, y1, alpha) { context.lineWidth = "hairline"; context.strokeStyle = "rgba(255,160,30," + alpha + ")"; context.beginPath(); context.moveTo(x0, y0); context.lineTo(x1, y1); context.closePath(); context.stroke();
};
var drawCircle = function (x, y, r) { context.fillStyle = circleFill; context.beginPath(); context.arc(x, y, r, 0.0, Math.PI * 2.0); context.closePath(); context.fill();
};
var mouseX = 0.0;
var mouseY = 0.0;
// Physics Properties
var particleInfluenceRadius = 26.0;
var particleAttractionRadius = 18.0;
var partcileAttrationForce = 1.0 / 200.0;
var partcileVelocityDecay = 0.99;
var particleMouseInfluenceRadius = 48.0;
var particleMouseRejectionForce = 1.0 / 96.0;
var solveAndDraw = function () { var strength; var i = particles.length; while (--i > -1) { var particle = particles[i]; var j = i; while (--j > -1) { var neighbour = particles[j]; var dx = particle.sx - neighbour.sx; var dy = particle.sy - neighbour.sy; var dd = Math.sqrt(dx * dx + dy * dy); if (dd > particleInfluenceRadius) { //-- out of radius } else if (dd > particleAttractionRadius) { //-- attraction particle.vx -= dx * partcileAttrationForce; particle.vy -= dy * partcileAttrationForce; neighbour.vx += dx * partcileAttrationForce; neighbour.vy += dy * partcileAttrationForce; strength = 1.0 - (dd - particleAttractionRadius) / (particleInfluenceRadius - particleAttractionRadius); drawLine( particle.sx, particle.sy, neighbour.sx, neighbour.sy, strength); } else if (dd > 0.0) { //-- rejection:spring dd = 0.5 * (dd - particleAttractionRadius) / dd; dx *= dd; dy *= dd; particle.vx -= dx; particle.vy -= dy; neighbour.vx += dx; neighbour.vy += dy; drawLine( particle.sx, particle.sy, neighbour.sx, neighbour.sy, 1.0); } } }
};
var moveAndDraw = function () { for (var i = 0; i < n; ++i) { var particle = particles[i]; var sx = particle.sx; var sy = particle.sy; // mouse attraction var dx = mouseX - sx; var dy = mouseY - sy; var dd = Math.sqrt(dx * dx + dy * dy); if (dd < particleMouseInfluenceRadius) { particle.vx -= dx * particleMouseRejectionForce; particle.vy -= dy * particleMouseRejectionForce; } // damp velocity particle.vx *= partcileVelocityDecay; particle.vy *= partcileVelocityDecay; // apply velocity sx += particle.vx; sy += particle.vy; // bounds if (sx < 0) { sx = 0; particle.vx = -particle.vx; } else if (sx > width) { sx = width; particle.vx = -particle.vx; } if (sy < 0) { sy = 0; particle.vy = -particle.vy; } else if (sy > height) { sy = height; particle.vy = -particle.vy; } // draw drawCircle(sx, sy, 2.0); // write back particle.sx = sx; particle.sy = sy; }
};
var enterFrame = function () { context.clearRect(0, 0, width, height); solveAndDraw(); moveAndDraw(); window.requestAnimationFrame(enterFrame);
};
var mouseMove = function (e) { mouseX = e.offsetX; mouseY = e.offsetY;
};
window.requestAnimationFrame(enterFrame);
canvas.addEventListener("mousemove", mouseMove);
Developer | André Michelle |
Username | andremichelle |
Uploaded | October 18, 2022 |
Rating | 4.5 |
Size | 2,828 Kb |
Views | 18,216 |
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 |
Stern-Brocot Sequence | 2,631 Kb |
Dub Techno Chords | 3,909 Kb |
Fourier series | 2,989 Kb |
Noise monotone increasing | 2,174 Kb |
Code 7 | 2,837 Kb |
Web Audio Api Convolver | 3,023 Kb |
Geolocation Api | 2,322 Kb |
Time Displacement | 2,617 Kb |
Calculating Pi with Virtual Darts | 2,389 Kb |
Sonic Brain Food | 2,234 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 |
Toolbar | Onsen | 5,414 Kb |
Getting Started | Viblast | 1,500 Kb |
CSS background-size - GSAP | Jonathan | 2,209 Kb |
HTML5 Video Autoplay | Zivcos | 1,352 Kb |
E-mail Template | SoloMDFK | 4,871 Kb |
SVG Animation | Pollardld | 3,133 Kb |
Drawing a Terminal with CSS | Lachlanjc | 3,185 Kb |
Sidebar Thing | Jonambas | 2,779 Kb |
A Pen by Jess | Jessamyne | 5,100 Kb |
Box-sizing | Elad2412 | 1,572 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!