Skip to content

Instantly share code, notes, and snippets.

@gregtemp
Last active December 18, 2015 04:28
Show Gist options
  • Save gregtemp/5725287 to your computer and use it in GitHub Desktop.
Save gregtemp/5725287 to your computer and use it in GitHub Desktop.
ShapeMorph Shapes morphing into other shapes
//
// C4WorkSpace.m
// Examples
//
// Created by Greg Debicki.
//
#import "C4WorkSpace.h"
@implementation C4WorkSpace {
C4Shape *shape;
int count;
}
-(void)setup {
shape = [C4Shape rect:CGRectMake(0, 0, 150, 150)];
shape.center = self.canvas.center;
shape.animationDuration = 0.3f;
[self.canvas addShape:shape];
}
-(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