sysconf topleft
# 
proc drawpins . .
   for i to 9
      for j to i
         move (15 - i) * 3 + j * 6 i * 6 + 2
         circle 0.7
      .
   .
.
color 555
drawpins
background -1
# 
len box[] 10
len x[] 10
len y[] 10
# 
proc showbox . .
   for i to 10
      x = i * 6 + 15
      for j to box[i]
         move x 100 - j * 4 + 2
         circle 2
      .
   .
.
proc init . .
   for i to 10
      box[i] = 0
      x[i] = 0
   .
.
# 
color 543
on timer
   if busy = 0 and random 4 = 1
      busy = 1
      for i to 10
         if x[i] = 0
            x[i] = 48
            y[i] = 2
            break 1
         .
      .
   else
      busy = 0
   .
   clear
   showbox
   for i to 10
      x = x[i]
      if x > 0
         if y[i] <= 56
            y[i] += 2
            if y[i] mod 6 = 2
               x += 3 * (random 2 * 2 - 3)
               x[i] = x
            .
         else
            idx = (x - 15) / 6
            y[i] += 4
            if y[i] >= 96 - box[idx] * 4
               x[i] = 0
               box[idx] += 1
               if box[idx] > 10
                  init
                  break 1
               .
            .
         .
         move x y[i]
         circle 2
      .
   .
   timer 0.1
.
timer 0
