|
29 | 29 | // Two workarounds exist, neither of which are needed in newer versions of OpenSCAD. The workarounds solve the problem because |
30 | 30 | // **modules** execute after their parent, so the `$` variables **are** available in modules. You can put your assignments |
31 | 31 | // in a `let()` module, or you can wrap your child in a `union()`. Both methods appear below. |
32 | | -// ``` |
| 32 | +// Figure(2D,NoScales): This example shows how we can use `$idx` to produce **different** geometry at each index. |
33 | 33 | // xcopies(n=10, spacing=10) |
34 | 34 | // text(str($idx)); |
| 35 | +// Continues: |
35 | 36 | // ``` |
36 | | -// Figure(2D): This example shows how we can use `$idx` to produce **different** geometry at each index. |
37 | 37 | // xcopies(n=10, spacing=10) |
38 | 38 | // text(str($idx)); |
39 | | -// Continues: |
40 | | -// Figure(2D): Here the children are sometimes squares and sometimes circles as determined by the conditional `if` module. This use of `if` is OK because no variables are assigned. |
| 39 | +// ``` |
| 40 | +// Figure(2D,NoScales): Here the children are sometimes squares and sometimes circles as determined by the conditional `if` module. This use of `if` is OK because no variables are assigned. |
41 | 41 | // xcopies(n=4, spacing=10) |
42 | 42 | // if($idx%2==0) circle(r=3,$fn=16); |
43 | 43 | // else rect(6); |
|
47 | 47 | // if($idx%2==0) circle(r=3,$fn=16); |
48 | 48 | // else rect(6); |
49 | 49 | // ``` |
50 | | -// Figure(2D): Suppose we would like to color odd and even index copies differently. In this example we compute the color for a given child from `$idx` using the ternary operator. The `let()` module is a module that sets variables and makes them available to its children. Note that multiple assignments in `let()` are separated by commas, not semicolons. |
| 50 | +// Figure(2D,NoScales): Suppose we would like to color odd and even index copies differently. In this example we compute the color for a given child from `$idx` using the ternary operator. The `let()` module is a module that sets variables and makes them available to its children. Note that multiple assignments in `let()` are separated by commas, not semicolons. |
51 | 51 | // xcopies(n=6, spacing=10){ |
52 | 52 | // let(c = $idx % 2 == 0 ? "red" : "green") |
53 | 53 | // color(c) rect(6); |
|
59 | 59 | // color(c) rect(6); |
60 | 60 | // } |
61 | 61 | // ``` |
62 | | -// Figure(2D): This example shows how you can change the position of children adaptively. If you want to avoid repeating your code for each case, this requires storing a transformation matrix in a variable and then applying it using `multmatrix()`. We wrap our code in `union()` to ensure that it works in OpenSCAD 2021.01. |
| 62 | +// Figure(2D,NoScales): This example shows how you can change the position of children adaptively. If you want to avoid repeating your code for each case, this requires storing a transformation matrix in a variable and then applying it using `multmatrix()`. We wrap our code in `union()` to ensure that it works in OpenSCAD 2021.01. |
63 | 63 | // xcopies(n=5,spacing=10) |
64 | 64 | // union() |
65 | 65 | // { |
|
72 | 72 | // xcopies(n=5,spacing=10) |
73 | 73 | // union() |
74 | 74 | // { |
75 | | -// shiftback = $idx%2==0 ? back(5) : IDENT; |
| 75 | +// shiftback = $idx%2==0 ? back(10) : IDENT; |
76 | 76 | // spin = zrot(180*$idx/4); |
77 | | -// multmatrix(shiftback*spin) stroke([[-4,0],[4,0]],endcap2="arrow2",width=1/2); |
| 77 | +// multmatrix(shiftback*spin) stroke([[-4,0],[4,0]],endcap2="arrow2",width=3/4,color="red"); |
78 | 78 | // } |
79 | 79 | // ``` |
80 | 80 |
|
@@ -473,31 +473,31 @@ function zcopies(spacing, n, l, sp, p=_NO_ARG) = |
473 | 473 | // See Also: move_copies(), xcopies(), ycopies(), zcopies(), line_copies(), rot_copies(), xrot_copies(), yrot_copies(), zrot_copies(), arc_copies(), sphere_copies() |
474 | 474 | // |
475 | 475 | // Examples: |
476 | | -// line_copies(10) sphere(d=1); |
477 | | -// line_copies(10, n=5) sphere(d=1); |
478 | | -// line_copies([10,5], n=5) sphere(d=1); |
479 | | -// line_copies(spacing=10, n=6) sphere(d=1); |
480 | | -// line_copies(spacing=[10,5], n=6) sphere(d=1); |
481 | | -// line_copies(spacing=10, l=50) sphere(d=1); |
482 | | -// line_copies(spacing=10, l=[50,30]) sphere(d=1); |
483 | | -// line_copies(spacing=[10,5], l=50) sphere(d=1); |
484 | | -// line_copies(l=50, n=4) sphere(d=1); |
485 | | -// line_copies(l=[50,-30], n=4) sphere(d=1); |
| 476 | +// line_copies(10) sphere(d=1.5); |
| 477 | +// line_copies(10, n=5) sphere(d=3); |
| 478 | +// line_copies([10,5], n=5) sphere(d=3); |
| 479 | +// line_copies(spacing=10, n=6) sphere(d=3); |
| 480 | +// line_copies(spacing=[10,5], n=6) sphere(d=3); |
| 481 | +// line_copies(spacing=10, l=50) sphere(d=3); |
| 482 | +// line_copies(spacing=10, l=[50,30]) sphere(d=3); |
| 483 | +// line_copies(spacing=[10,5], l=50) sphere(d=3); |
| 484 | +// line_copies(l=50, n=4) sphere(d=3); |
| 485 | +// line_copies(l=[50,-30], n=4) sphere(d=3); |
486 | 486 | // Example(FlatSpin,VPD=133): |
487 | | -// line_copies(p1=[0,0,0], p2=[5,5,20], n=6) cube(size=[3,2,1],center=true); |
| 487 | +// line_copies(p1=[0,0,0], p2=[5,5,20], n=6) cuboid([3,2,1]); |
488 | 488 | // Example(FlatSpin,VPD=133): |
489 | | -// line_copies(p1=[0,0,0], p2=[5,5,20], spacing=6) cube(size=[3,2,1],center=true); |
| 489 | +// line_copies(p1=[0,0,0], p2=[5,5,20], spacing=6) cuboid([3,2,1]); |
490 | 490 | // Example: All children are copied to each position |
491 | 491 | // line_copies(l=20, n=3) { |
492 | 492 | // cube(size=[1,3,1],center=true); |
493 | 493 | // cube(size=[3,1,1],center=true); |
494 | 494 | // } |
495 | 495 | // Example(2D): The functional form of line_copies() returns a list of transform matrices. |
496 | 496 | // mats = line_copies([10,5],n=5); |
497 | | -// for (m = mats) multmatrix(m) circle(d=2); |
| 497 | +// for (m = mats) multmatrix(m) circle(d=3); |
498 | 498 | // Example(2D): The functional form of line_copies() returns a list of points if given a point. |
499 | 499 | // pts = line_copies([10,5],n=5,p=[0,0,0]); |
500 | | -// move_copies(pts) circle(d=2); |
| 500 | +// move_copies(pts) circle(d=3); |
501 | 501 |
|
502 | 502 | module line_of(spacing, n, l, p1, p2) { |
503 | 503 | deprecate("line_copies"); |
|
0 commit comments