Skip to content

Instantly share code, notes, and snippets.

@C4Examples
Created April 23, 2013 09:05
Show Gist options
  • Save C4Examples/5441984 to your computer and use it in GitHub Desktop.
Save C4Examples/5441984 to your computer and use it in GitHub Desktop.
Advanced Examples randomMovementMask
//
// C4WorkSpace.m
// Examples
//
// Created by Greg Debicki.
//
@implementation C4WorkSpace {
C4Image *img;
C4Shape *container;
}
-(void)setup {
[self setupShapes];
img.backgroundColor = C4BLUE;
img.mask = container;
[self.canvas addImage:img];
}
-(void)setupShapes {
img = [C4Image imageNamed:@"C4Table"];
img.height = self.canvas.height;
container = [C4Shape rect:CGRectMake(0, 0, 300, self.canvas.height)];
container.fillColor = [UIColor clearColor];
[self addVisibleContainer];
img.center = self.canvas.center;
container.center = CGPointMake(img.width/2 ,img.height/2);
for (int i = 0; i < 30; i ++) {
[self makeStrip];
}
}
-(void)makeStrip {
CGFloat h = [C4Math randomIntBetweenA:1 andB:300];
C4Shape *strip = [C4Shape rect:CGRectMake(0, 0, 300, h)];
strip.center = CGPointMake(container.width/2 ,container.height/2);
strip.alpha = 0.3f;
[container addShape:strip];
[self runMethod:@"newPlace:" withObject:strip afterDelay:0.0f];
}
-(void)newPlace: (C4Shape *)sender {
CGFloat time = ([C4Math randomInt:350]/100.0f) + 1.5f;
sender.animationDuration = time;
sender.center = CGPointMake(sender.center.x, [C4Math randomInt:container.height]);
[self runMethod:@"newPlace:" withObject:sender afterDelay:time];
}
-(void)addVisibleContainer {
C4Shape *visibleContainer = [C4Shape rect:container.frame];
visibleContainer.center = self.canvas.center;
visibleContainer.fillColor = [UIColor clearColor];
visibleContainer.lineWidth = 2.0f;
visibleContainer.strokeColor = C4GREY;
[self.canvas addShape:visibleContainer];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment