diff --git a/docs/lib3x-arc_path.md b/docs/lib3x-arc_path.md index d63a9eb9..1dd35fd4 100644 --- a/docs/lib3x-arc_path.md +++ b/docs/lib3x-arc_path.md @@ -16,7 +16,8 @@ Creates an arc path. You can pass a 2 element vector to define the central angle $fn = 24; points = arc_path(radius = 20, angle = [45, 290]); - polyline_join(points) circle(1); + polyline_join(points) + circle(1); ![arc_path](images/lib3x-arc_path-1.JPG) @@ -25,7 +26,8 @@ Creates an arc path. You can pass a 2 element vector to define the central angle $fn = 24; points = arc_path(radius = 20, angle = 135); - polyline_join(points) circle(1); + polyline_join(points) + circle(1); ![arc_path](images/lib3x-arc_path-2.JPG) diff --git a/docs/lib3x-bauer_spiral.md b/docs/lib3x-bauer_spiral.md index c380cae6..b307be48 100644 --- a/docs/lib3x-bauer_spiral.md +++ b/docs/lib3x-bauer_spiral.md @@ -26,7 +26,8 @@ Creates visually even spacing of n points on the surface of the sphere. Successi sphere(1, $fn = 24); } - polyline_join(pts) sphere(.5); + polyline_join(pts) + sphere(.5); ![bauer_spiral](images/lib3x-bauer_spiral-1.JPG) diff --git a/docs/lib3x-bezier_smooth.md b/docs/lib3x-bezier_smooth.md index ff6578f4..ab0c8be3 100644 --- a/docs/lib3x-bezier_smooth.md +++ b/docs/lib3x-bezier_smooth.md @@ -51,6 +51,7 @@ Given a path, the `bezier_smooth` function uses bazier curves to smooth all corn smoothed_path_pts = bezier_smooth(path_pts, round_d, closed = true); - translate([50, 0, 0]) polygon(smoothed_path_pts); + translate([50, 0, 0]) + polygon(smoothed_path_pts); ![bezier_smooth](images/lib3x-bezier_smooth-2.JPG) \ No newline at end of file diff --git a/docs/lib3x-bijection_offset.md b/docs/lib3x-bijection_offset.md index 432404dc..e7f92b86 100644 --- a/docs/lib3x-bijection_offset.md +++ b/docs/lib3x-bijection_offset.md @@ -22,11 +22,11 @@ Move 2D outlines outward or inward by a given amount. Each point of the offsette [-15, 0] ]; - color("red") polygon(bijection_offset(shape, 3)); + color("red") polygon(bijection_offset(shape, 3)); color("orange") polygon(bijection_offset(shape, 2)); color("yellow") polygon(bijection_offset(shape, 1)); - color("green") polygon(shape); - color("blue") polygon(bijection_offset(shape, -1)); + color("green") polygon(shape); + color("blue") polygon(bijection_offset(shape, -1)); color("indigo") polygon(bijection_offset(shape, -2)); color("purple") polygon(bijection_offset(shape, -3)); @@ -43,7 +43,6 @@ Move 2D outlines outward or inward by a given amount. Each point of the offsette [-5, 0] ]; offsetted = bijection_offset(shape, 1); - offsetted2 = bijection_offset(shape, 2); offsetted3 = bijection_offset(shape, 3); diff --git a/docs/lib3x-bspline_curve.md b/docs/lib3x-bspline_curve.md index c001745c..f6e99811 100644 --- a/docs/lib3x-bspline_curve.md +++ b/docs/lib3x-bspline_curve.md @@ -49,7 +49,8 @@ // a non-uniform B-spline curve knots = [0, 1/8, 1/4, 1/2, 3/4, 4/5, 1]; - color("red") for(p = points) { + color("red") + for(p = points) { translate(p) sphere(0.5); } @@ -73,7 +74,8 @@ // For a clamped B-spline curve, the first `degree + 1` and the last `degree + 1` knots must be identical. knots = [0, 0, 0, 1, 2, 2, 2]; - color("red") for(p = points) { + color("red") + for(p = points) { translate(p) sphere(0.5); } diff --git a/docs/lib3x-contours.md b/docs/lib3x-contours.md index 1638519c..c4e454f1 100644 --- a/docs/lib3x-contours.md +++ b/docs/lib3x-contours.md @@ -23,10 +23,10 @@ Computes contour polygons by applying [marching squares](https://en.wikipedia.or points = [ for(y = [min_value:resolution:max_value]) - [ - for(x = [min_value:resolution:max_value]) - [x, y, f(x, y)] - ] + [ + for(x = [min_value:resolution:max_value]) + [x, y, f(x, y)] + ] ]; sf_thicken(points, 1); diff --git a/docs/lib3x-flat.md b/docs/lib3x-flat.md index b42559c5..546d8e80 100644 --- a/docs/lib3x-flat.md +++ b/docs/lib3x-flat.md @@ -16,26 +16,21 @@ returns a new list with all sub-list elements concatenated into it recursively u vt = [[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]]; assert( - flat([1, 2, [3, 4]]) == - [1, 2, 3, 4] + flat([1, 2, [3, 4]]) == [1, 2, 3, 4] ); assert( - flat([[1, 2], [3, 4]]) == - [1, 2, 3, 4] + flat([[1, 2], [3, 4]]) == [1, 2, 3, 4] ); assert( - flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]]) == - [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] + flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]]) == [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] ); assert( - flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], 2) == - [[1, 2], [3, 4], [5, 6], [7, 8]] + flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], 2) == [[1, 2], [3, 4], [5, 6], [7, 8]] ); assert( - flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], 3) == - [1, 2, 3, 4, 5, 6, 7, 8] + flat([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]], 3) == [1, 2, 3, 4, 5, 6, 7, 8] ); diff --git a/docs/lib3x-hashmap.md b/docs/lib3x-hashmap.md index 1fecd182..371c4fe8 100644 --- a/docs/lib3x-hashmap.md +++ b/docs/lib3x-hashmap.md @@ -39,9 +39,9 @@ This function maps keys to values. You can use the following to process the retu m3 = hashmap_del(m2, "k1"); assert(hashmap_get(m3, "k1") == undef); - echo(hashmap_keys(m3)); // a list contains "k2", "k2", "k3" - echo(hashmap_values(m3)); // a list contains 20, 30, 40 - echo(hashmap_entries(m3)); // a list contains ["k2", 20], ["k3", 30], ["k4", 40] + assert(hashmap_keys(m3) == ["k2", "k3", "k4"]); + assert(hashmap_values(m3) == [20, 30, 40]); + assert(hashmap_entries(m3) == [["k2", 20], ["k3", 30], ["k4", 40]]); Want to simulate class-based OO in OpenSCAD? Here's my experiment. diff --git a/docs/lib3x-hashset.md b/docs/lib3x-hashset.md index d8f6f935..9af978dc 100644 --- a/docs/lib3x-hashset.md +++ b/docs/lib3x-hashset.md @@ -35,4 +35,4 @@ This function models the mathematical set, backed by a hash table. You can use t s3 = hashset_del(s2, 2); assert(!hashset_has(s3, 2)); - echo(hashset_elems(s3)); // a list contains 1, 3, 4, 5, 9 + assert(hashset_elems(s3) == [1, 3, 4, 5, 9]); diff --git a/docs/lib3x-hashset_elems.md b/docs/lib3x-hashset_elems.md index 4926bb84..369e7d98 100644 --- a/docs/lib3x-hashset_elems.md +++ b/docs/lib3x-hashset_elems.md @@ -14,5 +14,5 @@ Returns a list containing all elements in a [util/set/hashset](https://openhome. use ; s = hashset([1, 2, 3, 4, 5]); - echo(hashset_elems(s)); // a list contains 1, 2, 3, 4, 5 + assert(hashset_elems(s) == [1, 2, 3, 4, 5]); diff --git a/docs/lib3x-helix.md b/docs/lib3x-helix.md index 31076113..a291668f 100644 --- a/docs/lib3x-helix.md +++ b/docs/lib3x-helix.md @@ -27,7 +27,8 @@ Gets all points on the path of a spiral around a cylinder. Its `$fa`, `$fs` and ); for(p = points) { - translate(p) sphere(5); + translate(p) + sphere(5); } polyline_join(points) diff --git a/docs/lib3x-hollow_out.md b/docs/lib3x-hollow_out.md index f756b67a..c671ecf2 100644 --- a/docs/lib3x-hollow_out.md +++ b/docs/lib3x-hollow_out.md @@ -10,7 +10,10 @@ Hollows out a 2D object. use ; - hollow_out(shell_thickness = 1) circle(r = 3, $fn = 48); - hollow_out(shell_thickness = 1) square([10, 5]); + hollow_out(shell_thickness = 1) + circle(r = 3, $fn = 48); + + hollow_out(shell_thickness = 1) + square([10, 5]); ![hollow_out](images/lib3x-hollow_out-1.JPG) diff --git a/docs/lib3x-in_polyline.md b/docs/lib3x-in_polyline.md index b2fd8c9d..ab1a4e7f 100644 --- a/docs/lib3x-in_polyline.md +++ b/docs/lib3x-in_polyline.md @@ -20,10 +20,10 @@ Checks whether a point is on a line. [10, 10] ]; - echo(in_polyline(pts, [-2, -3])); // false - echo(in_polyline(pts, [5, 0])); // true - echo(in_polyline(pts, [10, 5])); // true - echo(in_polyline(pts, [10, 15])); // false + assert(!in_polyline(pts, [-2, -3])); + assert(in_polyline(pts, [5, 0])); + assert(in_polyline(pts, [10, 5])); + assert(!in_polyline(pts, [10, 15])); ---- @@ -35,7 +35,7 @@ Checks whether a point is on a line. [20, 10, 10] ]; - echo(in_polyline(pts, [10, 0, 10])); // true - echo(in_polyline(pts, [15, 0, 10])); // true - echo(in_polyline(pts, [15, 1, 10])); // false - echo(in_polyline(pts, [20, 11, 10])); // false \ No newline at end of file + assert(in_polyline(pts, [10, 0, 10])); + assert(in_polyline(pts, [15, 0, 10])); + assert(!in_polyline(pts, [15, 1, 10])); + assert(!in_polyline(pts, [20, 11, 10])); \ No newline at end of file diff --git a/docs/lib3x-m_mirror.md b/docs/lib3x-m_mirror.md index f96a8541..825ed67b 100644 --- a/docs/lib3x-m_mirror.md +++ b/docs/lib3x-m_mirror.md @@ -16,8 +16,8 @@ Generate a 4x4 transformation matrix which can pass into `multmatrix` to mirror cube([3, 2, 1]); multmatrix(m_mirror([1, 1, 0])) - rotate([0, 0, 10]) - cube([3, 2, 1]); + rotate([0, 0, 10]) + cube([3, 2, 1]); ![m_mirror](images/lib3x-m_mirror-1.JPG) diff --git a/docs/lib3x-m_rotation.md b/docs/lib3x-m_rotation.md index 1fda56f4..c235317e 100644 --- a/docs/lib3x-m_rotation.md +++ b/docs/lib3x-m_rotation.md @@ -19,8 +19,8 @@ Generate a 4x4 transformation matrix which can pass into `multmatrix` to rotate hull() { sphere(1); multmatrix(m_rotation(a)) - translate(point) - sphere(1); + translate(point) + sphere(1); } ![m_rotation](images/lib3x-m_rotation-1.JPG) @@ -32,14 +32,14 @@ Generate a 4x4 transformation matrix which can pass into `multmatrix` to rotate hull() { sphere(1); translate(v) - sphere(1); + sphere(1); } p = [10, 10, 0]; for(i = [0:20:340]) { multmatrix(m_rotation(a = i, v = v)) - translate(p) - sphere(1); + translate(p) + sphere(1); } ![m_rotation](images/lib3x-m_rotation-2.JPG) \ No newline at end of file diff --git a/docs/lib3x-m_scaling.md b/docs/lib3x-m_scaling.md index a6e96a10..5e3ab2ad 100644 --- a/docs/lib3x-m_scaling.md +++ b/docs/lib3x-m_scaling.md @@ -14,8 +14,8 @@ Generate a 4x4 transformation matrix which can pass into `multmatrix` to scale i cube(10); translate([15, 0, 0]) - multmatrix(m_scaling([0.5, 1, 2])) - cube(10); + multmatrix(m_scaling([0.5, 1, 2])) + cube(10); ![m_scaling](images/lib3x-m_scaling-1.JPG) diff --git a/docs/lib3x-m_shearing.md b/docs/lib3x-m_shearing.md index 5107260b..36f73304 100644 --- a/docs/lib3x-m_shearing.md +++ b/docs/lib3x-m_shearing.md @@ -18,10 +18,12 @@ Generate a 4x4 transformation matrix which can pass into `multmatrix` to shear a multmatrix(m_shearing(sx = [1, 0])) cube(1); - translate([2, 0, 0]) multmatrix(m_shearing(sx = [0, 1])) + translate([2, 0, 0]) + multmatrix(m_shearing(sx = [0, 1])) cube(1); - translate([4, 0, 0]) multmatrix(m_shearing(sx = [1, 1])) + translate([4, 0, 0]) + multmatrix(m_shearing(sx = [1, 1])) cube(1); } @@ -29,10 +31,12 @@ Generate a 4x4 transformation matrix which can pass into `multmatrix` to shear a multmatrix(m_shearing(sy = [1, 0])) cube(1); - translate([2, 0, 0]) multmatrix(m_shearing(sy = [0, 1])) + translate([2, 0, 0]) + multmatrix(m_shearing(sy = [0, 1])) cube(1); - translate([4, 0, 0]) multmatrix(m_shearing(sy = [1, 1])) + translate([4, 0, 0]) + multmatrix(m_shearing(sy = [1, 1])) cube(1); } @@ -40,10 +44,12 @@ Generate a 4x4 transformation matrix which can pass into `multmatrix` to shear a multmatrix(m_shearing(sz = [1, 0])) cube(1); - translate([2, 0, 0]) multmatrix(m_shearing(sz = [0, 1])) + translate([2, 0, 0]) + multmatrix(m_shearing(sz = [0, 1])) cube(1); - translate([4, 0, 0]) multmatrix(m_shearing(sz = [1, 1])) + translate([4, 0, 0]) + multmatrix(m_shearing(sz = [1, 1])) cube(1); } diff --git a/docs/lib3x-midpt_smooth.md b/docs/lib3x-midpt_smooth.md index 27ba18aa..14a8f8b3 100644 --- a/docs/lib3x-midpt_smooth.md +++ b/docs/lib3x-midpt_smooth.md @@ -19,7 +19,12 @@ Given a 2D path, this function constructs a mid-point smoothed version by joinin taiwan = shape_taiwan(50); smoothed = midpt_smooth(taiwan, 20, true); - translate([0, 0, 0]) polyline_join(taiwan) circle(.125); - #translate([10, 0, 0]) polyline_join(smoothed) circle(.125); + translate([0, 0, 0]) + polyline_join(taiwan) + circle(.125); + + #translate([10, 0, 0]) + polyline_join(smoothed) + circle(.125); ![midpt_smooth](images/lib3x-midpt_smooth-1.JPG) \ No newline at end of file diff --git a/docs/lib3x-mz_square_cells.md b/docs/lib3x-mz_square_cells.md index 77072cd2..e88bc618 100644 --- a/docs/lib3x-mz_square_cells.md +++ b/docs/lib3x-mz_square_cells.md @@ -41,11 +41,9 @@ The cell data is seperated from views. You can use cell data to construct [diffe cells = mz_square_cells(rows, columns); for(cell = cells) { - x = cell[0]; - y = cell[1]; type = cell[2]; - translate([x, y] * cell_width) { + translate([cell.x, cell.y] * cell_width) { if(type == TOP_WALL || type == TOP_RIGHT_WALL) { line2d([0, cell_width], [cell_width, cell_width], wall_thickness); } diff --git a/docs/lib3x-mz_square_initialize.md b/docs/lib3x-mz_square_initialize.md index fc3b0af4..5c9f8b65 100644 --- a/docs/lib3x-mz_square_initialize.md +++ b/docs/lib3x-mz_square_initialize.md @@ -68,12 +68,10 @@ It's a helper for initializing cell data of a maze. // Mask mask_width = cell_width + wall_thickness; translate([-wall_thickness / 2, -wall_thickness / 2]) - for(i = [0:rows - 1]) { - for(j = [0:columns - 1]) { - if(mask[i][j] == 0) { - translate([cell_width * j, cell_width * (rows - i - 1)]) - square(mask_width); - } + for(i = [0:rows - 1], j = [0:columns - 1]) { + if(mask[i][j] == 0) { + translate([cell_width * j, cell_width * (rows - i - 1)]) + square(mask_width); } } diff --git a/docs/lib3x-mz_theta_cells.md b/docs/lib3x-mz_theta_cells.md index 1aac3dab..6f1ffa44 100644 --- a/docs/lib3x-mz_theta_cells.md +++ b/docs/lib3x-mz_theta_cells.md @@ -42,31 +42,29 @@ The value of `type` is the wall type of the cell. It can be `0`, `1`, `2` or `3` maze = mz_theta_cells(rows, beginning_number); // draw cell walls - for(rows = maze) { - for(cell = rows) { - ri = cell[0]; - ci = cell[1]; - type = cell[2]; - thetaStep = 360 / len(maze[ri]); - innerR = (ri + 1) * cell_width; - outerR = (ri + 2) * cell_width; - theta1 = thetaStep * ci; - theta2 = thetaStep * (ci + 1); - - innerVt1 = vt_from_angle(theta1, innerR); - innerVt2 = vt_from_angle(theta2, innerR); - outerVt2 = vt_from_angle(theta2, outerR); - - if(type == INWARD_WALL || type == INWARD_CCW_WALL) { - polyline_join([innerVt1, innerVt2]) - circle(wall_thickness / 2); - } + for(rows = maze, cell = rows) { + ri = cell[0]; + ci = cell[1]; + type = cell[2]; + thetaStep = 360 / len(maze[ri]); + innerR = (ri + 1) * cell_width; + outerR = (ri + 2) * cell_width; + theta1 = thetaStep * ci; + theta2 = thetaStep * (ci + 1); + + innerVt1 = vt_from_angle(theta1, innerR); + innerVt2 = vt_from_angle(theta2, innerR); + outerVt2 = vt_from_angle(theta2, outerR); + + if(type == INWARD_WALL || type == INWARD_CCW_WALL) { + polyline_join([innerVt1, innerVt2]) + circle(wall_thickness / 2); + } - if(type == CCW_WALL || type == INWARD_CCW_WALL) { - polyline_join([innerVt2, outerVt2]) - circle(wall_thickness / 2); - } - } + if(type == CCW_WALL || type == INWARD_CCW_WALL) { + polyline_join([innerVt2, outerVt2]) + circle(wall_thickness / 2); + } } // outmost walls diff --git a/docs/lib3x-mz_theta_get.md b/docs/lib3x-mz_theta_get.md index 8b595ca8..71b0e062 100644 --- a/docs/lib3x-mz_theta_get.md +++ b/docs/lib3x-mz_theta_get.md @@ -23,31 +23,29 @@ It's a helper for getting data from a theta-maze cell. function vt_from_angle(theta, r) = [r * cos(theta), r * sin(theta)]; maze = mz_theta_cells(rows, beginning_number); - for(rows = maze) { - for(cell = rows) { - ri = mz_theta_get(cell, "r"); - ci = mz_theta_get(cell, "c"); - type = mz_theta_get(cell, "t"); - thetaStep = 360 / len(maze[ri]); - innerR = (ri + 1) * cell_width; - outerR = (ri + 2) * cell_width; - theta1 = thetaStep * ci; - theta2 = thetaStep * (ci + 1); - - innerVt1 = vt_from_angle(theta1, innerR); - innerVt2 = vt_from_angle(theta2, innerR); - outerVt2 = vt_from_angle(theta2, outerR); - - if(type == "INWARD_WALL" || type == "INWARD_CCW_WALL") { - polyline_join([innerVt1, innerVt2]) - circle(wall_thickness / 2); - } + for(rows = maze, cell = rows) { + ri = mz_theta_get(cell, "r"); + ci = mz_theta_get(cell, "c"); + type = mz_theta_get(cell, "t"); + thetaStep = 360 / len(maze[ri]); + innerR = (ri + 1) * cell_width; + outerR = (ri + 2) * cell_width; + theta1 = thetaStep * ci; + theta2 = thetaStep * (ci + 1); + + innerVt1 = vt_from_angle(theta1, innerR); + innerVt2 = vt_from_angle(theta2, innerR); + outerVt2 = vt_from_angle(theta2, outerR); + + if(type == "INWARD_WALL" || type == "INWARD_CCW_WALL") { + polyline_join([innerVt1, innerVt2]) + circle(wall_thickness / 2); + } - if(type == "CCW_WALL" || type == "INWARD_CCW_WALL") { - polyline_join([innerVt2, outerVt2]) - circle(wall_thickness / 2); - } - } + if(type == "CCW_WALL" || type == "INWARD_CCW_WALL") { + polyline_join([innerVt2, outerVt2]) + circle(wall_thickness / 2); + } } thetaStep = 360 / len(maze[rows - 1]); diff --git a/docs/lib3x-nz_cell.md b/docs/lib3x-nz_cell.md index 0e35b969..120e6bdc 100644 --- a/docs/lib3x-nz_cell.md +++ b/docs/lib3x-nz_cell.md @@ -26,9 +26,8 @@ It's an implementation of [Worley noise](https://en.wikipedia.org/wiki/Worley_no feature_points = [for(pt_angle = pts_angles) pt_angle[0] + half_size]; noised = [ - for(y = [0:size.y - 1]) - for(x = [0:size.x - 1]) - [x, y, nz_cell(feature_points, [x, y])] + for(y = [0:size.y - 1], x = [0:size.x - 1]) + [x, y, nz_cell(feature_points, [x, y])] ]; max_dist = max([for(n = noised) n[2]]); diff --git a/docs/lib3x-nz_perlin3.md b/docs/lib3x-nz_perlin3.md index 6454a486..d79ac94f 100644 --- a/docs/lib3x-nz_perlin3.md +++ b/docs/lib3x-nz_perlin3.md @@ -18,15 +18,13 @@ Returns the 3D [Perlin noise](https://en.wikipedia.org/wiki/Perlin_noise) value seed = rand(0, 255); noised = [ - for(z = [0:.2:5]) - for(y = [0:.2:5]) - for(x = [0:.2:5]) - [x, y, z, nz_perlin3(x, y, z, seed)] + for(z = [0:.2:5], y = [0:.2:5], x = [0:.2:5]) + [x, y, z, nz_perlin3(x, y, z, seed)] ]; for(nz = noised) { if(nz[3] > 0.2) { - translate([nz[0], nz[1], nz[2]]) + translate([nz.x, nz.y, nz.z]) cube(.2); } } diff --git a/docs/lib3x-nz_perlin3s.md b/docs/lib3x-nz_perlin3s.md index a5d3605b..d057c8bf 100644 --- a/docs/lib3x-nz_perlin3s.md +++ b/docs/lib3x-nz_perlin3s.md @@ -27,11 +27,11 @@ Returns 3D [Perlin noise](https://en.wikipedia.org/wiki/Perlin_noise) values at points_with_h = [ for(ri = [0:len(points) - 1]) - let(ns = nz_perlin2s(points[ri], seed)) - [ - for(ci = [0:len(ns) - 1]) - [points[ri][ci][0], points[ri][ci][1], ns[ci] + 1] - ] + let(ns = nz_perlin2s(points[ri], seed)) + [ + for(ci = [0:len(ns) - 1]) + [points[ri][ci][0], points[ri][ci][1], ns[ci] + 1] + ] ]; h_scale = 1.5; @@ -39,7 +39,7 @@ Returns 3D [Perlin noise](https://en.wikipedia.org/wiki/Perlin_noise) values at for(i = [0:len(row) - 1]) { p = row[i]; pts = [ - for(z = [0:.2:p[2] * h_scale]) [p[0], p[1], z] + for(z = [0:.2:p[2] * h_scale]) [p.x, p.y, z] ]; noise = nz_perlin3s(pts, seed); for(j = [0:len(pts) - 1]) { diff --git a/docs/lib3x-nz_worley2.md b/docs/lib3x-nz_worley2.md index b681b1df..714fb600 100644 --- a/docs/lib3x-nz_worley2.md +++ b/docs/lib3x-nz_worley2.md @@ -27,9 +27,8 @@ It divides the space into grids. The nucleus of each cell is randomly placed in seed = 51; points = [ - for(y = [0:size.y - 1]) - for(x = [0:size.x - 1]) - [x, y] + for(y = [0:size.y - 1], x = [0:size.x - 1]) + [x, y] ]; cells = [for(p = points) nz_worley2(p.x, p.y, seed, grid_w, dist)]; @@ -43,7 +42,7 @@ It divides the space into grids. The nucleus of each cell is randomly placed in square(1); } - cells_pts = dedup([for(c = cells) [c[0], c[1]]]); + cells_pts = dedup([for(c = cells) [c.x, c.y]]); for(p = cells_pts) { translate(p) linear_extrude(max_dist) diff --git a/docs/lib3x-nz_worley2s.md b/docs/lib3x-nz_worley2s.md index 3fb59968..44355d8d 100644 --- a/docs/lib3x-nz_worley2s.md +++ b/docs/lib3x-nz_worley2s.md @@ -25,9 +25,8 @@ It divides the space into grids. The nucleus of each cell is randomly placed in seed = 51; points = [ - for(y = [0:size.y - 1]) - for(x = [0:size.x - 1]) - [x, y] + for(y = [0:size.y - 1], x = [0:size.x - 1]) + [x, y] ]; cells = nz_worley2s(points, seed, grid_w, dist); diff --git a/docs/lib3x-nz_worley3s.md b/docs/lib3x-nz_worley3s.md index 76560fe9..d4ffc1c6 100644 --- a/docs/lib3x-nz_worley3s.md +++ b/docs/lib3x-nz_worley3s.md @@ -26,7 +26,7 @@ It divides the space into grids. The nucleus of each cell is randomly placed in cells = nz_worley3s(points, seed, grid_w, dist); for(i = [0:len(cells) - 1]) { - c = (norm([cells[i][0], cells[i][1], cells[i][2]]) % 20) / 20; + c = (norm([cells[i].x, cells[i].y, cells[i].z]) % 20) / 20; color([c, c, c]) translate(points[i]) cube(1); diff --git a/docs/lib3x-path_extrude.md b/docs/lib3x-path_extrude.md index 954a774f..c01be8df 100644 --- a/docs/lib3x-path_extrude.md +++ b/docs/lib3x-path_extrude.md @@ -255,12 +255,13 @@ So, which is the correct method? Both methods are correct when you provide only shape_pentagram_pts = shape_pentagram(star_radius); // not closed perfectly - translate([-8, 0, 0]) path_extrude( - shape_pentagram_pts, - [each pts, pts[0]], - closed = true, - method = "AXIS_ANGLE" - ); + translate([-8, 0, 0]) + path_extrude( + shape_pentagram_pts, + [each pts, pts[0]], + closed = true, + method = "AXIS_ANGLE" + ); // adjust it path_extrude( @@ -272,12 +273,13 @@ So, which is the correct method? Both methods are correct when you provide only ); // "EULER_ANGLE" is easy in this situation - translate([0, 8, 0]) path_extrude( - shape_pentagram_pts, - [each pts, pts[0]], - closed = true, - method = "EULER_ANGLE" - ); + translate([0, 8, 0]) + path_extrude( + shape_pentagram_pts, + [each pts, pts[0]], + closed = true, + method = "EULER_ANGLE" + ); ![path_extrude](images/lib3x-path_extrude-9.JPG) diff --git a/docs/lib3x-path_scaling_sections.md b/docs/lib3x-path_scaling_sections.md index 59b9d3ce..1a8e00ff 100644 --- a/docs/lib3x-path_scaling_sections.md +++ b/docs/lib3x-path_scaling_sections.md @@ -45,7 +45,6 @@ You can use any point as the first point of the edge path. Just remember that yo use ; use ; - taiwan = shape_taiwan(100); fst_pt = [13, 0, 0]; diff --git a/docs/lib3x-pie.md b/docs/lib3x-pie.md index 9f61f3a6..b9180f1c 100644 --- a/docs/lib3x-pie.md +++ b/docs/lib3x-pie.md @@ -13,8 +13,10 @@ Creates a pie (circular sector). Its `$fa`, `$fs` and `$fn` are consistent with use ; pie(radius = 20, angle = [210, 310]); - translate([-15, 0, 0]) pie(radius = 20, angle = [45, 135]); - translate([15, 0, 0]) pie(radius = 20, angle = [45, 135], $fn = 12); + translate([-15, 0, 0]) + pie(radius = 20, angle = [45, 135]); + translate([15, 0, 0]) + pie(radius = 20, angle = [45, 135], $fn = 12); ![pie](images/lib3x-pie-1.JPG) diff --git a/docs/lib3x-polyhedra_superellipsoid.md b/docs/lib3x-polyhedra_superellipsoid.md index b0129128..b2adea50 100644 --- a/docs/lib3x-polyhedra_superellipsoid.md +++ b/docs/lib3x-polyhedra_superellipsoid.md @@ -17,9 +17,8 @@ Creates a [superellipsoid](https://en.wikipedia.org/wiki/Superellipsoid). step = 0.5; - for(e = [0:step:4]) { - for(n = [0:step:4]) - translate([e / step, n / step] * 3) + for(e = [0:step:4], n = [0:step:4]) { + translate([e / step, n / step] * 3) superellipsoid(e, n); } diff --git a/docs/lib3x-polyline2d.md b/docs/lib3x-polyline2d.md index 67f539ba..e7874b04 100644 --- a/docs/lib3x-polyline2d.md +++ b/docs/lib3x-polyline2d.md @@ -23,16 +23,23 @@ Creates a polyline from a list of `[x, y]` coordinates. When the end points are use ; $fn = 24; - polyline2d(points = [[1, 2], [-5, -4], [-5, 3], [5, 5]], width = 1, - endingStyle = "CAP_ROUND"); + polyline2d( + points = [[1, 2], [-5, -4], [-5, 3], [5, 5]], + width = 1, + endingStyle = "CAP_ROUND" + ); ![polyline2d](images/lib3x-polyline2d-2.JPG) use ; $fn = 24; - polyline2d(points = [[1, 2], [-5, -4], [-5, 3], [5, 5]], width = 1, - startingStyle = "CAP_ROUND", endingStyle = "CAP_ROUND"); + polyline2d( + points = [[1, 2], [-5, -4], [-5, 3], [5, 5]], + width = 1, + startingStyle = "CAP_ROUND", + endingStyle = "CAP_ROUND" + ); ![polyline2d](images/lib3x-polyline2d-3.JPG) diff --git a/docs/lib3x-ptf_bend.md b/docs/lib3x-ptf_bend.md index af705bd6..51226a7f 100644 --- a/docs/lib3x-ptf_bend.md +++ b/docs/lib3x-ptf_bend.md @@ -21,12 +21,10 @@ Transforms a point inside a rectangle to a point of an arc. radius = 20; angle = 180; - for(i = [0:len(t) - 1]) { - for(pt = vx_ascii(t[i], invert = true)) { - bended = ptf_bend(size, pt + [i * 8, 0], radius, angle); - translate(bended) - sphere(0.5, $fn = 24); - } + for(i = [0:len(t) - 1], pt = vx_ascii(t[i], invert = true)) { + bended = ptf_bend(size, pt + [i * 8, 0], radius, angle); + translate(bended) + sphere(0.5, $fn = 24); } ![ptf_bend](images/lib3x-ptf_bend-1.JPG) diff --git a/docs/lib3x-ptf_rotate.md b/docs/lib3x-ptf_rotate.md index 6784e8da..6029a496 100644 --- a/docs/lib3x-ptf_rotate.md +++ b/docs/lib3x-ptf_rotate.md @@ -22,8 +22,8 @@ Rotates a point `a` degrees around the axis of the coordinate system or an arbit hull() { sphere(1); translate(ptf_rotate(point, a)) - rotate(a) - sphere(1); + rotate(a) + sphere(1); } ![ptf_rotate](images/lib3x-ptf_rotate-1.JPG) @@ -57,7 +57,7 @@ Rotates a point `a` degrees around the axis of the coordinate system or an arbit hull() { sphere(1); translate(v) - sphere(1); + sphere(1); } p = [10, 10, 0]; diff --git a/docs/lib3x-sf_solidify.md b/docs/lib3x-sf_solidify.md index dc718476..a22ac32c 100644 --- a/docs/lib3x-sf_solidify.md +++ b/docs/lib3x-sf_solidify.md @@ -27,18 +27,18 @@ It solidifies two square surfaces, described by a m * n list of `[x, y, z]`s. surface1 = [ for(y = [min_value:resolution:max_value]) - [ - for(x = [min_value:resolution:max_value]) - [x, y, f(x, y) + 100] - ] + [ + for(x = [min_value:resolution:max_value]) + [x, y, f(x, y) + 100] + ] ]; surface2 = [ for(y = [min_value:resolution:max_value]) - [ - for(x = [min_value:resolution:max_value]) - [x, y, -f(x, y) - 100] - ] + [ + for(x = [min_value:resolution:max_value]) + [x, y, -f(x, y) - 100] + ] ]; sf_solidify(surface1, surface2); diff --git a/docs/lib3x-sf_solidifyT.md b/docs/lib3x-sf_solidifyT.md index 9f5e95e6..a0f7a90a 100644 --- a/docs/lib3x-sf_solidifyT.md +++ b/docs/lib3x-sf_solidifyT.md @@ -29,27 +29,25 @@ It solidifies two surfaces with triangular mesh. use ; thickness = .2; - a_step = 10; + a_step = 15; r_step = 0.2; scale = 100; - function f(x, y) = (pow(y,2)/pow(2, 2))-(pow(x,2)/pow(2, 2)); + function f(x, y) = (y ^ 2 - x ^ 2) / 4; pts2d = [ - for(a = [a_step:a_step:360]) - for(r = [r_step:r_step:2]) - let( - x = round(r * cos(a) * 100) / 100, - y = round(r * sin(a) * 100) / 100 - ) - [x, y] + for(a = [a_step:a_step:360], r = [r_step:r_step:2]) + let( + x = r * cos(a), + y = r * sin(a) + ) + [x, y] ]; points1 = [for(p = pts2d) scale * [p.x, p.y, f(p.x, p.y)]]; points2 = [for(p = points1) [p.x, p.y, p.z - scale * thickness]]; triangles = tri_delaunay(pts2d); - sf_solidifyT(points1, points2, triangles); ![sf_solidifyT](images/lib3x-sf_solidifyT-2.JPG) \ No newline at end of file diff --git a/docs/lib3x-sf_thicken.md b/docs/lib3x-sf_thicken.md index c17e3873..5996aab9 100644 --- a/docs/lib3x-sf_thicken.md +++ b/docs/lib3x-sf_thicken.md @@ -28,10 +28,8 @@ It thickens a surface, described by a m * n list of `[x, y, z]`s. use ; function f(x, y) = - 30 * ( - cos(sqrt(pow(x, 2) + pow(y, 2))) + - cos(3 * sqrt(pow(x, 2) + pow(y, 2))) - ); + let(leng = norm([x, y])) + 30 * (cos(leng) + cos(3 * leng)); thickness = 3; min_value = -200; @@ -40,10 +38,10 @@ It thickens a surface, described by a m * n list of `[x, y, z]`s. surface1 = [ for(y = [min_value:resolution:max_value]) - [ - for(x = [min_value:resolution:max_value]) - [x, y, f(x, y) + 100] - ] + [ + for(x = [min_value:resolution:max_value]) + [x, y, f(x, y) + 100] + ] ]; sf_thicken(surface1, thickness); @@ -60,10 +58,10 @@ It thickens a surface, described by a m * n list of `[x, y, z]`s. surface1 = [ for(y = [min_value:resolution:max_value]) - [ - for(x = [min_value:resolution:max_value]) - [x, y, f(x, y) + 100] - ] + [ + for(x = [min_value:resolution:max_value]) + [x, y, f(x, y) + 100] + ] ]; sf_thicken(surface1, thickness, direction = [1, 1, -1]); diff --git a/docs/lib3x-sf_thickenT.md b/docs/lib3x-sf_thickenT.md index c05e9421..348134a3 100644 --- a/docs/lib3x-sf_thickenT.md +++ b/docs/lib3x-sf_thickenT.md @@ -18,7 +18,7 @@ It thickens a surface with triangular mesh. a_step = 15; r_step = 0.2; - function f(x, y) = (y^2 - x^2) / 4; + function f(x, y) = (y ^ 2 - x ^ 2) / 4; points = [ for(a = [a_step:a_step:360], r = [r_step:r_step:2]) diff --git a/docs/lib3x-shape_circle.md b/docs/lib3x-shape_circle.md index 7dea0ef3..6fcc3c58 100644 --- a/docs/lib3x-shape_circle.md +++ b/docs/lib3x-shape_circle.md @@ -23,9 +23,9 @@ Sometimes you need all points on the path of a circle. Here's the function. Its step_angle = 360 / leng; for(i = [0:leng - 1]) { translate(points[i]) - rotate([90, 0, 90 + i * step_angle]) - linear_extrude(1, center = true) - text("A", valign = "center", halign = "center"); + rotate([90, 0, 90 + i * step_angle]) + linear_extrude(1, center = true) + text("A", valign = "center", halign = "center"); } ![shape_circle](images/lib3x-circle_path-1.JPG) \ No newline at end of file diff --git a/docs/lib3x-shape_liquid_splitting.md b/docs/lib3x-shape_liquid_splitting.md index b8e10b93..b6e76832 100644 --- a/docs/lib3x-shape_liquid_splitting.md +++ b/docs/lib3x-shape_liquid_splitting.md @@ -36,7 +36,8 @@ Returns shape points of two splitting liquid shapes, kind of how cells divide. T shape_pts = shape_liquid_splitting(radius, centre_dist); width = centre_dist / 2 + radius; - rotate_extrude() difference() { + rotate_extrude() + difference() { polygon(shape_pts); translate([-width, -radius]) @@ -57,11 +58,11 @@ Returns shape points of two splitting liquid shapes, kind of how cells divide. T width = centre_dist + radius * 2; rotate_extrude() - intersection() { - rotate(-90) polygon(shape_pts); + intersection() { + rotate(-90) polygon(shape_pts); - translate([radius / 2, 0]) - square([radius, width], center = true); - } + translate([radius / 2, 0]) + square([radius, width], center = true); + } ![shape_liquid_splitting](images/lib3x-shape_liquid_splitting-3.JPG) \ No newline at end of file diff --git a/docs/lib3x-shape_superformula.md b/docs/lib3x-shape_superformula.md index 02d3a242..e36e2f2b 100644 --- a/docs/lib3x-shape_superformula.md +++ b/docs/lib3x-shape_superformula.md @@ -14,21 +14,30 @@ Returns shape points of a [Superformula](https://en.wikipedia.org/wiki/Superform phi_step = 0.05; polygon(shape_superformula(phi_step, 3, 3, 4.5, 10, 10)); + translate([3, 0]) polygon(shape_superformula(phi_step, 4, 4, 12, 15, 15)); + translate([6, 0]) polygon(shape_superformula(phi_step, 7, 7, 10, 6, 6)); + translate([9, 0]) polygon(shape_superformula(phi_step, 5, 5, 4, 4, 4)); translate([0, -4]) - scale(0.8) polygon(shape_superformula(phi_step, 5, 5, 2, 7, 7)); + scale(0.8) + polygon(shape_superformula(phi_step, 5, 5, 2, 7, 7)); + translate([3, -4]) - scale(0.25) polygon(shape_superformula(phi_step, 5, 5, 2, 13, 13)); + scale(0.25) + polygon(shape_superformula(phi_step, 5, 5, 2, 13, 13)); + translate([6, -4]) polygon(shape_superformula(phi_step, 4, 4, 1, 1, 1)); + translate([9, -4]) - scale(0.3) polygon(shape_superformula(phi_step, 4, 4, 1, 7, 8)); + scale(0.3) + polygon(shape_superformula(phi_step, 4, 4, 1, 7, 8)); ![shape_superformula](images/lib3x-shape_superformula-1.JPG) diff --git a/docs/lib3x-sphere_spiral.md b/docs/lib3x-sphere_spiral.md index b70f3996..a4a529ea 100644 --- a/docs/lib3x-sphere_spiral.md +++ b/docs/lib3x-sphere_spiral.md @@ -47,8 +47,8 @@ Creates all points and angles on the path of a spiral around a sphere. It return for(pa = points_angles) { translate(pa[0]) rotate(pa[1]) - rotate([90, 0, 90]) linear_extrude(1) - text("A", valign = "center", halign = "center"); + rotate([90, 0, 90]) linear_extrude(1) + text("A", valign = "center", halign = "center"); } %sphere(40); diff --git a/docs/lib3x-stereographic_extrude.md b/docs/lib3x-stereographic_extrude.md index 470c92f6..73f950e1 100644 --- a/docs/lib3x-stereographic_extrude.md +++ b/docs/lib3x-stereographic_extrude.md @@ -19,13 +19,15 @@ The 2D polygon should center at the origin and you have to determine the side le stereographic_extrude(shadow_side_leng = dimension, convexity = 10) text( "M", size = dimension, - valign = "center", halign = "center" + valign = "center", + halign = "center" ); color("black") text( "M", size = dimension, - valign = "center", halign = "center" + valign = "center", + halign = "center" ); ![stereographic_extrude](images/lib3x-stereographic_extrude-1.JPG) diff --git a/docs/lib3x-sweep.md b/docs/lib3x-sweep.md index 73f7362a..6e973514 100644 --- a/docs/lib3x-sweep.md +++ b/docs/lib3x-sweep.md @@ -53,11 +53,11 @@ The indexes of the above triangles is: // spin section1 sections = [ for(i = [0:55]) - [ - for(p = section1) - let(pt = ptf_rotate(p, [90, 0, 10 * i])) - [pt.x, pt.y , pt.z + i] - ] + [ + for(p = section1) + let(pt = ptf_rotate(p, [90, 0, 10 * i])) + [pt.x, pt.y , pt.z + i] + ] ]; sweep(sections); @@ -83,11 +83,11 @@ The indexes of the above triangles is: // spin section1 sections = [ for(i = [0:55]) - [ - for(p = section1) - let(pt = ptf_rotate(p, [90, 0, 10 * i])) - [pt.x, pt.y , pt.z + i] - ] + [ + for(p = section1) + let(pt = ptf_rotate(p, [90, 0, 10 * i])) + [pt.x, pt.y , pt.z + i] + ] ]; sweep(sections, "HOLLOW"); @@ -111,11 +111,11 @@ The indexes of the above triangles is: // spin section1 sections = [ for(i = [0:55]) - [ - for(p = section1) - let(pt = ptf_rotate(p, [90, 0, 10 * i])) - [pt.x, pt.y , pt.z + i] - ] + [ + for(p = section1) + let(pt = ptf_rotate(p, [90, 0, 10 * i])) + [pt.x, pt.y , pt.z + i] + ] ]; sweep( diff --git a/docs/lib3x-vrn3_from.md b/docs/lib3x-vrn3_from.md index 3bd857a2..34898fde 100644 --- a/docs/lib3x-vrn3_from.md +++ b/docs/lib3x-vrn3_from.md @@ -54,9 +54,7 @@ Create a 3D version of [Voronoi diagram](https://en.wikipedia.org/wiki/Voronoi_d r * sin(yas[i]) ] ]; - - thickness = 2; - + difference() { sphere(r); diff --git a/docs/lib3x-vx_curve.md b/docs/lib3x-vx_curve.md index 76819499..dca38d3d 100644 --- a/docs/lib3x-vx_curve.md +++ b/docs/lib3x-vx_curve.md @@ -24,8 +24,8 @@ Draws a voxel-by-voxel curve from control points. The curve is drawn only from t ]; for(pt = vx_curve(pts)) { - translate(pt) - cube(1); + translate(pt) + cube(1); } #for(pt = pts) { diff --git a/docs/lib3x-vx_from.md b/docs/lib3x-vx_from.md index 25e74a7e..32c6d26f 100644 --- a/docs/lib3x-vx_from.md +++ b/docs/lib3x-vx_from.md @@ -26,11 +26,13 @@ Given a list of 0s and 1s that represent a black-and-white image. This function ]); for(pt = pts) { - translate(pt) square(1); + translate(pt) + square(1); } translate([8, 0]) for(pt = pts) { - translate(pt) text("A", font="Arial Black", 1); + translate(pt) + text("A", font="Arial Black", 1); } ![vx_from](images/lib3x-vx_from-1.JPG)