Tag Info

Hot answers tagged

10

Dynamic has this build into it. You can take advantage of the Dynamic second and third arguments. The second argument of evaluate as the dynamic is being updated. The third argument is evaluated when the mouse is released. Which is what you want. To illustrate, here is an example, where f[r] and g[r] are inside the arguments of the slider itself. This is ...


9

ControlActive is useful for this purpose: DynamicModule[{r = 1, old = 1} , Grid[ { {Slider[Dynamic[r]], SpanFromLeft} , {Dynamic[f[r]], Dynamic[g[ControlActive[r, old = r]; old]]} } ] ] The variable old has been introduced to hold the "old" value of r. The key expression is ControlActive[r, old = r]; old, which always returns the value of ...


8

You have to study the documentation carefully, but I agree that help-pages like the one of Manipulate are very densely packed with information. In the Details and Options section you find how to set options for controls: {{u,...},...,opts} control with particular options The non-obvious part is, that you have to set the ControlType as well to make ...


5

That is how you might do it within the framework of Manipulate: Manipulate[ Plot[a*x^3 + b*x^2 + c*x + d, {x, -4, 4}], Row[{Control[{{a, 1, "a"}, 0, 3}], Spacer[20], Control[{{b, 2, "b"}, 0, 5}]}], Row[{Control[{{c, 1, "c"}, 0, 4}], Spacer[20], Control[{{d, 0, "d"}, 0, 2}]}], ControlPlacement -> {Top, Top, Bottom, Bottom} ] It ...


5

You might use Row. For example: Manipulate[{u, v}, Row[{Control[{u, 0, 6}], Control[{v, 10, 20}]}, Spacer[10]]]


5

I think you've got to take over placement manually. First declare the variable setter with no control (None). Next add a SetterBar. Put this inside a Pane so you can control placement. The ImageSize of the Pane needs to be determined by hand. You can use ImageSize -> Full, which makes it fill the width of the notebook window -- perhaps desirable or ...


4

Here is an option: Manipulate[{}, Dynamic@If[visible != "hide x-slider", Control[{x, 0, 1}], Invisible@Control[{x, 0, 1}]], {visible, {"hide x-slider", "show x-slider"}, ControlType -> PopupMenu}]


4

