Re: Dynamic Module with Trigger
- To: mathgroup at smc.vnet.net
- Subject: [mg96694] Re: [mg96671] Dynamic Module with Trigger
- From: John Fultz <jfultz at wolfram.com>
- Date: Sat, 21 Feb 2009 19:38:06 -0500 (EST)
- Reply-to: jfultz at wolfram.com
In your toy example, just add a second argument to the Dynamic[a] in the Slider... DynamicModule[{a = 3, b}, b = a; Column[{Slider[Dynamic[a, (a = #; b = a) &], {0, 10, 1}], Trigger[Dynamic[b, (b = #; b = b + a) &], {0, 25}], Row[{Dynamic[{a, b}]}], Graphics[{Dynamic[Line[{{0, 0}, {b, 0}}]]}, PlotRange -> {{0, 40}, {-10, 10}}, Frame -> True, ImageSize -> 72 6]}]] I also changed the b=2 initialization to instead be b=a. There are some things I would change about this example which would make the code considerably simpler and easier to understand, but I've decided not to since I don't know how inaccurately this example reflects real difficulties you're dealing with in your real-world problem. But, for example, I would have changed the first Dynamic to use (a=#, b=0)&, the Trigger Dynamic to use no special function at all, and the Graphics Dynamic to show a line with the computed point a+b. Sincerely, John Fultz jfultz at wolfram.com User Interface Group Wolfram Research, Inc. On Fri, 20 Feb 2009 05:45:50 -0500 (EST), Hugh Goyder wrote: > In the toy DynamicModule below pressing the trigger makes an existing > line longer. The initial length of the line is controlled by a slider. > The module works but I want to add the feature that when I move the > slider the trigger resets itself and the now changed initial line is > drawn. Is it possible to do this? > > Thanks > Hugh Goyder > > DynamicModule[ > {a = 3, b}, > b = 2; > Column[{ > Slider[Dynamic[a], {0, 10, 1}], > Trigger[Dynamic[b, (b = #; b = b + a) &], {0, 25}], > Row[{Dynamic[{a, b}]}], > Graphics[{Dynamic[Line[{{0, 0}, {b, 0}}]]}, > PlotRange -> {{0, 40}, {-10, 10}}, Frame -> True, > ImageSize -> 72 6] > }] > ]