Created
April 23, 2013 09:10
-
-
Save C4Examples/5442029 to your computer and use it in GitHub Desktop.
C4Math arcTangent
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. | |
// | |
#import "C4WorkSpace.h" | |
@implementation C4WorkSpace { | |
CGPoint p; | |
NSMutableArray *shapes; | |
NSInteger numberOfColumns; | |
NSInteger numberOfRows; | |
} | |
-(void)setup { | |
shapes = [@[] mutableCopy]; | |
numberOfColumns = 5; | |
numberOfRows = 5; | |
for (int i = 0; i < numberOfColumns; i ++){ | |
for (int j = 0; j < numberOfRows; j ++ ) { | |
C4Shape *shape = [C4Shape rect:CGRectMake(0, 0, 50, 2)]; | |
shape.anchorPoint = CGPointMake(0.0,0.5); | |
CGFloat newX = ((self.canvas.width/numberOfColumns) * i) + ((self.canvas.width/numberOfColumns)/2); | |
CGFloat newY = ((self.canvas.height/numberOfRows) * j) + ((self.canvas.height/numberOfRows)/2); | |
shape.center = CGPointMake(newX, newY); | |
shape.userInteractionEnabled = NO; | |
shape.strokeColor = [UIColor clearColor]; | |
[shapes addObject:shape]; | |
} | |
} | |
[self.canvas addObjects:shapes]; | |
} | |
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { | |
p = [[touches anyObject] locationInView:self.canvas]; | |
for (int i = 0; i < (numberOfRows*numberOfColumns); i++) { | |
C4Shape *shape = shapes[i]; | |
CGFloat arctangent = [C4Math atan2Y:p.y-shape.center.y X:p.x-shape.center.x]; | |
shape.rotation = arctangent; | |
} | |
event = event; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment