Skip to content

Instantly share code, notes, and snippets.

@C4Tutorials
Created April 3, 2013 20:29
Show Gist options
  • Save C4Tutorials/5304944 to your computer and use it in GitHub Desktop.
Save C4Tutorials/5304944 to your computer and use it in GitHub Desktop.
Masking a shape with an image, and an image with a shape.
//
// C4WorkSpace.m
//
// Created by Travis Kirton.
//
#import "C4WorkSpace.h"
@implementation C4WorkSpace {
C4Shape *circle, *shapeMask;
C4Image *table, *imageMask;
}
-(void)setup {
circle = [C4Shape ellipse:CGRectMake(0,0,240,240)];
circle.lineWidth = 0.0f;
circle.fillColor = C4BLUE;
imageMask = [C4Image imageNamed:@"C4Gradient"];
imageMask.frame = circle.bounds;
circle.mask = imageMask;
table = [C4Image imageNamed:@"C4Table"];
table.height = circle.height;
shapeMask = [C4Shape rect:CGRectMake(0, 0, 170, 170)];
shapeMask.center = CGPointMake(table.width / 2.0f, table.height / 2.0f);
shapeMask.rotation = QUARTER_PI;
table.mask = shapeMask;
circle.center = CGPointMake(self.canvas.width / 3.0f, self.canvas.center.y);
table.center = CGPointMake(self.canvas.width * 2.0f / 3.0f, self.canvas.center.y);
[self.canvas addObjects:@[circle,table]];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment