# Issue with pure function when mapping dynamic content within graphics scope

What I am trying to achieve can be described using following code:

vector = {{0, 0}, {1, 0}};
Graphics[Circle[#, 1] & /@ vector]


In the above, a pure function is applied to Map given vector to construct a set of Circle objects. Same type of logic is applied below, however it does not compile and throws an error:

Coordinate {{0, 0}, {1, 0}} should be a pair of numbers, or a Scaled or Offset form

Code:

DynamicModule[
(*Parameters*)
range = {{0, 100}, {0, 100}};
vector = {{0, 0}, {1, 0}};

EventHandler[
Show[
Graphics[{
(*Composition*)
Line[Dynamic[vector]],
Circle[#, radius] & /@ Dynamic[vector] (*Error*)
}],
(*Options*)
PlotRange -> range, Axes -> True],
{
(*Events*)
"MouseClicked" :> (AppendTo[vector, MousePosition["Graphics"]])
}
]
]


Why does MMA generates the error stated above and how can it be bypassed? Essentially, I want to have a Circle around ea. Point which forms part of the Line.

• Dynamic[vector] is incorrect usage. Best way to always think about Dynamic is that it dynamically updates pixels on the screen. When you consider that definition it should be apparent why Dynamic[vector] is incorrect. The next problem that arises from that usage is that the syntax for Circle becomes incorrect which is why you see the pink boxes. Oct 31, 2015 at 4:40

When mapping a vector onto Circle it needs to be just that, a vector with Head List. Putting Dynamic outside of Graphics will allow you to see the circles as they update. Alternatively wrap it around the mapping onto Circle. Additionally your use of Show is redundant.

DynamicModule[{vector, range, radius},
radius = 5;range = {{0, 100}, {0, 100}};vector = {{0, 0}, {1, 0}};

EventHandler[
Graphics[{Line[Dynamic[vector]],
PlotRange -> range, Axes -> True],
{"MouseClicked" :> (AppendTo[vector, MousePosition["Graphics"]])}]]


• You say to put Dynamic outside of Graphics. That is not consistent with your example. Typo? Oct 31, 2015 at 23:09
• @JackLaVigne you can have it outside of Graphics or wrapped around the mapping onto Circle. Nov 1, 2015 at 2:33

You need just a single Dynamic in front of Show. Because, as stated in the documentation,

Dynamic does its work entirely in the front end, you cannot use it inside functions that need to access the value of an expression in order to do their work.

Prepend Show with Dynamic, will update the graphics output whenever there is a change in the values of the variables used inside:

DynamicModule[
(*Parameters*)
range = {{0, 100}, {0, 100}};
vector = {{0, 0}, {1, 0}};

EventHandler[
Dynamic@Show[
Graphics[{
(*Composition*)
Line[vector],