How to use Repeat with Execute command?

Thulani shared this question 1 week ago
Answered

I have a list

objsLstAsStr = {"C","D","E","F","G"}

I would like to use Repeat to execute the following with few lines of code since I will be having many points.

SetCoords(C,x(Element[L_1', 1]),y(Element[L_1', 1]))

SetCoords(D,x(Element[L_1', 2]),y(Element[L_1', 2]))

SetCoords(E,x(Element[L_1', 3]),y(Element[L_1', 3]))

SetCoords(F,x(Element[L_1', 4]),y(Element[L_1', 4]))

SetCoords(G,x(Element[L_1', 5]),y(Element[L_1', 5]))

Please assist.

Comments (9)

photo
2

Maybe you mean something as the following example

(shift all points, listed with their names as string in L_1: 1 unit to down)

L_1= {"C","D","E","F","G"}

or better because the object-name of the point can be changed:

L_1= {Name(C),Name(D), Name(E), Name(F), Name(G)}

and in a script:

Execute(Zip("SetValue("+P+", "+P+"+(0,-1))", P, L_1))

is the same as: Execute(Zip("SetCoords("+P+", x("+P+")+0, y("+P+")-1)", P, L_1))

Note1: Zip create a list of strings:

{"SetValue(C, C+(0,-1))", "SetValue(D, D+(0,-1))", ...... , "SetValue(G, G+(0,-1))"}

And Execute(<list>) interprete this stings (in the list) as commands.

Note2: see also in the manual the very great possibility with parameters (%1,%2....%9) for Execute.

photo
1

This looks promising, however what if (0,-1) should come from a corresponding point in another parallel list.

Execute(Zip("SetValue("+P+", "+P+"+(0,-1))", P, L_1))

photo
photo
2

this `?

photo
1

Hi rami and thancks

can you change this file so that point gradually moved?

photo
3

I think the iteration of Execute() need too much time (Image bucking).

Attached a solution with classic animation in combination with Execute()

Principle: the movable points during animation are hide, separate points are animated and after animation the movable points are Execute() and visible.

photo
2

Improved version.

Here the original points are moved and the scripts are much more easy.

The Execute() works quick enough (he is not recursive, this was my thinking before version 01B).

Prinziple:

At begin animation (button1) the actual positions of all points (C..G) are saved (in L_0)

The Execute() is in the animation-slider (timeP) and move all named points to the actual position between L_0 and L_1 depending on timeP.

photo
1

This is more than perfect for my solution. Thanks a lot. I have to go through the manual.

photo
1

thanks alot rami

this is very exelent

photo
photo
2

or this (only for demonstrate another possibility)

without objsLstAsStr but point-names with same prefix and with index from 1 to n.

=====================================================


  • If MovePoint01 or MovePoint02 not is what you are looking for: descript it's in natural Language (not in GGB-language).
  • If the syntax of MovePoint01 or MovePoint02 not is clear for you: ask so specific as possible.
  • But first check what is generated: XX= <script-command without Execute (only the Zip-Part)>

example for MovePoint02 (script in AllBlueGoHome):

xxBlue=(Sequence("SetValue(B_{"+n+"}, Home_B("+n+") )",n,1,8))

------------------------------

Note: Monday I'm outside for 1 week (no response from my side)

© 2018 International GeoGebra Institute