I am aware this might seem like a duplicate, however, I have viewed these posts (1 & 2) and have been unable to solve this.

   DynamicModule[{pt = {.5, .5}, ll = {}, 
  base = {White, Rectangle[{0, 0}, {2, 2}]}}, 
 LocatorPane[Dynamic[pt, (AppendTo[ll, #]; pt = Last@ll) &], 
      With[{newpts = Partition[ll, 2, 1]}, 
       Table[{i, Line[newpts[[i]]]}, {i, 1, Length[newpts], 1}]]}]

enter image description here

Would someone be able to help me to solve this error? Thank in advance


A few things in your code were unnecessary (e.g. the Show before Graphics) and others were confusing and the cause of your trouble. Note that Line will take a list of points and construct a polygonal line from it automatically; you do not need to produce each segment in a separate Line statement, so the Partition and Table bits can be avoided.

This works with no errors:

 {pt = {.5, .5}, ll = {}, base = {White, Rectangle[{0, 0}, {2, 2}]}},
   Dynamic[pt, (AppendTo[ll, #]; pt = Last@ll) &],
   Dynamic@Graphics[{base, Line@Partition[ll, 2, 1]}]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.