Created
July 24, 2012 15:44
-
-
Save C4Examples/3170773 to your computer and use it in GitHub Desktop.
Rectangles & Ellipses
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 | |
// Examples | |
// | |
// Created by Travis Kirton | |
// | |
#import "C4WorkSpace.h" | |
@implementation C4WorkSpace | |
-(void)setup { | |
C4Shape *rectangle, *square, *circle, *ellipse; | |
//Create a rectangle | |
rectangle = [C4Shape rect:CGRectMake(0, 0, 200, 100)]; | |
//Create a square (same w & h) | |
square = [C4Shape rect:CGRectMake(0, 0, 100, 100)]; | |
//Create an ellipse | |
ellipse = [C4Shape ellipse:CGRectMake(0, 0, 200, 100)]; // same dimensions as rectangle | |
//Create a circle (same w & h) | |
circle = [C4Shape ellipse:CGRectMake(0, 0, 100, 100)]; // same dimensions as square | |
//Figure out the vertical whitespace (i.e. the space between shapes and the edges of the canvas) | |
CGFloat whiteSpace = self.canvas.height - 4* rectangle.height; | |
whiteSpace = whiteSpace/5; // because there are 5 gaps | |
//center all the shapes to the canvas | |
CGPoint center; | |
center.x = self.canvas.center.x; | |
//set the y position for the rectangle | |
center.y = whiteSpace + rectangle.height/2; | |
rectangle.center = center; | |
//set the y position for the square | |
center.y = center.y + whiteSpace + square.height; | |
square.center = center; | |
//set the y position for the ellipse | |
center.y = center.y + whiteSpace + ellipse.height; | |
ellipse.center = center; | |
//set the y position for the circle | |
center.y = center.y + whiteSpace + circle.height; | |
circle.center = center; | |
//add all the objects to the canvas | |
[self.canvas addShape:rectangle]; | |
[self.canvas addShape:square]; | |
[self.canvas addShape:ellipse]; | |
[self.canvas addShape:circle]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment