Last active
December 18, 2015 04:28
-
-
Save gregtemp/5725292 to your computer and use it in GitHub Desktop.
ShapeMorphMasks Shapes morphing with animated masks
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 | |
// Examples | |
// | |
// Created by Greg Debicki. | |
// | |
#import "C4WorkSpace.h" | |
@implementation C4WorkSpace { | |
C4Shape *shape; | |
C4Shape *mask1, *mask2; | |
int count; | |
} | |
-(void)setup { | |
shape = [C4Shape rect:CGRectMake(0, 0, 150, 150)]; | |
shape.center = self.canvas.center; | |
shape.animationDuration = 0.7f; | |
[self setupMask]; | |
shape.mask = mask1; | |
[self.canvas addShape:shape]; | |
} | |
-(void) setupMask { | |
mask1 = [C4Shape rect:CGRectMake(0, 0, 600, 20)]; | |
mask1.center = CGPointMake(shape.width/2, shape.height/2); | |
mask1.animationDuration = 3.0f; | |
mask1.animationOptions = REPEAT; | |
mask1.rotation = TWO_PI; | |
mask2 = [C4Shape rect:CGRectMake(0, 0, 20, 600)]; | |
mask2.center = CGPointMake(mask1.width/2, mask1.height/2); | |
mask2.animationDuration = 3.2f; | |
mask2.animationOptions = REPEAT | AUTOREVERSE; | |
mask2.rotation = TWO_PI; | |
[mask1 addShape:mask2]; | |
} | |
-(void) touchesBegan { | |
if (count < 5){ | |
count++; | |
} | |
else { | |
count = 0; | |
} | |
switch (count) { | |
case 0: | |
[self rectango]; | |
break; | |
case 1: | |
[self ellipso]; | |
break; | |
case 2: | |
[self lino]; | |
break; | |
case 3: | |
[self triango]; | |
break; | |
case 4: | |
[self polyGone]; | |
break; | |
case 5: | |
[self wham]; | |
break; | |
default: | |
break; | |
} | |
} | |
-(void) rectango { | |
CGRect rect = CGRectMake(0, 0, 150, 150); | |
[shape rect:rect]; | |
shape.center = self.canvas.center; | |
} | |
-(void) ellipso { | |
CGRect rect = CGRectMake(0, 0, 150, 150); | |
[shape ellipse:rect]; | |
shape.center = self.canvas.center; | |
} | |
-(void) lino { | |
CGPoint p1[2] = {CGPointMake(0,0),CGPointMake(150,0)}; | |
[shape line:p1]; | |
shape.center = self.canvas.center; | |
} | |
-(void) triango { | |
CGPoint p2[3] = { | |
CGPointMake(0,0), | |
CGPointMake(150,150), | |
CGPointMake(0,150)}; | |
[shape triangle:p2]; | |
shape.center = self.canvas.center; | |
} | |
-(void) polyGone { | |
CGPoint p3[4] = { | |
CGPointMake(100,0), | |
CGPointMake(250,0), | |
CGPointMake(150, 150), | |
CGPointMake(0,150) | |
}; | |
[shape polygon:p3 pointCount:4]; | |
shape.center = self.canvas.center; | |
} | |
-(void) wham { | |
C4Font *f = [C4Font fontWithName:@"ArialRoundedMTBold" size:100.0f]; | |
[shape shapeFromString:@"WHAM!" withFont:f]; | |
shape.center = self.canvas.center; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment