Loops
Iterate over the values in a vector or range.
for (z = [-1, 1]){
translate([0, 0, z])
cube(size = 1, center = false);
}
for ( i = [0 : 5] ){
rotate( i * 360 / 6, [1, 0, 0])
translate([0, 10, 0])
sphere(r = 1);
}
or
for (i = [10:50]){
echo(i);
}
// Note: The middle parameter in the range designation ('0.2' in this case) is the 'increment-by' value
for ( i = [0 : 0.2 : 5] ){
rotate( i * 360 / 6, [1, 0, 0])
translate([0, 10, 0])
sphere(r = 1);
}
or
intersection() {
cube(size=180, center=true);
union(){
for (i=[0:10:350]) {
rotate(a=[0,0,i]) {
translate([20, 0, 0]) {
rotate(a=[20,0,0]) {
cylinder(h=200, r1=5, r2=5, center=true);
}
}
}
}
}
}
Ranjit Bhatnagar
for (i = [0:5]) {
echo(360*i/6, sin(360*i/6)*80, cos(360*i/6)*80);
translate([sin(360*i/6)*80, cos(360*i/6)*80, 0 ])
cylinder(h = 10, r=10);
}
for (i = [0 : 0.1 : 6]) {
echo(360*i/6, sin(360*i/6)*80, cos(360*i/6)*80);
translate([sin(360*i/6)*80, cos(360*i/6)*80, 0 ])
cylinder(h = 10, r=5);
}