-
-
Save aalemayhu/4d4fea357521b257ccc1 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
/** | |
* Draws a smiley inside the given rectangle. The mood value (0...1) is used | |
* to make the smiley happy or sad. | |
* | |
* @param rect Rectangle to draw the smiley into | |
* @param mood Happy (= 1) or sad (= 0) or anything in between | |
*/ | |
-(void)drawSmileyInRect:(CGRect)rect withMood:(float)mood { | |
CGContextRef ctx = UIGraphicsGetCurrentContext(); | |
CGContextSaveGState(ctx); | |
CGContextTranslateCTM(ctx, rect.origin.x, rect.origin.y); | |
CGContextScaleCTM(ctx, rect.size.width/8 ,rect.size.height/8); // Hint: Original Coordinate System has a width an height of 8 pixels | |
// Eyes: | |
CGContextFillEllipseInRect(ctx, CGRectMake(2, 2, 1, 1)); | |
CGContextFillEllipseInRect(ctx, CGRectMake(5, 2, 1, 1)); | |
// Lips: | |
UIBezierPath *path = [UIBezierPath bezierPath]; | |
[path moveToPoint:CGPointMake(1.5, 5.5)]; | |
[path addQuadCurveToPoint:CGPointMake(6.5, 5.5) controlPoint:CGPointMake(4, 4+mood*4)]; | |
path.lineWidth = 0.5; | |
path.lineCapStyle = kCGLineCapRound; | |
[[UIColor blackColor] setStroke]; | |
[path stroke]; | |
CGContextRestoreGState(ctx); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment