function animateChoice(target) {
  var angle = 0;
  var speed = 0;
  var oldx = -10;
  var oldy = -10;
  var decelFromAngle = -1;
  var allowDecel = false;
  for (var i = 0; true; i++) {
    angle = angle + speed;
    if (angle > radians) angle -= radians;
    if (i < animStartSteps || (speed < maxSpeed && !allowDecel)) {
      speed = speed + accel;
      if (speed > maxSpeed) {
        speed = maxSpeed;
        /* when we reach max speed, we know how long it takes
         * to accelerate, and therefore how long to decelerate, so
         * we can work out what angle to start decelerating from */
        if (decelFromAngle < 0) {
          decelFromAngle = target-angle;
          while (decelFromAngle < 0) decelFromAngle += radians;
          while (decelFromAngle > radians) decelFromAngle -= radians;
        }
      }
    } else {
      if (!allowDecel && (angle < decelFromAngle) && (angle+speed >= decelFromAngle)) allowDecel = true;
      if (allowDecel) speed = speed - accel;
      if (speed < minSpeed) speed = minSpeed;
      if (speed == minSpeed && angle < target && angle+speed >= target) return;
    }

    var r = i/2;
    if (r > ballTrack) r = ballTrack;
    var x = centreX+Math.cos(angle)*r;
    var y = centreY+Math.sin(angle)*r;
    g.setColor('#000000');
    g.fillCircle(oldx,oldy,ballSize+1);
    g.setColor('#ffffff');
    g.fillCircle(x, y, ballSize);
    oldx=x;
    oldy=y;
  }
}
// animate a ball rolling around and settling at "target" radians
animate a ball rolling around and settling at "target" radians
animate a ball rolling around and settling at " target " radians
function animateChoice(target) {
  var angle = 0;
  var speed = 0;
  var oldx = -10;
  var oldy = -10;
  var decelFromAngle = -1;
  var allowDecel = false;
  for (var i = 0; true; i++) {
    angle = angle + speed;
    if (angle > radians) angle -= radians;
    if (i < animStartSteps || (speed < maxSpeed && !allowDecel)) {
      speed = speed + accel;
      if (speed > maxSpeed) {
        speed = maxSpeed;
        if (decelFromAngle < 0) {
          decelFromAngle = target-angle;
          while (decelFromAngle < 0) decelFromAngle += radians;
          while (decelFromAngle > radians) decelFromAngle -= radians;
        }
      }
    } else {
      if (!allowDecel && (angle < decelFromAngle) && (angle+speed >= decelFromAngle)) allowDecel = true;
      if (allowDecel) speed = speed - accel;
      if (speed < minSpeed) speed = minSpeed;
      if (speed == minSpeed && angle < target && angle+speed >= target) return;
    }
    var r = i/2;
    if (r > ballTrack) r = ballTrack;
    var x = centreX+Math.cos(angle)*r;
    var y = centreY+Math.sin(angle)*r;
    g.setColor('#000000');
    g.fillCircle(oldx,oldy,ballSize+1);
    g.setColor('#ffffff');
    g.fillCircle(x, y, ballSize);
    oldx=x;
    oldy=y;
  }
}
function animateChoice ( target ) { var angle = 0 ; var speed = 0 ; var oldx = - 10 ; var oldy = - 10 ; var decelFromAngle = - 1 ; var allowDecel = false ; for ( var i = 0 ; true ; i ++ ) { angle = angle + speed ; if ( angle > radians ) angle -= radians ; if ( i < animStartSteps || ( speed < maxSpeed && ! allowDecel ) ) { speed = speed + accel ; if ( speed > maxSpeed ) { speed = maxSpeed ; if ( decelFromAngle < 0 ) { decelFromAngle = target - angle ; while ( decelFromAngle < 0 ) decelFromAngle += radians ; while ( decelFromAngle > radians ) decelFromAngle -= radians ; } } } else { if ( ! allowDecel && ( angle < decelFromAngle ) && ( angle + speed >= decelFromAngle ) ) allowDecel = true ; if ( allowDecel ) speed = speed - accel ; if ( speed < minSpeed ) speed = minSpeed ; if ( speed == minSpeed && angle < target && angle + speed >= target ) return ; } var r = i / 2 ; if ( r > ballTrack ) r = ballTrack ; var x = centreX + Math . cos ( angle ) * r ; var y = centreY + Math . sin ( angle ) * r ; g . setColor ( '#000000' ) ; g . fillCircle ( oldx , oldy , ballSize + 1 ) ; g . setColor ( '#ffffff' ) ; g . fillCircle ( x , y , ballSize ) ; oldx = x ; oldy = y ; } }
animate a ball rolling around and settling at "target" radians
animate a ball rolling around and settling at " target " radians
/* when we reach max speed, we know how long it takes
         * to accelerate, and therefore how long to decelerate, so
         * we can work out what angle to start decelerating from */