MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Dynamic Module with Trigger

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96710] Re: [mg96671] Dynamic Module with Trigger
  • From: "David Park" <djmpark at comcast.net>
  • Date: Sat, 21 Feb 2009 19:41:01 -0500 (EST)
  • References: <15627703.1235127915317.JavaMail.root@m02>

Hugh,

I'm not certain if I understand your objective. Why don't you draw your line
from zero to a + b, and keep b 'pure'? The following uses the slider to
readjust a and adjusts the existing line for the new value of a.

DynamicModule[
 {a = 3, b = 0},
 Column[
  {Slider[Dynamic[a], {0, 10, 1}], Trigger[Dynamic[b], {0, 25}],
   Row[{Dynamic[{a, a + b}]}],
   Graphics[
    {Dynamic[Line[{{0, 0}, {a + b, 0}}]]}, 
    PlotRange -> {{0, 40}, {-10, 10}},
    Frame -> True,
    ImageSize -> 72 6]}]]

On the other hand, the following uses the slider to adjust a and sets b to
zero.

DynamicModule[
 {a = 3, b = 0},
 Column[
  {Slider[Dynamic[a, (a = #; b = 0) &], {0, 10, 1}], 
   Trigger[Dynamic[b], {0, 25}],
   Row[{Dynamic[{a, a + b}]}],
   Graphics[
    {Dynamic[Line[{{0, 0}, {a + b, 0}}]]}, 
    PlotRange -> {{0, 40}, {-10, 10}},
    Frame -> True,
    ImageSize -> 72 6]}]]

Also, I wouldn't initialize b to anything other than zero or the initial
value of the Trigger.


David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/  



From: Hugh Goyder [mailto:h.g.d.goyder at cranfield.ac.uk] 

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]
   }]
 ]




  • Prev by Date: Re: Dynamic Module with Trigger
  • Next by Date: Re: pfa2pfb
  • Previous by thread: Re: Dynamic Module with Trigger
  • Next by thread: Stylesheets