Skip to content

Commit

Permalink
Added support for back easing functions. Easier than anticipated. Nee…
Browse files Browse the repository at this point in the history
…ds optimization, but that's what contributors are for
  • Loading branch information
warrenm committed Jun 3, 2011
1 parent ebebd2d commit a651ada
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
2 changes: 2 additions & 0 deletions AHEasing/PlaygroundViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ - (void)configureEasingFunction
case CurveTypeElastic:
currentFunction = (currentEasing == EaseIn) ? ElasticEaseIn : (currentEasing == EaseOut) ? ElasticEaseOut : ElasticEaseInOut;
break;
case CurveTypeBack:
currentFunction = (currentEasing == EaseIn) ? BackEaseIn : (currentEasing == EaseOut) ? BackEaseOut : BackEaseInOut;
}

[graphView setEasingFunction:currentFunction];
Expand Down
18 changes: 15 additions & 3 deletions AHEasing/easing.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,31 @@ AHFloat ElasticEaseInOut(AHFloat p)
}
}

// Modeled after the overshooting cubic y = x^3 - x*sin(x*pi)
AHFloat BackEaseIn(AHFloat p)
{
return p;
return p * p * p - p * sin(p * M_PI);
}

// Modeled after overshooting cubic y = 1 - ((1-x)^3 - (1-x)*sin((1-x)*pi))
AHFloat BackEaseOut(AHFloat p)
{
return p;
AHFloat f = (1 - p);
return 1 - (f * f * f - f * sin(f * M_PI));
}

AHFloat BackEaseInOut(AHFloat p)
{
return p;
if(p < 0.5)
{
AHFloat f = 2 * p;
return 0.5 * (f * f * f - f * sin(f * M_PI));
}
else
{
AHFloat f = (1 - (2 * p - 1));
return 0.5 * (1 - (f * f * f - f * sin(f * M_PI))) + 0.5;
}
}

AHFloat BounceEaseIn(AHFloat p)
Expand Down
8 changes: 4 additions & 4 deletions AHEasing/easing.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ AHFloat ElasticEaseIn(AHFloat p);
AHFloat ElasticEaseOut(AHFloat p);
AHFloat ElasticEaseInOut(AHFloat p);

// Overshooting cubic easing
//AHFloat BackEaseIn(AHFloat p);
//AHFloat BackEaseOut(AHFloat p);
//AHFloat BackEaseInOut(AHFloat p);
// Overshooting cubic easing;
AHFloat BackEaseIn(AHFloat p);
AHFloat BackEaseOut(AHFloat p);
AHFloat BackEaseInOut(AHFloat p);

// Exponentially-decaying bounce easing
//AHFloat BounceEaseIn(AHFloat p);
Expand Down
7 changes: 6 additions & 1 deletion AHEasing/en.lproj/PlaygroundView.xib
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBSegmentControlStyle">2</int>
<int key="IBNumberOfSegments">9</int>
<int key="IBNumberOfSegments">10</int>
<int key="IBSelectedSegmentIndex">0</int>
<object class="NSArray" key="IBSegmentTitles">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand All @@ -101,6 +101,7 @@
<string>Circ</string>
<string>Exp</string>
<string>Elastic</string>
<string>Back</string>
</object>
<object class="NSMutableArray" key="IBSegmentWidths">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand All @@ -113,6 +114,7 @@
<real value="0.0"/>
<real value="0.0"/>
<real value="0.0"/>
<real value="0.0"/>
</object>
<object class="NSMutableArray" key="IBSegmentEnabledStates">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand All @@ -125,6 +127,7 @@
<boolean value="YES"/>
<boolean value="YES"/>
<boolean value="YES"/>
<boolean value="YES"/>
</object>
<object class="NSMutableArray" key="IBSegmentContentOffsets">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand All @@ -137,6 +140,7 @@
<string>{0, 0}</string>
<string>{0, 0}</string>
<string>{0, 0}</string>
<string>{0, 0}</string>
</object>
<object class="NSMutableArray" key="IBSegmentImages">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand All @@ -149,6 +153,7 @@
<reference ref="4"/>
<reference ref="4"/>
<reference ref="4"/>
<reference ref="4"/>
</object>
</object>
<object class="IBUISegmentedControl" id="942628741">
Expand Down

0 comments on commit a651ada

Please sign in to comment.