Skip to content

Instantly share code, notes, and snippets.

@rcaetano
Created April 2, 2012 14:12
Show Gist options
  • Save rcaetano/2283710 to your computer and use it in GitHub Desktop.
Save rcaetano/2283710 to your computer and use it in GitHub Desktop.
Vivace Logo
//
// VivaceLogoView.h
// zeon
//
// Created by Richard Caetano on 4/2/12.
// Copyright (c) 2012 Modal Software Corporation. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface VivaceLogoView : UIView
@property (atomic, retain) UIColor* logoColor;
- (UIImage*)getImage;
- (void)writeToFile:(NSString*)filename;
@end
//
// VivaceLogoView.m
// zeon
//
// Created by Richard Caetano on 4/2/12.
// Copyright (c) 2012 Modal Software Corporation. All rights reserved.
//
#import "VivaceLogoView.h"
@implementation VivaceLogoView
@synthesize logoColor;
- (void)dealloc
{
self.logoColor = nil;
[super dealloc];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.logoColor = [UIColor whiteColor];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
// draws the vivace logo - a cassette tape gear
// helpers
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat width = rect.size.width;
CGFloat height = rect.size.height;
CGFloat lineWidth = rect.size.width / 10;
CGFloat padding = lineWidth / 2;
// setup
CGContextSetStrokeColorWithColor(context, self.logoColor.CGColor);
CGContextSetLineWidth(context, lineWidth);
[self.logoColor setStroke];
// draw circle
UIBezierPath* circle = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(padding, padding, width - lineWidth, height - lineWidth)];
circle.lineWidth = lineWidth;
[circle stroke];
// draw teeth (x = r cos(a), y = r sin(a))
CGFloat radius = (width / 2) - padding;
CGFloat inner_len = radius * 0.50;
CGFloat offset = width / 2;
for (CGFloat angle=0;angle<M_PI*2;angle+=(M_PI*2)/6)
{
CGContextMoveToPoint(context, cosf(angle) * inner_len + offset, sin(angle) * inner_len + offset);
CGContextAddLineToPoint(context, cosf(angle) * radius + offset, sin(angle) * radius + offset);
}
CGContextStrokePath(context);
}
- (UIImage*)getImage
{
UIGraphicsBeginImageContext(self.bounds.size);
[self drawRect:self.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
- (void)writeToFile:(NSString*)filename;
{
NSData *imageData = UIImagePNGRepresentation([self getImage]);
[imageData writeToFile:filename atomically:YES];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment