mirror of https://github.com/vitalif/openscad
Add example for indexed access using children().
parent
d8b67df3a2
commit
80da2525b4
|
@ -0,0 +1,60 @@
|
|||
echo(version=version());
|
||||
|
||||
// children() with a parameter allows access to a specific child
|
||||
// object with children(0) being the first one. In addition the
|
||||
// $children variable is automatically set to the number of child
|
||||
// objects.
|
||||
|
||||
module align_in_grid_and_add_text()
|
||||
{
|
||||
if ($children == 0) {
|
||||
text("Nothing...", 6, halign = "center");
|
||||
} else {
|
||||
t = $children == 1 ? "one object" : str($children, " objects ");
|
||||
text(t, 6, halign = "center");
|
||||
|
||||
for (y = [0 : $children - 1])
|
||||
for (x = [0 : $children - 1])
|
||||
translate([15 * (x - ($children - 1) / 2), 20 * y + 40, 0])
|
||||
scale(1 + x / $children)
|
||||
children(y);
|
||||
}
|
||||
}
|
||||
|
||||
color("red")
|
||||
translate([-100, -20, 0])
|
||||
align_in_grid_and_add_text();
|
||||
|
||||
color("yellow")
|
||||
translate([-50, -20, 0])
|
||||
align_in_grid_and_add_text() {
|
||||
cube(5, center = true);
|
||||
}
|
||||
|
||||
color("cyan")
|
||||
translate([0, -20, 0])
|
||||
align_in_grid_and_add_text() {
|
||||
cube(5, center = true);
|
||||
sphere(4);
|
||||
}
|
||||
|
||||
color("green")
|
||||
translate([50, -20, 0])
|
||||
align_in_grid_and_add_text() {
|
||||
cube(5, center = true);
|
||||
sphere(4);
|
||||
cylinder(r = 4, h = 5);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Written in 2015 by Torsten Paul <Torsten.Paul@gmx.de>
|
||||
//
|
||||
// To the extent possible under law, the author(s) have dedicated all
|
||||
// copyright and related and neighboring rights to this software to the
|
||||
// public domain worldwide. This software is distributed without any
|
||||
// warranty.
|
||||
//
|
||||
// You should have received a copy of the CC0 Public Domain
|
||||
// Dedication along with this software.
|
||||
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
Loading…
Reference in New Issue