You can use DynamicWrapper[] : mchoice[question_, answers_, correct_, var_] := DynamicModule[{x}, DynamicWrapper[ Column[{ ActionMenu[question, MapThread[#1 :> (x = #2) &, {answers, Range@Length@answers}]], PaneSelector[MapThread[#1 -> #2 &, {Range@Length@answers, answers}], Dynamic[x]] }], var = (x == correct)]]


4

Is this what you are after? DynamicModule[{x = 0, x2 = 0}, Framed[ Column[{ Dynamic[{"a", "b", "c"}.{x, x2, 1 - x - x2}], LabeledSlider[Dynamic[x, (x = #; x2 = Min[x2, 1 - x];) &], {0, 1}], Dynamic@LabeledSlider[Dynamic[x2], {0, 1 - x}] }] , Alignment -> Center, ImageSize -> {400, 100}]] Or maybe, other way when x and x2 ...


4

Not much to add to the code below. Indeed, it seems EventHandler is a solution to your problem. You need PassEventsDown to let the slider update. DynamicModule[{r = 1, s = 1}, EventHandler[ Grid[ { {Slider[Dynamic[r]], SpanFromLeft}, {Dynamic[f[r]], Dynamic[g[s]]} } ], {"MouseUp" :> (s = r)}, PassEventsDown -> True ] ]


4

This will work. The only change is that I removed the option ControlType and added a "slider function" at the end of the control for v. Note that Pinguin Dirks suggestion in the comments also works, is more convenient and he beat me to it :). Still I guess this code shows how you can have even more control over your slider. Manipulate[ With[{ar = 1/(2*Pi), ...


4

Put your options inside your control (you don't need those cumbersome constructions with patterns and Dynamic@Animate): Animate[Plot[Sin[x + a], {x, 0, 10}, Filling -> 0], {{a, 0, ""}, 0, 5, AppearanceElements -> "PlayPauseButton"}, AnimationRunning -> False]


3

With Manipulate, you can demonstrate the relationship of the three simplex coordinates. Since x and x2 define the value of x3, I added Enabled -> False to its controller. Another way would be to set up some rules about which variable to decrease if any of the three variables is increased (i.e. decrease x3 if x or x2 is increased, decrease x if x3 or x2 is ...


3

You could label the points: Manipulate[ Column[{Dynamic@ Grid@Map[Pane[#, {60, 20}] &, Transpose@points, {2}]}], {{points, ({#, 0.1} &) /@ {-1, -1.5, 1.5, 1}}, LocatorPane[ Dynamic[points, (points = {#, 0.1} & /@ First /@ #) &], Graphics[{}, PlotRange -> {{-2, 2}, {-.5, .5}}, AxesOrigin -> {0, 0}, Axes ...


3

Inside a Manipulate it's pretty straightforward: this[x_] := x; that[x_] := x^2; Manipulate[p[3], {p, {this, that}}] Here p takes on value of one of the function names, and then the chosen function is executed when the button is pressed.


3

This is not an answer but an extended comment on andre's answer. I up-voted the answer because it's basically a good one. However, I want to point out two problems with the answer as posted. The following doesn't work because y has a value when mchoice is called. y = 42; Dynamic @ y mchoice["argon", {"solid", "liquid", "gas"}, 3, y] The following ...


3

EventHandler DynamicModule[ {u = CharacterRange["a", "e"]}, EventHandler[ Framed[Dynamic@First@u], { {"MouseClicked", 1} :> (u = RotateLeft[u, 1]), {"MouseClicked", 2} :> (u = RotateRight[u, 1]) } ] ] But since second button is showing menu it is not very useful :) It is only a method so You can change event trigger. You can ...


3

Here are a couple variations, including Kuba's ButtonBar, which has yet to be posted as an answer. buttonFunctionBar[lbls_, func_, opts : OptionsPattern[ButtonBar]] := ButtonBar[# :> func[#] & /@ lbls, opts]; actionFunctionMenu[title_, lbls_, func_, opts : OptionsPattern[ActionMenu]] := ActionMenu[title, # :> func[#] & /@ lbls, opts]; ...


3

There is really a general method build into Dynamics in Mathematica meant for these things. It is the second argument of dynamics. One can think of the second argument of Dynamics as an event callback. In GUI, this acts exactly as an event callback in traditional GUI programming, where when one changes state of a UI control, a callback is fired, where one ...


2

A couple more ways. PaneSelector, with a blank Row: Manipulate[{x, y}, PaneSelector[{True -> Control[{x, 0, 1}], False -> Row[{}]}, Dynamic[visible != "only y-slider visible"]], PaneSelector[{True -> Control[{y, 0, 1}], False -> Row[{}]}, Dynamic[visible != "only x-slider visible"]], {visible, {"only x-slider visible", "only y-slider ...


2

So you want a SetterBar which provides the argument values to a function Foo? Isn't the most simple way to do this {SetterBar[Dynamic[y], Range[5]], Dynamic[Foo[y]]} Without explicit Dynamic there is maybe really only the solution which was already pointed out by bill s. Manipulate[Foo[v], {v, {1, 2, 3, 4}}] Or if you want it packed into a ...


2

I had to struggle with similar things before, and I found that the best way to control location of controls with respect to output they affect is to discard the whole Manipulate display area and do everything in the control area itself using Dynamics. This way you can control exactly where each slider/controller is located. This is done using basic Grid ...


2

I think you just have to experiment with adjusting the Sine plot. Here is what I got by doing a little trial and error work. Manipulate[Plot[a b c x, {x, 0, 100}, PlotRange -> {0, 100}], {{a, 1}, 0, 2, Appearance -> "Labeled"}, {{b1, 1}, 0, 2, Appearance -> "Labeled"}, {{b2, 1}, 0, 2, Appearance -> "Labeled"}, Dynamic[Plot[Sin[t], {t, 0, ...


2

As hinted in the comment, you might try it this way: Manipulate[ Column[{Style[{{a, 0, 0}, {0, b, 0}, {0, 0, c}} // MatrixForm, FontSize -> 18, FontColor -> Black, TextAlignment -> Left], Graphics3D[{GraphicsComplex[streckung[a, b, c], Polygon[i]]}, Axes -> True, Boxed -> True, PlotRange -> {{-5, 5}, {-5, 5}, {-5, 5}}, ...


1

Initialization for CheckboxBar works pretty much as for any type of control. {{checkBoxes, initial-checked-values, ""}, value-list, ControlType -> CheckboxBar}] For example, Manipulate[Row[{"Boxes checked: ", Length@checkBoxes}], {{checkBoxes, {1, 3}, ""}, {1, 2, 3, 4}, ControlType -> CheckboxBar}] will produce the following initial state when ...


1

Illustrating the advice of rm-rf: DynamicModule[ {f, a, b, c, d}, f = a*x^3 + b*x^2 + c*x + d; Column[ {Row[{"a ", Slider[Dynamic[a], {0, 3}], "b ", Slider[Dynamic[b], {0, 3}]}, Frame -> True], Dynamic@ Plot[f, {x, -4, 4}, ImageSize -> 400, PlotRange -> {-50, 50}, PlotStyle -> {Red, Thick}, PlotLabel -> ...


1

I downloaded and examined the CDF you refer to. I conclude from my examination that what looks like a highly stylized TabView may actually be a custom control built based on EvenHandler. Often when one sees what look like fancy versions of Mathematica controls in sophisticated CDFs, they are custom replacements such as the one you were looking at. As far as ...



Only top voted, non community-wiki answers of a minimum length are eligible