Skip to content

Instantly share code, notes, and snippets.

@drart
Forked from C4Examples/C4Workspace.m
Last active December 25, 2015 11:29
Show Gist options
  • Save drart/6969047 to your computer and use it in GitHub Desktop.
Save drart/6969047 to your computer and use it in GitHub Desktop.
//
// C4WorkSpace.m
// Examples
//
// Created by Travis Kirton and Greg Debicki.
// Updated by Adam Tindale.
#import "C4WorkSpace.h"
@implementation C4WorkSpace
{
NSMutableArray *shapes;
int counter;
}
-(void)setup
{
shapes = [NSMutableArray array];
for(int i = 0; i < 40; i++)
{
C4Shape *s = [C4Shape rect:CGRectMake(0, 0, 600, 20)];
s.fillColor = [UIColor colorWithWhite:0.0f alpha:i/40.0f];
s.strokeColor = [UIColor clearColor];
s.anchorPoint = CGPointMake(0.5f,8.0f+i);
CGPoint p = self.canvas.center;
p.y += self.canvas.height/2;
s.center = p;
[shapes addObject:s];
}
[self.canvas addObjects:shapes];
[self runMethod:@"setupAnimations" afterDelay:0.1f];
}
-(void)setupAnimations
{
counter = 0;
for(C4Shape * s in shapes)
{
s.animationDuration = counter++*.01f + 2.0f;
[self animateObject:s];
}
}
-(void)animateObject:(C4Shape *)shape
{
shape.animationDuration = (shape.animationDuration > 0.2) ?
shape.animationDuration *= 0.99f : 2.0f + 0.1f*(counter++%40);
shape.rotation += TWO_PI;
[self runMethod:@"animateObject:" withObject:shape afterDelay:shape.animationDuration+ 0.2f];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment