Re: Manipulate with variable number of controls
- To: mathgroup at smc.vnet.net
- Subject: [mg107789] Re: Manipulate with variable number of controls
- From: Simon <simonjtyler at gmail.com>
- Date: Fri, 26 Feb 2010 04:05:39 -0500 (EST)
- References: <hm6ts0$ggb$1@smc.vnet.net>
Theres an example in tutorial/AdvancedDynamicFunctionality (section Nesting Dynamic) that has a variable number of controls. Maybe you could use something similar... On Feb 26, 6:33 am, "Dominic" <miliot... at rtconline.com> wrote: > Hi, > > Can I set up a Manipulate with a variable number of controls? The code > below draws 4 circles and line segments between them at the angles given > by the slider values. As you can see, I had to hard-code the function > for the lines, and the number of controls given by the size of rtable. > Is is possible to dynamically construct this Manipulate based on the > size of rtable? I noticed if I try to build a control outside of > Manipulate such as mycontrol1={"t1",0,2 PI}, and then use mycontrol1 > inside of Manipulate, it doesn't work. Also, I use > LocalizeVariales->False since I then go on to use the values of the > angles (t1,t2, ...) in the program. > > Can anybody help me to get this working for arbitrary-size rtable with > not more than five entries, or is Manipulate not capable of dynamically > allocating a variable number of controls? > > Thanks guys, > > Dominic > > rtable = {0, 1, 2, 3, 4}; > t1 = 0; > t2 = 0; > t3 = 0; > t4 = 0; > > myf4[t1_, t2_, t3_, t4_] := > {Line[{{Re[rtable[[1]]*Exp[I*t1]], > Im[rtable[[1]]*Exp[I*t1]]}, > {Re[rtable[[2]]*Exp[I*t1]], > Im[rtable[[2]]*Exp[I*t1]]}}], > Line[{{Re[rtable[[2]]*Exp[I*t2]], > Im[rtable[[2]]*Exp[I*t2]]}, > {Re[rtable[[3]]*Exp[I*t2]], > Im[rtable[[3]]*Exp[I*t2]]}}], > Line[{{Re[rtable[[3]]*Exp[I*t3]], > Im[rtable[[3]]*Exp[I*t3]]}, > {Re[rtable[[4]]*Exp[I*t3]], > Im[rtable[[4]]*Exp[I*t3]]}}], > Line[{{Re[rtable[[4]]*Exp[I*t4]], > Im[rtable[[4]]*Exp[I*t4]]}, > {Re[rtable[[5]]*Exp[I*t4]], > Im[rtable[[5]]*Exp[I*t4]]}}]}; > > mycircles = Table[Circle[{0, 0}, > rtable[[n]]], {n, 2, > Length[rtable]}]; > > Manipulate[Show[Graphics[ > {myf4[t1, t2, t3, t4], mycircles}], > Axes -> True, PlotRange -> > {{-5, 5}, {-5, 5}}], {t1, 0, 2*Pi}, > {t2, 0, 2*Pi}, {t3, 0, 2*Pi}, > {t4, 0, 2*Pi}, LocalizeVariables -> > False]