Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@PrimaryFeather
Created March 21, 2014 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PrimaryFeather/9683678 to your computer and use it in GitHub Desktop.
Save PrimaryFeather/9683678 to your computer and use it in GitHub Desktop.
Water distortion filter, implemented with Sparrow's "DisplacementMapFilter".
- (void)addDistortionTo:(SPDisplayObject *)target
{
float scale = Sparrow.contentScaleFactor;
NSURL *url = scale == 1.0f ?
[NSURL URLWithString:@"http://i.imgur.com/n95LSGb.jpg"] :
[NSURL URLWithString:@"http://i.imgur.com/QRXLvws.jpg"];
[SPTexture loadFromURL:url generateMipmaps:NO scale:scale
onComplete:^(SPTexture *texture, NSError *outError)
{
float __block offset = 0;
SPDisplacementMapFilter *filter = [[SPDisplacementMapFilter alloc] initWithMapTexture:texture];
filter.componentX = SPColorChannelRed;
filter.componentY = SPColorChannelRed;
filter.scaleX = 40;
filter.scaleY = 5;
target.filter = filter;
[target addEventListenerForType:SPEventTypeEnterFrame block:^(SPEnterFrameEvent *event)
{
if (offset > texture.height / 2.0f) offset -= texture.height / 2.0f;
else offset += event.passedTime * 20.0f;
filter.mapPoint.y = offset - texture.height / 2;
}];
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment