34@interface OOFlasherEntity (Internal)
36- (void) setUpColors:(NSArray *)colorSpecifiers;
44+ (instancetype) flasherWithDictionary:(NSDictionary *)dictionary
46 return [[[
OOFlasherEntity alloc] initWithDictionary:dictionary] autorelease];
50- (id) initWithDictionary:(NSDictionary *)dictionary
52 float size = [dictionary oo_floatForKey:@"size" defaultValue:1.0f];
54 if ((
self = [super initWithDiameter:
size]))
56 _frequency = [dictionary oo_floatForKey:@"frequency" defaultValue:1.0f] * 2.0f;
57 _phase = [dictionary oo_floatForKey:@"phase" defaultValue:0.0f];
58 _brightfraction = [dictionary oo_floatForKey:@"bright_fraction" defaultValue:0.5f];
60 [
self setUpColors:[dictionary oo_arrayForKey:@"colors"]];
61 [
self getCurrentColorComponents];
63 [
self setActive:[dictionary oo_boolForKey:@"initially_on" defaultValue:YES]];
77- (void) setUpColors:(NSArray *)colorSpecifiers
79 NSMutableArray *colors = [NSMutableArray arrayWithCapacity:[colorSpecifiers count]];
81 NSEnumerator *specEnum = [colorSpecifiers objectEnumerator];
82 while ((specifier = [specEnum nextObject]))
87 _colors = [colors copy];
93 [
self setColor:[_colors objectAtIndex:_activeColor] alpha:_colorComponents[3]];
103- (void) setActive:(BOOL)active
112 green:_colorComponents[1]
113 blue:_colorComponents[2]
114 alpha:_colorComponents[3]];
124- (void) setFrequency:(
float)frequency
126 _frequency = frequency;
136- (void) setPhase:(
float)phase
144 return _brightfraction;
148- (void) setFraction:(
float)fraction
150 _brightfraction = fraction;
156 [
super update:delta_t];
162 float wave = sinf(_frequency *
M_PI * (_time + _phase));
163 NSUInteger
count = [_colors count];
164 if (
count > 1 && wave < 0)
166 if (!_justSwitched && wave > _wave)
170 _activeColor %=
count;
171 [
self setColor:[_colors objectAtIndex:_activeColor]];
174 else if (_justSwitched)
179 float threshold = cosf(_brightfraction *
M_PI);
181 float brightness = _brightfraction;
182 if (wave > threshold)
184 brightness = _brightfraction + (((1-_brightfraction)/(1-threshold))*(wave-threshold));
186 else if (wave < threshold)
188 brightness = _brightfraction + ((_brightfraction/(threshold+1))*(wave-threshold));
191 _colorComponents[3] = brightness;
197 _colorComponents[3] = 1.0;
202- (void) drawImmediate:(
bool)immediate translucent:(
bool)translucent
206 [
super drawImmediate:immediate translucent:translucent];
211- (void) drawSubEntityImmediate:(
bool)immediate translucent:(
bool)translucent
215 [
super drawSubEntityImmediate:immediate translucent:translucent];
226- (double)findCollisionRadius
228 return [
self diameter] / 2.0;
232- (void) rescaleBy:(GLfloat)factor
234 [
self setDiameter:[
self diameter] * factor];
238- (void) rescaleBy:(GLfloat)factor writeToCache:(BOOL)writeToCache
247@implementation Entity (OOFlasherEntityExtensions)
void getCurrentColorComponents()
OOColor * colorWithRed:green:blue:alpha:(float red,[green] float green,[blue] float blue,[alpha] float alpha)
OOColor * colorWithDescription:saturationFactor:(id description,[saturationFactor] float factor)