Tag Info

Hot answers tagged

26

You are correct about the behavior of computations done from preemptive links. So-called "preemptive evaluations" have been around since version 6. They are a class of evaluations that all work through the same mechanism. When Mathematica checks to see if a user interrupt has been requested, which it does at a high rate most of the time, it also looks to see ...


17

Yes, I did something like that and it runs very very nicely. What I implemented is a dynamic Newton fractale visualizer where you can manipulate the number and position of the complex roots, the colours and the gamma correction settings from the Mathematica side. These values are sent to a parallel C++ implementation which calculates the fractale into a ...


12

Preliminaries As Todd has indicated in his answer which has a lot of excellent information, the situation where the described behaviour will actually trigger problems will be very rare. I also read from his answer that WRI doesn't consider this behavior to be a bug and my hopes that this might change in future versions are low or nonexistent. I show ...


12

Here's a V9 solution (CellObject is new in V9). The output is two cells, one with graphics to be edited and another that contains an InputField. The connection between them is maintained by identifying the graphics cell by the tag CellTags -> "DrawOnMe", which needs to be unique, and by the V9 feature CurrentValue[cellobj, CellChangeTimes]. By putting ...


12

Well, Mike Honeychurch and Leonid Shifrin have pretty much covered the ground, but I have one thing to add, which, while based only on observed behavior, I think helps explain what's going on. Set and SetDelayed both create OwnValues is the form HoldPattern[symbol] :> code. The difference is that code is unevaluated in the case of SetDelayed. ...


11

