     myservo.write(angle);       // tell servo to go to position in variable 'angle'
     delay(delayTime);           // waits for the servo to reach the position
 
-    float rad = angle * degrees_to_radians;
-    int increAngle = ceil(increment * sin(rad));
-
     // note decrement instead of increment
-    angle -= increAngle;
+    angle -= calcDeltaAngle(angle, startAngle, endAngle, increment);
   }
 }
+
+int calcDeltaAngle(int angle, int startAngle, int endAngle, int maxAngleIncrement)
+{
+  // normal half circle is 180 degrees
+  const double wholeRange = 180.0;
+
+  // amount to rotate head depends on where it is: more in the
+  // middle, & less at the ends. AKA sine wave.
+  int currRange = endAngle - startAngle;
+  double rangeRatio = wholeRange / currRange;
+  int offsetAngle = angle - startAngle;
+  double normalizedOffset = rangeRatio * offsetAngle;
+
+  double rad = normalizedOffset * degrees_to_radians;
+  double sineValue = sin(rad);
+  int increAngle = ceil(0.1 + maxAngleIncrement * sineValue);
+
+  /*
+  Serial.print(angle);
+  Serial.print("\t");
+  Serial.print(increAngle);
+  Serial.println("");
+  */
+
+  return increAngle;
+}
+
+

{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo.write(90);
}

void loop()
{
  const int startAngle = 10;
  const int endAngle = 170;

  // milliseconds to wait between servo movement
  const int delayTime = 25;

  // maximum servo movement per iteration
  const int increment = 3;

  // milliseconds to wait at one end point before reversing rotation
  const int turnaroundTime = 25;

  int angle = 0;


    myservo.write(angle);       // tell servo to go to position in variable 'angle'
    delay(delayTime);           // waits for the servo to reach the position

    angle += calcDeltaAngle(angle, startAngle, endAngle, increment);
  }

  delay(turnaroundTime);
