Created
April 23, 2013 09:04
-
-
Save C4Examples/5441978 to your computer and use it in GitHub Desktop.
Advanced Examples randomMovementSubview
This file contains 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. | |
// | |
@implementation C4WorkSpace { | |
C4Shape *bigCircle; | |
} | |
-(void)setup { | |
[self makeBigCircle]; | |
} | |
-(void) makeBigCircle { | |
bigCircle = [C4Shape ellipse:CGRectMake(0, 0, 600, 600)]; | |
bigCircle.center = self.canvas.center; | |
bigCircle.strokeColor = [UIColor clearColor]; | |
[self.canvas addShape:bigCircle]; | |
for (int i = 0; i < 100; i ++) { | |
[self makeCircle]; | |
} | |
bigCircle.animationDuration = 7.5f; | |
bigCircle.animationOptions = REPEAT; | |
bigCircle.rotation += TWO_PI; | |
} | |
-(void)makeCircle { | |
C4Shape *circle = [C4Shape ellipse:CGRectMake(0, 0, 5, 5)]; | |
circle.center = CGPointMake(bigCircle.width/2, bigCircle.height/2); | |
[bigCircle addShape:circle]; | |
[self runMethod:@"newPlace:" withObject:circle afterDelay:0.0f]; | |
} | |
-(void)newPlace: (C4Shape *)sender { | |
CGFloat time = ([C4Math randomInt:250]/100.0f) + 1.0f; | |
sender.animationDuration = time; | |
NSInteger r = [C4Math randomIntBetweenA:100 andB:300]; | |
CGFloat theta = DegreesToRadians([C4Math randomInt:360]); | |
sender.center = CGPointMake(r*[C4Math cos:theta] + (bigCircle.width/2), | |
r*[C4Math sin:theta] + (bigCircle.height/2)); | |
[self runMethod:@"newPlace:" withObject:sender afterDelay:time]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment