Skip to content

Instantly share code, notes, and snippets.

@gregtemp
Created April 9, 2013 18:48
Show Gist options
  • Save gregtemp/5348299 to your computer and use it in GitHub Desktop.
Save gregtemp/5348299 to your computer and use it in GitHub Desktop.
C4 Simple Random Movement
//
// C4WorkSpace.m
// Examples
//
// Created by Greg Debicki.
//
@implementation C4WorkSpace {
C4Shape *circle;
}
-(void)setup {
circle = [C4Shape ellipse:CGRectMake(0, 0, 50, 50)];
circle.center = self.canvas.center;
[self.canvas addShape:circle];
[self runMethod:@"newPlace" afterDelay:0.0f];
}
-(void)newPlace {
CGFloat time = ([C4Math randomInt:150]/100) + 0.5f;
circle.animationDuration = time;
circle.center = CGPointMake([C4Math randomInt:self.canvas.width/2] + self.canvas.width/4,
[C4Math randomInt:self.canvas.height/2] + self.canvas.height/4);
[self runMethod:@"newPlace" afterDelay:time];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment