Created
February 15, 2013 14:31
-
-
Save C4Code/4960722 to your computer and use it in GitHub Desktop.
Rotating a small rect that traces the strokeEnd point of a circle's path.
This file contains hidden or 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
#import "C4WorkSpace.h" | |
@implementation C4WorkSpace { | |
C4Shape *s, *sq; | |
} | |
-(void)setup { | |
//create a shape and style it | |
s = [C4Shape ellipse:CGRectMake(0, 0, 200, 200)]; | |
s.lineWidth = 10.0f; | |
s.center = self.canvas.center; | |
[self.canvas addShape:s]; | |
//create a small square and style it | |
sq = [C4Shape rect:CGRectMake(0, 0, s.lineWidth, s.lineWidth)]; | |
sq.fillColor = C4RED; | |
sq.lineWidth = 0.0f; | |
//offset it's anchor point | |
//add 0.5 to offset the square by half its width | |
sq.anchorPoint = CGPointMake(-1 * (s.width / 2) / sq.width + 0.5,0.5); | |
//center the square, based on its anchor point, to the center of the shape | |
sq.center = CGPointMake(s.width / 2,s.height / 2); | |
[s addShape:sq]; | |
} | |
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { | |
//figure out how far along the screen the user has touched | |
CGPoint p = [[touches anyObject] locationInView:self.canvas]; | |
//normalize it to 1.0 | |
CGFloat normalized = p.x / self.canvas.width; | |
//change the end of the stroke | |
s.strokeEnd = normalized; | |
//rotate the square to match the end of the stroke | |
sq.rotation = TWO_PI * normalized; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment