mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-01-17 06:08:31 +01:00
refactor
This commit is contained in:
parent
b613b87536
commit
623878b75e
@ -46,25 +46,25 @@ function spiral_step(spiral, angle_step) =
|
|||||||
[each spiral_path(spiral), vt(c, r, sa, as, a)]
|
[each spiral_path(spiral), vt(c, r, sa, as, a)]
|
||||||
);
|
);
|
||||||
|
|
||||||
function _foliage_scroll(width, height, spirals, max_spirals, min_radius, angle_step, done) =
|
function _foliage_scroll(size, spirals, max_spirals, min_radius, angle_step, done) =
|
||||||
let(
|
let(
|
||||||
more_spirals = try_add_spiral(width, height, spirals, max_spirals, min_radius, done),
|
more_spirals = try_add_spiral(size, spirals, max_spirals, min_radius, done),
|
||||||
nx_spirals = [
|
nx_spirals = [
|
||||||
for(i = 0; i < len(more_spirals); i = i + 1)
|
for(i = 0; i < len(more_spirals); i = i + 1)
|
||||||
if(i < done) more_spirals[i] else spiral_step(more_spirals[i], angle_step)
|
if(i < done) more_spirals[i] else spiral_step(more_spirals[i], angle_step)
|
||||||
],
|
],
|
||||||
nx_done = count(nx_spirals, function(s) spiral_angle(s) > 630)
|
nx_done = count(nx_spirals, function(s) spiral_angle(s) > 630)
|
||||||
)
|
)
|
||||||
nx_done < len(nx_spirals)? _foliage_scroll(width, height, nx_spirals, max_spirals, min_radius, angle_step, nx_done) : nx_spirals;
|
nx_done < len(nx_spirals)? _foliage_scroll(size, nx_spirals, max_spirals, min_radius, angle_step, nx_done) : nx_spirals;
|
||||||
|
|
||||||
function try_add_spiral(width, height, spirals, max_spirals, min_radius, done) =
|
function try_add_spiral(size, spirals, max_spirals, min_radius, done) =
|
||||||
let(
|
let(
|
||||||
leng = len(spirals),
|
leng = len(spirals),
|
||||||
more_spirals = [
|
more_spirals = [
|
||||||
each spirals,
|
each spirals,
|
||||||
each [
|
each [
|
||||||
for(i = done; i < leng; i = i + 1)
|
for(i = done; i < leng; i = i + 1)
|
||||||
let(maybeSpiral = try_create_spiral(width, height, spirals, i, min_radius))
|
let(maybeSpiral = try_create_spiral(size, spirals, i, min_radius))
|
||||||
if(!is_undef(maybeSpiral)) maybeSpiral
|
if(!is_undef(maybeSpiral)) maybeSpiral
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
@ -72,7 +72,7 @@ function try_add_spiral(width, height, spirals, max_spirals, min_radius, done) =
|
|||||||
)
|
)
|
||||||
leng_more_spirals > max_spirals ? [for(i = [0:max_spirals - 1]) more_spirals[i]] : more_spirals;
|
leng_more_spirals > max_spirals ? [for(i = [0:max_spirals - 1]) more_spirals[i]] : more_spirals;
|
||||||
|
|
||||||
function try_create_spiral(width, height, spirals, i, min_radius) =
|
function try_create_spiral(size, spirals, i, min_radius) =
|
||||||
let(spiral = spirals[i])
|
let(spiral = spirals[i])
|
||||||
spiral_angle(spiral) <= 270 ? undef :
|
spiral_angle(spiral) <= 270 ? undef :
|
||||||
let(
|
let(
|
||||||
@ -89,10 +89,10 @@ function try_create_spiral(width, height, spirals, i, min_radius) =
|
|||||||
cx = center.x + offR * cos(ca - 180),
|
cx = center.x + offR * cos(ca - 180),
|
||||||
cy = center.y + offR * sin(ca - 180)
|
cy = center.y + offR * sin(ca - 180)
|
||||||
)
|
)
|
||||||
out_size(width, height, cx, cy, cr) || overlapped(spirals, i, cx, cy, cr) ? undef : spiral([cx, cy], cr, ca, -angleSign);
|
out_size(size, cx, cy, cr) || overlapped(spirals, i, cx, cy, cr) ? undef : spiral([cx, cy], cr, ca, -angleSign);
|
||||||
|
|
||||||
function out_size(width, height, cx, cy, cr) =
|
function out_size(size, cx, cy, cr) =
|
||||||
let(half_width = width / 2, half_height = height / 2)
|
let(half_width = size.x / 2, half_height = size.y / 2)
|
||||||
cx < -half_width + cr || cx > half_width - cr || cy < -half_height + cr || cy > half_height - cr;
|
cx < -half_width + cr || cx > half_width - cr || cy < -half_height + cr || cy > half_height - cr;
|
||||||
|
|
||||||
function overlapped(spirals, i, cx, cy, cr, j = 0) =
|
function overlapped(spirals, i, cx, cy, cr, j = 0) =
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use <_impl/_foliage_scroll_impl.scad>
|
use <_impl/_foliage_scroll_impl.scad>
|
||||||
|
|
||||||
function foliage_scroll(width, height, max_spirals, init_radius, min_radius, angle_step = 10, done = 0) =
|
function foliage_scroll(size, max_spirals, init_radius, min_radius, angle_step = 10, done = 0) =
|
||||||
let(
|
let(
|
||||||
init_spirals = [
|
init_spirals = [
|
||||||
spiral([init_radius, 0], init_radius, 180),
|
spiral([init_radius, 0], init_radius, 180),
|
||||||
@ -8,7 +8,7 @@ function foliage_scroll(width, height, max_spirals, init_radius, min_radius, ang
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
[
|
[
|
||||||
for(spiral = _foliage_scroll(width, height, init_spirals, max_spirals, min_radius, angle_step, done))
|
for(spiral = _foliage_scroll(size, init_spirals, max_spirals, min_radius, angle_step, done))
|
||||||
spiral_path(spiral)
|
spiral_path(spiral)
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ angle_step = 10;
|
|||||||
min_radius = 10;
|
min_radius = 10;
|
||||||
init_radius = rands(min_radius * 2, min_radius * 4, 1)[0];
|
init_radius = rands(min_radius * 2, min_radius * 4, 1)[0];
|
||||||
|
|
||||||
for(spiral = foliage_scroll(width, height, max_spirals, init_radius, min_radius)) {
|
for(spiral = foliage_scroll([width, height], max_spirals, init_radius, min_radius)) {
|
||||||
polyline_join(spiral)
|
polyline_join(spiral)
|
||||||
circle(min_radius / 5);
|
circle(min_radius / 5);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user