This file contains 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
#pragma once | |
template<typename T> | |
class DoubleBuffer | |
{ | |
public: | |
DoubleBuffer():front_(&a_),back_(&b_){} | |
void swap() { T*t=front_;front_=back_;back_=t;; } | |
T& front() { return *front_; } | |
T& back() { return *back_; } |
This file contains 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
#pragma once | |
#include "ofxMultiKinectV2.h" | |
#include "ofxCv.h" | |
class Kinect : public ofxMultiKinectV2 | |
{ | |
public: | |
template<typename PixelType> | |
ofPixels_<PixelType> getClippedPixels(const ofRectangle &crop_rect, unsigned short min_distance_in_mm, unsigned short max_distance_in_mm) { |
This file contains 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
class Stepper | |
{ | |
public: | |
void setFps(float fps) { step_time_ = 1/fps; } | |
void play() { is_playing_ = true; } | |
void step() { time_counter_+=step_time_; } | |
void stop() { is_playing_=false; time_counter_=0; } | |
void update(float elapsed_time) { | |
steps_past_ = 0; | |
if(isPlaying()) { |
This file contains 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
vector<float> getVolumes(const ofVec3f &pos, const vector<ofVec3f> &speakers, float rolloff, float blur_radius) { | |
vector<float> volumes; | |
float sum = 0; | |
transform(begin(speakers), end(speakers), back_inserter(volumes), [&sum, pos, rolloff, blur_radius](const ofVec3f &speaker) { | |
const float rolloff_default = 20*log10f(0.5f); | |
float power = pow(sqrt(pos.squareDistance(speaker)+pow(blur_radius,2)), rolloff/rolloff_default); | |
sum += pow(power,2); | |
return power; | |
}); | |
sum = sqrt(sum); |
This file contains 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
#pragma once | |
#include "ofxWatchFile.h" | |
#include "ofxJsonUtils.h" | |
#define KVCS1(name) kv(name) | |
#define KVCS2(name, ...) KVCS1(name), KVCS1(__VA_ARGS__) | |
#define KVCS3(name, ...) KVCS1(name), KVCS2(__VA_ARGS__) | |
#define KVCS4(name, ...) KVCS1(name), KVCS3(__VA_ARGS__) |
This file contains 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 Foundation | |
extension String { | |
func regexEscaped() -> String { | |
var str: String = self | |
"\\*+.?{}()[]-|$".forEach{ | |
let s = String($0) | |
str = str.replacingOccurrences(of: s, with: "\\"+s) | |
} | |
return str |
This file contains 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
#!/bin/bash | |
CURRENT_FILE_PATH=`osascript -e "tell application id \"com.apple.dt.Xcode\" to return path of document 1 whose name ends with (word -1 of (get name of window 1))"` | |
/usr/bin/open -a Terminal "$(/usr/bin/dirname $CURRENT_FILE_PATH)" |
This file contains 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
class SoundManager | |
{ | |
public: | |
static std::shared_ptr<SoundManager> shared() { | |
static auto instance = std::make_shared<SoundManager>(); | |
return instance; | |
} | |
std::shared_ptr<ofSoundPlayer> load(const std::string &identifier, const std::string &path) { | |
auto player = std::make_shared<ofSoundPlayer>(); | |
if(player->load(path) && player_.insert(std::make_pair(identifier, player)).second) { |
This file contains 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
ofPushStyle(); | |
ofEnableBlendMode(OF_BLENDMODE_SUBTRACT); | |
float black = attenuation_+attenuation_fract_; | |
attenuation_fract_ = std::modf(black*255, &black)/255.f; | |
ofSetColor(black); | |
ofDrawRectangle(ofGetCurrentViewport()); | |
ofPopStyle(); |
This file contains 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 UIKit | |
extension UIView { | |
func recursiveSearch(condition: (UIView)->Bool, action: (UIView)->Void) { | |
self.subviews.forEach { view in | |
if condition(view) { | |
action(view) | |
} | |
view.recursiveSearch(condition: condition, action: action) | |
} |