My take: toward[p1_, p2_, v_: .05] := p1 + v Normalize[p2 - p1]; {n, r} = {4, 3}; DynamicModule[{pts, history}, pts = r {Cos[#], Sin[#]} & /@ Range[2 Pi/n, 2 Pi, 2 Pi/n]; history = {pts}; Print[Dynamic[ListPlot[Transpose@history, AspectRatio -> Automatic, Joined -> True, PlotStyle -> Directive[Thick, CapForm["Round"]], ...


11

I am writing this answer for a person who is familiar with Mathematica and has a good understanding of computer programming, but not so familiar with Java programming language. Using GraphStream is not so different from using any other Java library. You need to download the GraphStream core files from here and extract it. gs-core-1.1.2.jar is the only file ...


11

A reliable composition of elements Perhaps something like this? (Edit: Fixed to work with Autorun.) Note that the InputField label is editable, similar to a normal Manipulator. One can also add an additional InputField[Dynamic @ x] if a regular InputField is desired. Manipulate[ x, {{x, 1.}, 1., 100., Row[{Slider[Dynamic[Log10[#], (x = 10^#) &], ...


11

I prefer Bold and Larger in Style: Animate[ Grid[ Partition[ Table[ Style[i, Bold, Larger, If[i > j, Black, If[ PrimeQ @ i, Blue, Gray]]], {i, 100}], 10], Spacings -> {1, 1}], {j, 0, 100}, Paneled -> False] but if you like delete from ...


11

One way is to create a Polygon and transform the vertices under the flow. I used NDSolve to solve the flow for initial points in a square containing the OP's disk. Then I made a listable Function that can be applied to a the vertices of the polygon. Since only the flow depends on the time t, I used a GraphicsComplex so that the vertices come first as a ...


10

Nice answer by Mohsen, +1. I am continually impressed by the quality of the J/Link and .NET/Link expertise on this site. I have a couple remarks and then an example program. The question asked about some general tips for getting started with J/Link. This GraphStream library provides a perfect example for the typical workflow of a J/Link project. The ...


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

Thanks to Michael E2's comment, the following approach is successful. The method sets up a scheduled task that (at certain resolution res) monitors the elapsed $time and compares it to the dynamic $max. If $time is more than allowed by $max, it calls the front-end "EvaluatorAbort". Attributes[dynamicTimeConstrained] = {HoldAll}; ...


9

A direct replacement Perhaps your specific example might best be handled with: Array[ (a[##] = f[##]) &, Table[4, {3}] ] { . . . { . . . {f[3, 1, 1], f[3, 1, 2], f[3, 1, 3], f[3, 1, 4]} . . . } . . . } Where 4 is n and 3 is the number of loops. Output it was included above for illustration; it may be suppressed with CompoundExpression: ...


9

Here's a fairly simple way to fix your Manipulate by applying Dynamic to ListPlot. Manipulate[ (* Beep[]; *) data = function @ Range[-Pi*10., Pi*10, Pi/1000]; Dynamic @ ListPlot[data, PlotRange -> {{start, stop}, Automatic}], {function, {Sin, Cos, Tan}}, {start, 1, Length[data]}, {{stop, 300}, 1, Length[data]}, {data, ControlType -> None}] ...


9

I would approach this problem a bit differently. I would provide each such notebook with an initialization button at its top, right under its title, if any. By pressing this button, the dynamic apdating would be enabled. How to do it technically, is already in the comment of belisarius. The further is only a question of a design. The latter should be ...


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 definitely should not rely on this behavior. There is one and only one proper way to get dynamic behavior for the rhs of a front end option, and that is to wrap Dynamic around the entirety of the option. The only exceptions to this rule at present are certain options which will assume the Dynamic if one doesn't exist, such as CellDynamicExpression and ...


8

You need to identify the graphics object with a (local, dynamic) variable to use in a call to Export[]. It's easy to use a button to export from within the scope of the dynamic block. If you want the button to be external to the block, you can use TaggingRules as explained in your link. I prefer not to play around with extending the scope of variables. ...


8

Artes's answer is just fine. This variation works as follows. When you click on a number, the background of that number turns yellow and that of each of its divisors turns light blue. DynamicModule[{s = 101}, Grid[Partition[Dynamic@Button[Style[#, 16], (s = #), Background -> Which[ # == s, Yellow, Divisible[s, #], LightBlue, True, White], Appearance ...


7

This is good reason to use the second argument of dynamics. Manipulate[ function; (*just to allow tracking, since not explicity in the command*) ListLinePlot[data, PlotRange -> {{start, stop}, Automatic}, ImageSize -> 300, ImagePadding -> 30, Frame -> True, FrameLabel -> {{None, None}, {"x", function}} ], Grid[ { ...


7

I believe that Mathematica feeds the input string in free-form linguistic input to the function WolframAlpha. Try something like Manipulate[ If[in =!= "", WolframAlpha[in], "Enter input"], {{in, ""}, InputField[Dynamic[in], String] &} ] Response to comment I can't find a definitive statement in the documentation that an internet connection is ...


7

Here's a trivial example of the method in my comment. I've used total absolute difference for error (you can use whatever you please), and I put in a Pause so you can observe the effect for this trivial problem that would be blink-of-an-eye fast. In reality, you'd want to use UpdateInterval or equivalent, or Sow if you want the "history" post-run. Doing ...


6

This can be achieved by adding the ControllerLinking -> False option to any Graphics3D objects that you do not wish to be affected by the external controller. For example with Manipulate[ Graphics3D[{FaceForm[Hue[x]], Cuboid[]}, ControllerLinking -> False], {x, 0, 1}] my joystick x-axis changes the colour but the cube doesn't rotate.


6

To initialize and localize pt, you should use DynamicModule instead of Manipulate. Though I think using Setting in your code is not the best way to do what it does, however, the un-movable locator issue is NOT simply due to Setting but also because both Manipulate and LocatorPane are trying to dynamically set the value of pt, which is the control variable ...


6

Label this a most bizarre bug -- I can reproduce the problem (v9.0.0.0) -- the fix, change all those integer fractions in Blend to decimals.. This fails: jet[u_?NumericQ] := Blend[{{0, RGBColor[0, 0, 1/9]}, {1, Red}}, u] /; 0 <= u <= 1 This works jet[u_?NumericQ] := Blend[{{0, RGBColor[0, 0, 0.11111111]}, {1, Red}}, u] /; 0 <= u <= 1 ...


6

The hard part is the drag/drop and move around different shapes in Graphic Let's assume you want to drag a circle, then I would use a Locator with Appearance->None as center of the circle so that when you click and drag near the center you can move the circle around. Another example would be a triangle where you can drag the corners. In this ...


6

There are many issues arasing while creating complex DynamicModules. Usually I'm not even sure what to ask about. This is how I would do this in order to avoid putting procedures inside Button: testModule2[] := DynamicModule[{randomGrid, x = "", button}, button = Button["Create table", ff]; ...


6

What I really wanted to post was an alternative way of generating the grid. In my humble opinion, it's better to do it with Table without Partition as it looks better in code. But since Animate has already been dealt with, three times over, let me also use an alternative method for that: color[n_] := Style[n, Which[100 Clock[1, 10] < n, Black, PrimeQ@n, ...


6

This should work: rows = 3; cols = 4; data = RandomInteger[{1, 100}, {rows, cols}]; names = {"First", "Second", "Third", "Fourth"}; sortBy[data_, idx_] := If[idx == 0, data, Sort[data, #1[[idx]] < #2[[idx]] &]]; Dynamic@Grid@Prepend[data, Array[Button[names[[#]], data = sortBy[data, #]] &, cols]]



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