ninis.js
function field(x, y) {
  var ux = 0;
  var uy = 0;
  for(var a = 0; a < attractors.length; a++) {
    var attractor = attractors[a];

    var d2 =  (x - attractor.x) * (x - attractor.x) + (y - attractor.y) * (y - attractor.y);
    var d = Math.sqrt(d2);

    var weight = attractor.weight * Math.exp( -1 * d2 / (attractor.radius * attractor.radius) );

    ux += weight * (x - attractor.x) / d;
    uy += weight * (y - attractor.y) / d;
  }

  var norm = Math.sqrt(ux * ux + uy * uy);
  ux = ux / norm;
  uy = uy / norm;

  // If we are near a special attractor, add its contribution to the field
  if(isNearSpecialAttractor(x,y)) {
    var closestTextPoint = findClosestPointOnSpecialAttractor(x,y);
    var textUx = (closestTextPoint.specialAttractor.direction || 1) * (x - closestTextPoint.originX);
    var textUy = (closestTextPoint.specialAttractor.direction || 1) * (y - closestTextPoint.originY);
    var norm = Math.sqrt(textUx*textUx + textUy*textUy);
    textUx = textUx / norm;
    textUy = textUy / norm;

    // Combine fields
    if(closestTextPoint.specialAttractor.type == 'cos') {
      if(closestTextPoint.distance < closestTextPoint.specialAttractor.impactDistance) {
        textWeight = 0.5 * (1 + Math.cos(Math.PI * closestTextPoint.distance / (closestTextPoint.specialAttractor.impactDistance)));
      } else {
        textWeight = 0;
      }

    } else {
      textWeight = Math.exp( -1 * closestTextPoint.distance * closestTextPoint.distance /  (closestTextPoint.specialAttractor.impactDistance * D * D) );
    }
    ux = (1-textWeight)*ux + textWeight * textUx;
    uy = (1-textWeight)*uy + textWeight * textUy;

  }

  return [ux, uy];
}
function field(x, y) {
  var ux = 0;
  var uy = 0;
  for(var a = 0; a < attractors.length; a++) {
    var attractor = attractors[a];

    var d2 =  (x - attractor.x) * (x - attractor.x) + (y - attractor.y) * (y - attractor.y);
    var d = Math.sqrt(d2);

    var weight = attractor.weight * Math.exp( -1 * d2 / (attractor.radius * attractor.radius) );

    ux += weight * (x - attractor.x) / d;
    uy += weight * (y - attractor.y) / d;
  }

  var norm = Math.sqrt(ux * ux + uy * uy);
  ux = ux / norm;
  uy = uy / norm;

  // If we are near a special attractor, add its contribution to the field
  if(isNearSpecialAttractor(x,y)) {
    var closestTextPoint = findClosestPointOnSpecialAttractor(x,y);
    var textUx = (closestTextPoint.specialAttractor.direction || 1) * (x - closestTextPoint.originX);
    var textUy = (closestTextPoint.specialAttractor.direction || 1) * (y - closestTextPoint.originY);
    var norm = Math.sqrt(textUx*textUx + textUy*textUy);
    textUx = textUx / norm;
    textUy = textUy / norm;

    // Combine fields
    if(closestTextPoint.specialAttractor.type == 'cos') {
      if(closestTextPoint.distance < closestTextPoint.specialAttractor.impactDistance) {
        textWeight = 0.5 * (1 + Math.cos(Math.PI * closestTextPoint.distance / (closestTextPoint.specialAttractor.impactDistance)));
      } else {
        textWeight = 0;
      }

    } else {
      textWeight = Math.exp( -1 * closestTextPoint.distance * closestTextPoint.distance /  (closestTextPoint.specialAttractor.impactDistance * D * D) );
    }
    ux = (1-textWeight)*ux + textWeight * textUx;
    uy = (1-textWeight)*uy + textWeight * textUy;

  }

  return [ux, uy];
}
function field ( x , y ) { var ux = 0 ; var uy = 0 ; for ( var a = 0 ; a < attractors . length ; a ++ ) { var attractor = attractors [ a ] ; var d2 = ( x - attractor . x ) * ( x - attractor . x ) + ( y - attractor . y ) * ( y - attractor . y ) ; var d = Math . sqrt ( d2 ) ; var weight = attractor . weight * Math . exp ( - 1 * d2 / ( attractor . radius * attractor . radius ) ) ; ux += weight * ( x - attractor . x ) / d ; uy += weight * ( y - attractor . y ) / d ; } var norm = Math . sqrt ( ux * ux + uy * uy ) ; ux = ux / norm ; uy = uy / norm ; // If we are near a special attractor, add its contribution to the field if ( isNearSpecialAttractor ( x , y ) ) { var closestTextPoint = findClosestPointOnSpecialAttractor ( x , y ) ; var textUx = ( closestTextPoint . specialAttractor . direction || 1 ) * ( x - closestTextPoint . originX ) ; var textUy = ( closestTextPoint . specialAttractor . direction || 1 ) * ( y - closestTextPoint . originY ) ; var norm = Math . sqrt ( textUx * textUx + textUy * textUy ) ; textUx = textUx / norm ; textUy = textUy / norm ; // Combine fields if ( closestTextPoint . specialAttractor . type == 'cos' ) { if ( closestTextPoint . distance < closestTextPoint . specialAttractor . impactDistance ) { textWeight = 0.5 * ( 1 + Math . cos ( Math . PI * closestTextPoint . distance / ( closestTextPoint . specialAttractor . impactDistance ) ) ) ; } else { textWeight = 0 ; } } else { textWeight = Math . exp ( - 1 * closestTextPoint . distance * closestTextPoint . distance / ( closestTextPoint . specialAttractor . impactDistance * D * D ) ) ; } ux = ( 1 - textWeight ) * ux + textWeight * textUx ; uy = ( 1 - textWeight ) * uy + textWeight * textUy ; } return [ ux , uy ] ; }
Vector of the field at a given point
Vector of the field at a given point