# convert to loop?

6 messages
Open this post in threaded view
|

## convert to loop?

 this segment is simple, even to me: for (rcount = [0: 1: 3]){         rotate([0, 0, rcount * 90])         make something appear } the problem I'm hoping to solve involves translation of the "something" the translation values for x and y for the four rotations above toggle through positive and negative values ```loop number x y rotation 0 -v -v 0 1 +v -v 90 2 +v +v 180 3 -v +v 270 ```Is there a method to accomplish this in a single loop? I feel that if it has to be accomplished in a nested loop, the four individual code segments without a loop is just as easy to implement.
Open this post in threaded view
|

## Re: convert to loop?

 Use pow(-1, rcount)
Open this post in threaded view
|

## Re: convert to loop?

 That is an interesting approach. It provides for a single value through the loop, toggling from positive to negative, but how to use the same loop variable (rcount) to provide for the non-toggling aspect of the second coordinate of the translate command?
Open this post in threaded view
|

## Re: convert to loop?

 In reply to this post by herdima Like this? ```module pointer() { polygon(points=[[1,0], [-1,0.5], [-1,-0.5]], paths=[[0,1,2,]], convexity = 1); } v = 10; xtran=[-v, v, v, -v]; ytran=[-v, -v, v, v]; rot = [0,90,180,270]; pointer(); for (i = [0:3]) { echo(i, xtran[i], ytran[i], rot[i]); translate([xtran[i], ytran[i],0]) rotate (rot[i],0,0) pointer(); }```