lerp_line_points
lerp_line_points(x1, y1, x2, y2, count, [include]) -> List of coords [x,y], count*2
Returns multiple points evenly distributed along a line, optionally including endpoints
Syntaxe
var list = lerp_line_points(x1=10, y1=10, x2=20, y2=20, amount=5, include=true)
Arguments
| Name | Required | Default | Description |
|---|---|---|---|
x1 | yes | - | x-coordinate of the first point |
y1 | yes | - | y-coordinate of the first point |
x2 | yes | - | x-coordinate of the second point |
y2 | yes | - | y-coordinate of the second point |
count | yes | - | Number of points to generate |
include | - | - | True to include the two ends of the line (default: false) |
Full example
canvas(width=400, height=120);
var col1 = "#FFC107";
var col2 = "#37474F";
for (var i = 0; i<1; i+=0.1) {
var pt = lerp_line_point(x1=20, y1=20, x2=370, y2=40, amount=i);
circle(x=pt[0], y=pt[1], radius=10, fill=col1);
}
var pts = lerp_line_points(x1=20, y1=60, x2=370, y2=80, count=15);
for (var i = 0; i<pts.length-1; i+=2) {
var x = pts[i];
var y = pts[i+1];
circle(x=x, y=y, radius=10, fill=col2);
}
pts = lerp_line_points(x1=20, y1=80, x2=370, y2=100, count=15, include=true);
for (var i = 0; i<pts.length-1; i+=2) {
var x = pts[i];
var y = pts[i+1];
circle(x=x, y=y, radius=10, fill=col1);
}
save("lerp_line_point.png");
