More Fun with Lines
How do I make an more fun with lines?
The center point will follow your mouse. Even more good fun!Clicking will stop/start the animation. . What is a more fun with lines? How do you make a more fun with lines? This script and codes were developed by Dave DeHaan on 04 January 2023, Wednesday.
More Fun with Lines - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>More Fun with Lines</title> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ body { background: -webkit-linear-gradient(left, #222, #333) #333; margin: 0; padding: 0;
}
canvas { width: 100%; height: 500px;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <canvas id="canvas" width="500" height="500"></canvas> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
More Fun with Lines - Script Codes CSS Codes
body { background: -webkit-linear-gradient(left, #222, #333) #333; margin: 0; padding: 0;
}
canvas { width: 100%; height: 500px;
}
More Fun with Lines - Script Codes JS Codes
var coolLines = { settings: { fps: 60, lines: { count: 50, speed: 1, width: 3 }, interact: { radius: 150, }, }, color: { r: 255, g: 255, b: 255, rGoal: 255, gGoal: 255, bGoal: 255 }, gradient: null, dots: [], canvas: document.getElementById('canvas'), context: null, lineInterval: null, status: 'stopped', mousePos: {x:null, y:null}, init: function() { this.context = this.canvas.getContext('2d'); this.canvas.width = $('#canvas').width(); this.canvas.height = $('#canvas').height(); this.mousePos.x = this.canvas.width / 2; this.mousePos.y = this.canvas.height / 2; var i = 0; while (i < this.settings.lines.count) { this.dots.push({ 'y': Math.floor(Math.random() * this.canvas.height), 'x': Math.floor(Math.random() * this.canvas.width), 'yGoal': this.goalValue(this.canvas.height, this.canvas.height / 10), 'xGoal': this.goalValue(this.canvas.width, this.canvas.width / 10), 'speed': this.settings.lines.speed }); i++; } this.addListener(); this.start(); }, start: function() { var cl = this; cl.lineInterval = setInterval(function() { cl.canvas.width = cl.canvas.width; cl.context.beginPath(); cl.context.moveTo(cl.dots[0].x, cl.dots[0].y); for (key in cl.dots) { cl.context.lineTo(cl.dots[key].x, cl.dots[key].y); moveSpeed = cl.dots[key].speed; if (cl.dots[key].y < cl.dots[key].yGoal) { cl.dots[key].y += moveSpeed; } if (cl.dots[key].y > cl.dots[key].yGoal) { cl.dots[key].y -= moveSpeed; } if (cl.dots[key].y == cl.dots[key].yGoal) { cl.dots[key].yGoal = cl.goalValue(cl.canvas.height, cl.canvas.height / 10); } if (cl.dots[key].x < cl.dots[key].xGoal) { cl.dots[key].x += moveSpeed; } if (cl.dots[key].x > cl.dots[key].xGoal) { cl.dots[key].x -= moveSpeed; } if (cl.dots[key].x == cl.dots[key].xGoal) { cl.dots[key].xGoal = cl.goalValue(cl.canvas.width, cl.canvas.width / 10); } } cl.context.lineTo(cl.dots[0].x, cl.dots[0].y); cl.checkMouse(); cl.context.strokeStyle = cl.createGradient(); cl.context.lineWidth = cl.settings.lines.width; cl.context.stroke(); }, 1000/cl.settings.fps); this.status = 'started'; }, stop: function() { clearInterval(this.lineInterval); this.status = 'stopped'; }, createGradient: function() { var cl = this; cl.updateColor(); cl.gradient = cl.context.createRadialGradient( cl.mousePos.x, cl.mousePos.y, 10, cl.mousePos.x, cl.mousePos.y, cl.canvas.height * 1/2 ); cl.gradient.addColorStop(0, 'rgba('+cl.color.r+','+cl.color.g+','+cl.color.b+',.5)'); cl.gradient.addColorStop(1, 'rgba('+cl.color.r+','+cl.color.g+','+cl.color.b+',0)'); return cl.gradient; }, updateColor: function() { var cl = this; if (cl.color.r < cl.color.rGoal) { cl.color.r ++; } if (cl.color.r > cl.color.rGoal) { cl.color.r --; } if (cl.color.r == cl.color.rGoal) { cl.color.rGoal = Math.floor(Math.random() * 256); } if (cl.color.g < cl.color.gGoal) { cl.color.g ++; } if (cl.color.g > cl.color.gGoal) { cl.color.g --; } if (cl.color.g == cl.color.gGoal) { cl.color.gGoal = Math.floor(Math.random() * 256); } if (cl.color.b < cl.color.bGoal) { cl.color.b ++; } if (cl.color.b > cl.color.bGoal) { cl.color.b --; } if (cl.color.b == cl.color.bGoal) { cl.color.bGoal = Math.floor(Math.random() * 256); } }, goalValue: function(maxValue, range) { if (Math.random() * 2 > 1) { return Math.floor(maxValue - range * Math.random()); } else { return Math.floor(range * Math.random()); } }, getMousePosition: function(event) { var rect = this.canvas.getBoundingClientRect(); this.mousePos.x = event.clientX - rect.left; this.mousePos.y = event.clientY - rect.top; }, checkMouse: function() { for (key in this.dots) { if (Math.abs(this.dots[key].x - this.mousePos.x) < this.settings.interact.radius && Math.abs(this.dots[key].y - this.mousePos.y) < this.settings.interact.radius) this.context.moveTo(this.dots[key].x, this.dots[key].y); this.context.lineTo(this.mousePos.x, this.mousePos.y); } }, addListener: function() { var cl = this; this.canvas.addEventListener('mousemove', function(event) { cl.getMousePosition(event); }); this.canvas.addEventListener('mousedown', function(event) { if (cl.status == 'started') cl.stop(); else cl.start(); }); }
};
coolLines.init();
Developer | Dave DeHaan |
Username | davedehaan |
Uploaded | January 04, 2023 |
Rating | 3 |
Size | 3,118 Kb |
Views | 10,120 |
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 |
Winter | 2,613 Kb |
Asteroids | 2,846 Kb |
Tween Bubbles. | 2,175 Kb |
Unblur on Page Load | 2,048 Kb |
Javascript stopwatch | 2,102 Kb |
Auto-generating complementary colors | 1,988 Kb |
Multi-color Text using globalCompositeOperation | 1,983 Kb |
Unblur on scroll | 1,930 Kb |
404 Glitch Effect | 3,495 Kb |
A Pen by Dave DeHaan | 2,015 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 |
Blog Concept - Single Post | Marionebl | 9,603 Kb |
Experiment - SCSS SVG Background Image with Variables | See8ch | 3,270 Kb |
Brian The CSS Bee | Jonitrythall | 3,922 Kb |
Css or Czz.. | Judag | 4,111 Kb |
Minimelephant | Smashlee | 2,507 Kb |
The Monty Hall Problem | Melatonind | 4,360 Kb |
P1 | Vivi_Lai | 1,533 Kb |
Responsive slide | Thorien | 2,400 Kb |
Coburg Banks SVG Logo | Mjtweaver | 3,875 Kb |
Subtle site navigation with description | Necks | 3,206 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!