How can I connect two points using a string of tiny ellipses instead of the stock line() function in p5.js?
I am trying to create a more 'artistic' function to replace the stock line() function in p5.js. To achieve this, I want to write a function where given two points (x, y) and (x1, y1), tiny circles are densely & consistently drawn along the line connecting the two points.
I tried writing a function that first finds all possible x & y points and then use a conditional to only draw an ellipse if the slope between i and j and (x1, y1) matches the slope given by (x, y) and (x1, y1).
This only gives my desired result if (x, y) and (x1, y1) have a slope of 0, 1, or undefined; the dot spacings change dramatically with any other slope. I can't figure out how to get consistently placed dots along any line I input.
My function is as follows:
function customLine(x, y, x1, y1) {
for (var i = x; i >= x && i <= x1; i ++) {
for (var j = y; j >= y && j <= y1; j ++) {
if ((j - y) / (i - x) == (y1 - y) / (x1 - x)) {
fill(0);
circle(i, j, 5);
}
}
}
}
I've also attached an image showing that I get my desired effect for slope values of 0, undefined, or 1, but not when the slope is a fraction: output of above code, illustrating issue
How can I fix my function? Or is there any entirely easier way to do this? Thanks so much!