Skip to content

Instantly share code, notes, and snippets.

@C4Code
Created December 10, 2012 18:19
Show Gist options
  • Save C4Code/4252284 to your computer and use it in GitHub Desktop.
Save C4Code/4252284 to your computer and use it in GitHub Desktop.
hit testing a shape, adding shapes within another shape
#import "C4WorkSpace.h"
@implementation C4WorkSpace {
C4Shape *t;
}
-(void)setup {
t = [C4Shape arcWithCenter:CGPointMake(180, 180) radius:180 startAngle:0
endAngle:PI clockwise:NO];
[self.canvas addShape:t];
t.userInteractionEnabled = NO;
t.origin = CGPointMake(180,70);
t.frame = CGRectMake(180, 70, t.width, t.height);
[self.canvas addShape:t];
[self runMethod:@"createShapes" afterDelay:0.1];
}
-(void)createShapes {
for(int i = 0; i < 50;) {
CGPoint p = CGPointMake([C4Math randomInt:t.width] + t.origin.x,
[C4Math randomInt:t.height] + t.origin.y);
if([t pointInside:[t convertPoint:p fromView:self.canvas] withEvent:nil]) {
C4Shape *s = [C4Shape ellipse:CGRectMake(0, 0, 20, 20)];
s.center = p;
[self.canvas addShape:s];
i++;
}
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment