Skip to content

Instantly share code, notes, and snippets.

@C4Code
Created February 6, 2013 08:32
Show Gist options
  • Save C4Code/4721184 to your computer and use it in GitHub Desktop.
Save C4Code/4721184 to your computer and use it in GitHub Desktop.
Arctangent example
//
// C4WorkSpace.m
//
// Created by Travis Kirton and Greg Debicki.
//
#import "C4WorkSpace.h"
@implementation C4WorkSpace {
C4Shape *shape, *shape2;
}
-(void)setup {
shape = [C4Shape rect:CGRectMake(0, 0, 200, 10)];
shape.anchorPoint = CGPointMake(0.0,0.5);
shape.center = self.canvas.center;
shape.userInteractionEnabled = NO;
[self.canvas addShape:shape];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint p = [[touches anyObject] locationInView:self.canvas];
CGFloat arctangent = [C4Math atan2Y:p.y-self.canvas.center.y X:p.x-self.canvas.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