Skip to content

Instantly share code, notes, and snippets.

@turtlesoupy
Created September 16, 2012 08:16
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save turtlesoupy/3731538 to your computer and use it in GitHub Desktop.
Save turtlesoupy/3731538 to your computer and use it in GitHub Desktop.
Really cruddy iOS particle system to demo emissionLongitude
//
// SFSViewController.m
// AmazingParticleSpinner
//
// Created by Thomas Dimson on 9/15/12.
// Copyright (c) 2012 Thomas Dimson. All rights reserved.
//
#import "SFSViewController.h"
#import <QuartzCore/QuartzCore.h>
@implementation SFSViewController {
__weak UILabel *_angleLabel;
__weak CAEmitterLayer *_emitterLayer;
}
- (void)viewDidLoad
{
[super viewDidLoad];
CAEmitterLayer *emitterLayer = [CAEmitterLayer layer];
emitterLayer.emitterPosition = self.view.center;
_emitterLayer = emitterLayer;
[self.view.layer addSublayer:emitterLayer];
CAEmitterCell *funnyEmitterCell = [CAEmitterCell emitterCell];
funnyEmitterCell.contents = (id)[UIImage imageNamed:@"funny.jpg"].CGImage;
funnyEmitterCell.birthRate = 10.0;
funnyEmitterCell.velocity = 200.0;
funnyEmitterCell.lifetime = 5.0;
funnyEmitterCell.scale = 0.1;
funnyEmitterCell.name = @"funny";
emitterLayer.emitterCells = [NSArray arrayWithObject:funnyEmitterCell];
[self bumpAngle];
UILabel *angleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 100, 30)];
angleLabel.backgroundColor = [UIColor clearColor];
[self.view addSubview:angleLabel];
_angleLabel = angleLabel;
}
- (void) bumpAngle {
NSNumber *emissionLongitude = [_emitterLayer valueForKeyPath:@"emitterCells.funny.emissionLongitude"];
NSNumber *nextLongitude = [NSNumber numberWithFloat:[emissionLongitude floatValue] + 0.02];
[_emitterLayer setValue:nextLongitude forKeyPath:@"emitterCells.funny.emissionLongitude"];
_angleLabel.text = [NSString stringWithFormat:@"%.0f degrees", [nextLongitude floatValue] * 180 / M_PI];
[self performSelector:@selector(bumpAngle) withObject:nil afterDelay:0.1];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment