Points-line

Developer
Size
2,396 Kb
Views
8,096

How do I make an points-line?

What is a points-line? How do you make a points-line? This script and codes were developed by IEkiller on 18 January 2023, Wednesday.

Points-line Previews

Points-line - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>points-line</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas id="can" width=1000 height=800></canvas> <script src="js/index.js"></script>
</body>
</html>

Points-line - Script Codes CSS Codes

* { margin: 0; padding: 0;
}
canvas { background: #ccc; display: block;
}

Points-line - Script Codes JS Codes

var can = document.querySelector('#can');
can.width = window.innerWidth;
can.height = window.innerHeight;
var ctx = can.getContext('2d');
ctx.fillStyle = 'rgba(0,100,255,.8)';
ctx.strokeStyle = 'rgba(255, 100, 0, .8)';
ctx.lineWidth = 1;
var points = [ // {x:10, y:10, r: 3, sx: -1, sy: 2}
];
const lineRange = can.width / 6;
function init() { points = bronPoints(200, 3); window.tempPotins = [].concat(points); window.raf = requestAnimationFrame(loop);
}
function bronPoints(num, range) { var arr = []; for (var i = 0; i < num; i++) { arr.push({ x: Math.round(Math.random() * (can.width - 100) + 50), y: Math.round(Math.random() * (can.height - 100) + 50), r: !range ? Math.round(Math.random() * 5 + 5) : range, sx: Math.round(Math.random() * 7 - 3), sy: Math.round(Math.random() * 7 - 3), }) } return arr;
}
function loop() { ctx.clearRect(0, 0, can.width, can.height); drawLine(); drawPoint(); updatePoint(); window.raf = requestAnimationFrame(loop);
}
function drawPoint() { tempPotins.forEach(function(item, i) { ctx.beginPath(); ctx.arc(item.x, item.y, item.r, 0, 2 * Math.PI); ctx.closePath(); ctx.fill(); });
}
function updatePoint() { tempPotins.forEach(function(item, i) { item.x += item.sx; if (item.x >= can.width - item.r || item.x <= 0 + item.r) { item.sx = -item.sx; } item.y += item.sy; if (item.y >= can.height - item.r || item.y <= 0 + item.r) { item.sy = -item.sy; } });
}
function drawLine() { var arr = [].concat(tempPotins); while (arr.length > 0) { for (var i = 1, l = arr.length; i < l; i++) { if (isInRange(arr[0], arr[i])) { ctx.save(); ctx.beginPath(); ctx.moveTo(arr[0].x, arr[0].y); ctx.lineTo(arr[i].x, arr[i].y); ctx.closePath(); ctx.stroke(); ctx.restore(); } } arr.shift(); }
}
function isInRange(po1, po2) { var dis = Math.sqrt(Math.pow(po2.x - po1.x, 2) + Math.pow(po2.y - po1.y, 2)); return dis < lineRange;
}
init();
Points-line - Script Codes
Points-line - Script Codes
Home Page Home
Developer IEkiller
Username win7killer
Uploaded January 18, 2023
Rating 3
Size 2,396 Kb
Views 8,096
Do you need developer help for Points-line?

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!

IEkiller (win7killer) Script Codes
Create amazing video scripts with AI!

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!