Skip to content

Instantly share code, notes, and snippets.

@C4Code
Created March 19, 2013 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save C4Code/5198175 to your computer and use it in GitHub Desktop.
Save C4Code/5198175 to your computer and use it in GitHub Desktop.
Basic ColorAt example.
#import "C4WorkSpace.h"
@implementation C4WorkSpace {
C4Image *image;
NSInteger count;
C4Timer *timer;
}
-(void)setup {
image = [C4Image imageNamed:@"C4Sky"];
image.center = self.canvas.center;
[image loadPixelData];
[self listenFor:@"pixelDataWasLoaded" andRunMethod:@"grabColors"];
}
-(void)grabColors {
timer = [C4Timer timerWithInterval:0.05f target:self method:@"test" repeats:YES];
[timer start];
}
-(void)test {
CGPoint randomPoint = CGPointMake([C4Math randomInt:(int)image.width],[C4Math randomInt:(int)image.height]);
UIColor *c = [image colorAt:randomPoint];
randomPoint.x += image.origin.x;
randomPoint.y += image.origin.y;
C4Shape *s = [C4Shape ellipse:CGRectMake(randomPoint.x-10, randomPoint.y-10, 20, 20)];
s.fillColor = c;
s.lineWidth = 0.0f;
[self.canvas addShape:s];
count++;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment