Created
August 15, 2014 21:27
-
-
Save michaelschade/9ccbd190dfb06fd58790 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "MSAppDelegate.h" | |
@implementation MSAppDelegate | |
@synthesize lifxContext, lastKeyPress; | |
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification | |
{ | |
self.lifxContext = [[LFXClient sharedClient] localNetworkContext]; | |
self.lastKeyPress = CACurrentMediaTime(); | |
[NSEvent addGlobalMonitorForEventsMatchingMask:(NSKeyDownMask) handler:^(NSEvent *event){ | |
NSTimeInterval keyPressElapsed = CACurrentMediaTime() - self.lastKeyPress; | |
NSTimeInterval duration = 0.8 + 40*(keyPressElapsed*keyPressElapsed); //(10*keyPressElapsed - 1)/keyPressElapsed; | |
if ([event isARepeat]) { | |
duration = 1.4; | |
} else if (duration < 0) { | |
duration = 0; | |
} else if (duration > 5) { | |
duration = 5; | |
} | |
NSLog(@"Last key press: %f | time elapsed: %f | duration: %f", self.lastKeyPress, keyPressElapsed, duration); | |
for (LFXLight *light in lifxContext.allLightsCollection.lights) { | |
LFXHSBKColor *color = [LFXHSBKColor colorWithHue:arc4random()%360 saturation:1.0 brightness:1.0]; | |
[light setColor:color overDuration:duration]; | |
} | |
self.lastKeyPress = CACurrentMediaTime(); | |
}]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment