Last active
December 16, 2015 04:09
-
-
Save C4Tutorials/5375529 to your computer and use it in GitHub Desktop.
Composite Objects Tutorial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// C4WorkSpace.m | |
// Composite Objects Tutorial | |
// | |
// Created by Travis Kirton. | |
// | |
#import "C4WorkSpace.h" | |
@implementation C4WorkSpace { | |
C4Shape *mainShape; | |
} | |
-(void)setup { | |
mainShape = [C4Shape rect:CGRectMake(0, 0, 368, 368)]; | |
mainShape.lineWidth = 0.0f; | |
mainShape.fillColor = [UIColor clearColor]; | |
mainShape.center = self.canvas.center; | |
[self.canvas addShape:mainShape]; | |
CGPoint center = CGPointMake(mainShape.width / 2, mainShape.height / 2); | |
for(int i = 0; i < 12; i ++) { | |
C4Shape *shape = [C4Shape ellipse:mainShape.frame]; | |
shape.anchorPoint = CGPointMake(0.5,1.0f); | |
shape.center = center; | |
shape.rotation = TWO_PI / 12.0f * i; | |
shape.fillColor = [UIColor clearColor]; | |
[mainShape addShape:shape]; | |
[self runMethod:@"animateShape:" withObject:shape afterDelay:(i+1)*0.5f]; | |
} | |
C4Shape *mask = [C4Shape ellipse:mainShape.frame]; | |
mask.center = center; | |
mainShape.mask = mask; | |
mainShape.animationDuration = 10.0f; | |
mainShape.animationOptions = REPEAT | LINEAR; | |
mainShape.rotation = TWO_PI; | |
} | |
-(void)animateShape:(C4Shape *)shape { | |
shape.animationOptions = REPEAT | AUTOREVERSE; | |
shape.animationDuration = 2.0f; | |
shape.strokeColor = C4RED; | |
shape.rotation = PI; | |
[self runMethod:@"animateStrokeEnd:" withObject:shape afterDelay:0.25f]; | |
} | |
-(void)animateStrokeEnd:(C4Shape *)shape { | |
shape.animationDuration = 15.0f; | |
shape.strokeEnd = 0.0f; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment