1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-02-24 09:33:26 +01:00

c-style for and each

This commit is contained in:
Justin Lin 2019-06-14 08:50:35 +08:00
parent 78bfb2f31d
commit 0510b18516

View File

@ -12,18 +12,19 @@ function __outer_points_shape_starburst(r1, r2, n) =
let(
a = 360 / n
)
[for(i = [0:n-1]) [r1 * cos(a * i), r1 * sin(a * i)]];
[for(i = 0; i < n; i = i + 1) [r1 * cos(a * i), r1 * sin(a * i)]];
function __inner_points_shape_starburst(r1, r2, n) =
let (
a = 360 / n,
half_a = a / 2
)
[for(i = [0:n-1]) [r2 * cos(a * i + half_a), r2 * sin(a * i + half_a)]];
[for(i = 0; i < n; i = i + 1) [r2 * cos(a * i + half_a), r2 * sin(a * i + half_a)]];
function __one_by_one_shape_starburst(outer_points, inner_points, i = 0) =
len(outer_points) == i ? [] :
concat([outer_points[i], inner_points[i]], __one_by_one_shape_starburst(outer_points, inner_points, i + 1));
function shape_starburst(r1, r2, n) = __one_by_one_shape_starburst(
__outer_points_shape_starburst(r1, r2, n), __inner_points_shape_starburst(r1, r2, n)
);
function shape_starburst(r1, r2, n) =
let(
outer_points = __outer_points_shape_starburst(r1, r2, n),
inner_points = __inner_points_shape_starburst(r1, r2, n),
leng = len(outer_points)
)
[for(i = 0; i < leng; i = i + 1) each [outer_points[i], inner_points[i]]];