Created
May 8, 2013 03:08
-
-
Save mtabini/5537915 to your computer and use it in GitHub Desktop.
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
-(void)drawRect:(CGRect)rect { | |
CGFloat side = MIN(self.bounds.size.width, self.bounds.size.height); | |
NSInteger steps = 512; | |
float internalRadius = side * 0.0; | |
float externalRadius = side * 0.5; | |
float halfinteriorPerim = M_PI * internalRadius; | |
float halfexteriorPerim = M_PI * externalRadius; | |
float smallBase= halfinteriorPerim / steps; | |
float largeBase= halfexteriorPerim / steps; | |
UIBezierPath *cell = [UIBezierPath bezierPath]; | |
[cell moveToPoint:CGPointMake(- smallBase/2, internalRadius)]; | |
[cell addLineToPoint:CGPointMake(+ smallBase/2, internalRadius)]; | |
[cell addLineToPoint:CGPointMake( largeBase /2 , externalRadius)]; | |
[cell addLineToPoint:CGPointMake(-largeBase /2, externalRadius)]; | |
[cell closePath]; | |
float incr = 2 * M_PI / steps; | |
CGContextRef ctx = UIGraphicsGetCurrentContext(); | |
CGContextTranslateCTM(ctx, +self.bounds.size.width / 2, +self.bounds.size.height / 2); | |
CGContextScaleCTM(ctx, 0.9, 0.9); | |
CGContextRotateCTM(ctx, M_PI / 2); | |
CGContextRotateCTM(ctx, -incr / 2); | |
for (NSInteger index = 0; index < steps; index++) { | |
[[UIColor colorWithHue:(float) index / steps | |
saturation:1.0 | |
brightness:1.0 | |
alpha:1.0] set]; | |
[cell fill]; | |
[cell stroke]; | |
CGContextRotateCTM(ctx, -incr); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment