Skip to content

Instantly share code, notes, and snippets.

@C4Code
Created May 17, 2013 08:04
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 C4Code/5597635 to your computer and use it in GitHub Desktop.
Save C4Code/5597635 to your computer and use it in GitHub Desktop.
Possible Day 1 Code
//
// C4WorkSpace.m
// Possible Day 1 for ITP
//
// Created by Travis Kirton on 12-07-23.
//
#import "C4WorkSpace.h"
@implementation C4WorkSpace {
NSMutableSet *allShapes;
C4Shape *baseShape;
NSInteger swirlDirection;
}
-(void)setup {
allShapes = [NSMutableSet new];
swirlDirection = 1;
C4Shape *swirl = [self createSwirlyThingWithBaseFrame:CGRectMake(0, 0, 96, 96)];
swirl.center = self.canvas.center;
[self.canvas addShape:swirl];
C4Shape *swirl2 = [self createSwirlyThingWithBaseFrame:CGRectMake(0,0,64,64)];
swirl2.center = CGPointMake(self.canvas.width / 4, self.canvas.width / 4);
[self.canvas addShape:swirl2];
C4Shape *swirl3 = [self createSwirlyThingWithBaseFrame:CGRectMake(0,0,64,64)];
swirl3.center = CGPointMake(self.canvas.width * 3 / 4, self.canvas.width / 4);
[self.canvas addShape:swirl3];
C4Shape *swirl4 = [self createSwirlyThingWithBaseFrame:CGRectMake(0,0,64,64)];
swirl4.center = CGPointMake(self.canvas.width / 4, self.canvas.height - self.canvas.width / 4);
[self.canvas addShape:swirl4];
C4Shape *swirl5 = [self createSwirlyThingWithBaseFrame:CGRectMake(0,0,64,64)];
swirl5.center = CGPointMake(self.canvas.width * 3 / 4, self.canvas.height - self.canvas.width / 4);
[self.canvas addShape:swirl5];
for(C4Shape *s in allShapes) [self animate:s];
}
-(C4Shape *)createSwirlyThingWithBaseFrame:(CGRect)baseFrame {
baseShape = [C4Shape rect:baseFrame];
CGPoint anchor = CGPointMake(-0.5,0.5);
[self createAddShapesForAnchorPoint:anchor];
anchor = CGPointMake(0.5,-0.5);
[self createAddShapesForAnchorPoint:anchor];
anchor = CGPointMake(1.5,0.5);
[self createAddShapesForAnchorPoint:anchor];
anchor = CGPointMake(0.5,1.5);
[self createAddShapesForAnchorPoint:anchor];
baseShape.center = self.canvas.center;
return baseShape;
}
-(void)createAddShapesForAnchorPoint:(CGPoint)anchor {
NSMutableArray *newShapes = [@[] mutableCopy];
[newShapes addObject:baseShape];
for(int i = 1; i < 10; i++) {
CGRect frame;
frame = ((C4Shape *)newShapes[i-1]).frame;
frame.size.width *= .75;
frame.size.height *= .75;
C4Shape *currentShape = [C4Shape ellipse:frame];
[[newShapes lastObject] addShape:currentShape];
[newShapes addObject:currentShape];
}
for(int i = [newShapes count] - 1; i > 0; i--) {
C4Shape *small = newShapes[i];
C4Shape *larger = newShapes[i-1];
small.anchorPoint = anchor;
small.center = larger.center;
}
[allShapes addObjectsFromArray:newShapes];
}
-(void)animate:(C4Shape *)shape {
shape.animationDuration = 8.0f;
shape.animationOptions = REPEAT;
shape.rotation = TWO_PI * swirlDirection;
swirlDirection *= -1;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment