Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
Linearly connecting random points in a canvas using Javascript

Here is JS code to show random points on a canvas:

var myCanvas = document.getElementById("showCanvas");
var myContext = myCanvas.getContext("2d");
randomPoints(myContext, 4);

function randomPoints(canvas, count) {
  for (var i = 0; i < count; i++) {
    var x = Math.floor(Math.random() * 600);
    var y = Math.floor(Math.random() * 400);
    var r = 5;
    canvas.arc(x, y, r, 0, 2 * Math.PI, true);
    canvas.closePath();
    canvas.fill();
  }
}
<canvas id="showCanvas" width="600%" height="400%" style="border:2px solid #000000;">
  Your browser does not support the canvas element
</canvas>

It works fine, but can't find a way to connect these points in a linear format, e.g. a to d and not a to b, a to c and a to d like it shows below. I need help!

$('.drawLines').click(function() {
  myContext.beginPath();
  // wish there was something I could do here if necessary...
  myContext.stroke();
});

What am I missing?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!