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 foreach (specifier, colorSpecifiers)
86 _colors = [colors copy];
92 [
self setColor:[_colors objectAtIndex:_activeColor] alpha:_colorComponents[3]];
102- (void) setActive:(BOOL)active
111 green:_colorComponents[1]
112 blue:_colorComponents[2]
113 alpha:_colorComponents[3]];
123- (void) setFrequency:(
float)frequency
125 _frequency = frequency;
135- (void) setPhase:(
float)phase
143 return _brightfraction;
147- (void) setFraction:(
float)fraction
149 _brightfraction = fraction;
155 [
super update:delta_t];
161 float wave = sinf(_frequency *
M_PI * (_time + _phase));
162 NSUInteger
count = [_colors count];
163 if (
count > 1 && wave < 0)
165 if (!_justSwitched && wave > _wave)
169 _activeColor %=
count;
170 [
self setColor:[_colors objectAtIndex:_activeColor]];
173 else if (_justSwitched)
178 float threshold = cosf(_brightfraction *
M_PI);
180 float brightness = _brightfraction;
181 if (wave > threshold)
183 brightness = _brightfraction + (((1-_brightfraction)/(1-threshold))*(wave-threshold));
185 else if (wave < threshold)
187 brightness = _brightfraction + ((_brightfraction/(threshold+1))*(wave-threshold));
190 _colorComponents[3] = brightness;
196 _colorComponents[3] = 1.0;
201- (void) drawImmediate:(
bool)immediate translucent:(
bool)translucent
205 [
super drawImmediate:immediate translucent:translucent];
210- (void) drawSubEntityImmediate:(
bool)immediate translucent:(
bool)translucent
214 [
super drawSubEntityImmediate:immediate translucent:translucent];
225- (double)findCollisionRadius
227 return [
self diameter] / 2.0;
231- (void) rescaleBy:(GLfloat)factor
233 [
self setDiameter:[
self diameter] * factor];
237- (void) rescaleBy:(GLfloat)factor writeToCache:(BOOL)writeToCache
246@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)