blot
blot copied to clipboard
Fix trimPolylines function
Currently, the bt.trim() function does not handle polylines correctly. In the following example, as you change the values of t1 and t2, the drawing appears to loop the first line of each square until at each corner.
/*
This is a modified version of the following submission:
@title: square disarray
@author: leomcelroy
@snapshot: 0.png
*/
const width = 120;
const height = 120;
const gridsize = 2; //smallest grid array
setDocDimensions(width, height);
const finalLines = []; // we'll put our final lines here
const squareWidth = 10
const squareHeight = 10
for (let i = 0; i < gridsize; i++) {
for (let j = 0; j < gridsize; j++) {
const square = rect(squareWidth, squareHeight);
bt.translate(
square,
[
(squareWidth) * i,
(squareHeight) * j
]
);
bt.join(finalLines, square);
}
}
bt.trim(finalLines, 0.00, 0.04);
drawLines(finalLines);
function rect(w, h) {
// notice how this is an array of arrays
return [
[
[-w/2, h/2],
[w/2, h/2],
[w/2, -h/2],
[-w/2, -h/2],
[-w/2, h/2],
]
]
}
Ideally, bt.trim() would not loop between the first elements of each array in the finalLines array.