Created
April 3, 2013 19:32
-
-
Save C4Tutorials/5304505 to your computer and use it in GitHub Desktop.
Combining shapes to make a face.
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
// | |
// C4WorkSpace.m | |
// | |
// Created by Travis Kirton. | |
// | |
#import "C4WorkSpace.h" | |
@implementation C4WorkSpace { | |
C4Shape *face; | |
} | |
-(void)setup { | |
face = [C4Shape ellipse:CGRectMake(0, 0, 200, 320)]; | |
CGPoint hairPts[7] = { | |
CGPointMake(0, 80), | |
CGPointMake(20, 20), | |
CGPointMake(40, 60), | |
CGPointMake(80, 30), | |
CGPointMake(70, 60), | |
CGPointMake(100, 50), | |
CGPointMake(90, 80) | |
}; | |
C4Shape *hair = [C4Shape polygon:hairPts pointCount:7]; | |
hair.center = CGPointMake(face.width/2+4,-11); | |
C4Shape *leftEye = [C4Shape ellipse:CGRectMake(40, 100, 50, 30)]; | |
leftEye.fillColor = [UIColor colorWithWhite:200 alpha:1.0f]; | |
C4Shape *leftIris = [C4Shape ellipse:CGRectMake(30, 10, 10, 10)]; | |
leftIris.fillColor = C4GREY; | |
leftIris.lineWidth = 0.0f; | |
[leftEye addShape:leftIris]; | |
C4Shape *rightEye = [C4Shape ellipse:CGRectMake(160, 100, 50, 30)];; | |
rightEye.fillColor = leftEye.fillColor; | |
[rightEye addShape:[leftIris copy]]; | |
C4Shape *nose = [C4Shape arcWithCenter:CGPointMake(rightEye.center.x, rightEye.center.y) radius:60.0f startAngle:HALF_PI+0.5f endAngle:PI clockwise:YES]; | |
nose.fillColor = [UIColor clearColor]; | |
CGPoint noseLinePts[2] = {CGPointMake(0,nose.height),CGPointMake(nose.width+0.5f, nose.height)}; | |
C4Shape *noseLine = [C4Shape line:noseLinePts]; | |
[nose addShape:noseLine]; | |
C4Shape *mouth = [C4Shape arcWithCenter:CGPointMake(face.width / 2 + 5.0f, face.height / 2 + 10.0f) radius:60.0f startAngle:QUARTER_PI+QUARTER_PI/2 endAngle:HALF_PI+QUARTER_PI * 3/2 clockwise:YES]; | |
mouth.lineWidth = 10.0f; | |
mouth.fillColor = [UIColor clearColor]; | |
mouth.lineCap = CAPROUND; | |
C4Shape *mouthLine = [mouth copy]; | |
mouthLine.lineWidth = 2.0f; | |
mouthLine.strokeColor = [leftEye.fillColor colorWithAlphaComponent:0.66f]; | |
[face addShape:hair]; | |
[face addShape:leftEye]; | |
[face addShape:rightEye]; | |
[face addShape:nose]; | |
[face addShape:mouth]; | |
[face addShape:mouthLine]; | |
[self.canvas addShape:face]; | |
face.center = self.canvas.center; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment