
logo backcolor = colorchoice "Select background color"
set ndots = buttonchoice "How many dots?" "50|100|200|300|500"


// generate a pointlist with random points...
pointlist startcapture
repeat :ndots [ 
  pu; moveto (random winwide) (random winhigh)
  ]
pointlist endcapture

// display points as red dots..
logo linecolor = backcolor
logo fillcolor = "red"
set i = 1
repeat :ndots [ 
  pu; moveto point :i
  pd; circle 3
  fillshape
  incr i by 1
  ]

repeat untilbreak [    // episodes..
  logo linecolor = colorchoice "Select line color"
  set maxdist = buttonchoice "To connect 2 dots they must be closer than:" "50|75|100|125|150|200|300|500"

  // connect nearby dots with purple lines..
  message "Connecting the dots.." "Stop"
  pu; moveto point (random :ndots)
  set count = 0
  repeat untilbreak [
    if keypress = true [ break ]
    incr count by 1
    if :count > 500 [ buttonchoice "Can't find any dots close enough.." "OK" ; break ]
    set newpt = point (random :ndots)
    if (distanceto :newpt) > :maxdist [ continue ]
    pd; moveto :newpt; pu
    wait 12
    set count = 0
    ]

  // optional color fill..
  if buttonchoice "Fill with color?" "No|Yes" = "yes" [ 
    logo fillcolor = colorchoice "Choose fill color"
    fillshape 
    pu
    ]
  if buttonchoice "Keep going?" "Yes|No" = "no" [ break ]
  ]
