Last active
July 25, 2016 23:10
-
-
Save warpling/8a466cc676228e516bbcf44518fb3548 to your computer and use it in GitHub Desktop.
Circle Bloom!?
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
// | |
// CircleBloom.h | |
// Blackbox | |
// | |
// Created by Ryan McLeod on 7/25/16. | |
// Copyright © 2016 Ryan McLeod. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface CircleBloom : UIView | |
@property (strong, nonatomic, readonly) NSArray *blooms; | |
- (instancetype) initWithFrame:(CGRect)frame bloomCount:(NSUInteger)count bloomRadius:(CGFloat)radius bloomSpread:(CGFloat)spread; | |
@end |
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
// | |
// CircleBloom.m | |
// Blackbox | |
// | |
// Created by Ryan McLeod on 7/25/16. | |
// Copyright © 2016 Ryan McLeod. All rights reserved. | |
// | |
#import "CircleBloom.h" | |
@interface CircleBloom () | |
@end | |
@implementation CircleBloom { | |
NSUInteger bloomCount; | |
CGFloat bloomRadius; | |
CGFloat bloomSpread; | |
} | |
- (instancetype) initWithFrame:(CGRect)frame bloomCount:(NSUInteger)count bloomRadius:(CGFloat)radius bloomSpread:(CGFloat)spread { | |
self = [super initWithFrame:frame]; | |
if (self) { | |
bloomCount = count; | |
bloomRadius = radius; | |
bloomSpread = spread; | |
} | |
return self; | |
} | |
- (void) drawRect:(CGRect)rect { | |
[super drawRect:rect]; | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGContextSetBlendMode(context, kCGBlendModeScreen); | |
for (int ctr = 0; ctr < bloomCount; ctr++) { | |
// Save current context | |
CGContextSaveGState(context); | |
// Set our anchor point to the center of the rect | |
CGContextTranslateCTM(context, CGRectGetMidX(rect), CGRectGetMidY(rect)); | |
// Rotate from anchor point | |
CGFloat rotation = ctr * (2*M_PI / (1.f*bloomCount)); | |
CGContextRotateCTM(context, rotation); | |
// Translate away from center | |
CGContextTranslateCTM(context, -bloomRadius, -(2*bloomRadius + bloomSpread)); | |
CGRect circleFrame = CGRectMake(0, 0, 2*bloomRadius, 2*bloomRadius); | |
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:circleFrame]; | |
CGContextAddPath(context, [path CGPath]); | |
CGContextSetFillColorWithColor(context, [[UIColor cyanColor] CGColor]); | |
CGContextSetStrokeColorWithColor(context, nil); | |
CGContextDrawPath(context, kCGPathFill); | |
// Restore context for next circle | |
CGContextRestoreGState(context); | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment