Skip to content

Instantly share code, notes, and snippets.

@C4Examples
Created July 26, 2012 17:54
Show Gist options
  • Select an option

  • Save C4Examples/3183505 to your computer and use it in GitHub Desktop.

Select an option

Save C4Examples/3183505 to your computer and use it in GitHub Desktop.
Line Join
//
// C4WorkSpace.m
// Examples
//
// Created by Travis Kirton
//
#import "C4WorkSpace.h"
@interface C4WorkSpace ()
-(void)createAndStylePolygons;
-(void)createLabels;
@end
@implementation C4WorkSpace {
C4Shape *poly1, *poly2, *poly3;
}
-(void)setup {
[self createAndStylePolygons];
[self createLabels];
//set the lineJoin property for each shape
poly1.lineJoin = JOINMITER; //This is the default value
poly2.lineJoin = JOINROUND;
poly3.lineJoin = JOINBEVEL;
}
-(void)createAndStylePolygons {
//the base width for the polygons
CGFloat base = 300;
CGFloat height = [C4Math sqrt:3]/4 * base; // half the height of an equilateral
CGPoint polyPoints[3] = {CGPointZero,CGPointMake(150, -height),CGPointMake(300, 0)};
//create poly1 and style it
poly1 = [C4Shape polygon:polyPoints pointCount:3];
poly1.fillColor = [UIColor clearColor];
poly1.lineWidth = 30.0f;
poly1.center = CGPointMake(self.canvas.center.x, self.canvas.height /4);
//create poly2 and style it
poly2 = [C4Shape polygon:polyPoints pointCount:3];
poly2.fillColor = [UIColor clearColor];
poly2.strokeColor = C4BLUE;
poly2.lineWidth = 30.0f;
poly2.center = self.canvas.center;
poly2.lineJoin = JOINROUND;
poly2.center = self.canvas.center;
//create poly3 and style it
poly3 = [C4Shape polygon:polyPoints pointCount:3];
poly3.fillColor = [UIColor clearColor];
poly3.strokeColor = C4GREY;
poly3.lineWidth = 30.0f;
poly3.center = self.canvas.center;
poly3.center = CGPointMake(self.canvas.center.x, self.canvas.height *3/4);
//add all the polygons to the canvas
[self.canvas addShape:poly1];
[self.canvas addShape:poly2];
[self.canvas addShape:poly3];
}
-(void)createLabels {
C4Font *f = [C4Font fontWithName:@"ArialRoundedMTBold" size:30.0f];
C4Label *l;
CGPoint center;
//create the JOINMITER label, center it to the base of poly1
l = [C4Label labelWithText:@"JOINMITER" font:f];
center = poly1.center;
center.y += poly1.height/2;
l.center = center;
[self.canvas addLabel:l];
//create the JOINROUND label, center it to the base of poly2
l = [C4Label labelWithText:@"JOINROUND" font:f];
center = poly2.center;
center.y += poly2.height/2;
l.center = center;
[self.canvas addLabel:l];
//create the JOINBEVEL label, center it to the base of poly3
l = [C4Label labelWithText:@"JOINBEVEL" font:f];
center = poly3.center;
center.y += poly3.height/2;
l.center = center;
[self.canvas addLabel:l];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment