title: Calculating animation strokeStart based on timestamps?
body: <p>I'm not 100% sure this is appropriate for stackoverflow as a programming question as it's mostly a math logic problem I'm having a hard time with, so if not my bad. </p>
  
  <p>I'm animating a circle with some of the code below : </p>
  
  <pre><code>// Set the animation duration appropriately
      animation.duration = duration
  
      // Animate from 0 (no circle) to 1 (full circle)
      animation.fromValue = strokeStart
      animation.toValue = 1
  
      // Do a linear animation (i.e. the speed of the animation stays the same)
      animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
  
      // Set the circleLayer's strokeEnd property to 1.0 now so that it's the
      // right value when the animation ends.
      progressCircle.strokeEnd = 1.0
  </code></pre>
  
  <p>so the key values being worked with are the duration, from value, and the end value which is always going to be 1.</p>
  
  <p>The total 360 degrees of the circle is always going to represent 240 seconds of time (4 minutes). </p>
  
  <p>I set up a function to plug in values for duration and start value when I'm creating the circles, but what I'm having a hard time with is how to calculate those out appropriately.</p>
  
  <p>So for example, when I'm drawing in one of these circles I'm grabbing a timestamp from a server. Let's say the timestamp grabbed was exactly 120 seconds ago. The circle should be drawn in 1/2 way complete already and the rest of the 180 degrees of the circle should be drawn in over the remaining 120 seconds of the total 4 minutes. Another example would just be if a timestamp was done 3 minutes and 50 seconds ago, the circle would basically be filled in immediately by setting the strokeStart to some high percentage and over the next 10 seconds it'd fill up. </p>
  
  <p>I know how to grab the timestamp, I know how to grab how many seconds the timestamp is from the current time, but I don't know how to calculate out the strokeStart.</p>
  
  <p>Any ideas on this one?</p>