Created
November 23, 2012 17:56
-
-
Save aaronsherwood/4136650 to your computer and use it in GitHub Desktop.
openFrameworks code for the Glockentar
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
#include "testApp.h" | |
const int width =320; | |
const int height = 240; | |
int interval [8]; | |
bool trigger [8]; | |
float counter [8]; | |
int rectSpot [8]; | |
float triggerCounter [8]; | |
int inByte; | |
bool calibrateSquare =false; | |
//-------------------------------------------------------------- | |
void testApp::setup(){ | |
for (int i=0;i<8;i++){ | |
interval[i]=5; | |
trigger[i]=false; | |
counter[i]=0; | |
triggerCounter[i]=0; | |
} | |
ofSetWindowTitle("Glockentar"); | |
mainOutputSyphonServer.setName("Screen Output"); | |
mClient.setup(); | |
mClient.setApplicationName("Simple Server"); | |
mClient.setServerName(""); | |
ofSetFrameRate(60); // if vertical sync is off, we can go a bit fast... this caps the framerate at 60fps. | |
serial.setup(5, 9600); | |
} | |
//-------------------------------------------------------------- | |
void testApp::update(){ | |
//read from arduino | |
if ( serial.available() > 0 ) | |
{ | |
inByte=serial.readByte(); | |
counter[inByte]=0; | |
interval[inByte]=5; | |
trigger[inByte]=true; | |
rectSpot[inByte]=210-30*inByte; | |
inByte=0; | |
serial.flush(); | |
} | |
//loop through each guitar string | |
for (int i=0;i<8;i++){ | |
//if string triggered, calculate logarithmic curve for rect end point to follow | |
if (trigger[i]){ | |
counter[i] += interval[i]; | |
float x=ofNormalize(counter[i], 0, 320); | |
x= (1-pow(1-x,10)) * 320; | |
//execute curve ('triggerCounter' is used for length of the rect) | |
triggerCounter[i]=x; | |
if (triggerCounter[i]==320) { | |
interval[i]=-interval[i]; | |
} | |
if (triggerCounter[i]<0){ | |
trigger[i]=false; | |
} | |
} | |
} | |
} | |
//-------------------------------------------------------------- | |
void testApp::draw(){ | |
ofBackground(0); | |
ofSetColor(255, 0, 0); | |
ofFill(); | |
for (int i=0;i<8;i++){ | |
ofRect(0, rectSpot[i], triggerCounter[i], 30); | |
} | |
if (calibrateSquare){ | |
ofRect(0,0,320,240); | |
} | |
// Syphon Stuff | |
mClient.draw(50, 50); | |
mainOutputSyphonServer.publishScreen(); | |
} | |
//-------------------------------------------------------------- | |
void testApp::keyPressed (int key){ | |
if (key == 'c'){ | |
calibrateSquare=!calibrateSquare; | |
} | |
if (key == '1'){ | |
counter[0]=0; | |
interval[0]=5; | |
trigger[0]=true; | |
rectSpot[0]=210; | |
} | |
if (key == '2'){ | |
counter[1]=0; | |
interval[1]=5; | |
trigger[1]=true; | |
rectSpot[1]=180; | |
} | |
if (key == '3'){ | |
counter[2]=0; | |
interval[2]=5; | |
trigger[2]=true; | |
rectSpot[2]=150; | |
} | |
if (key == '4'){ | |
counter[3]=0; | |
interval[3]=5; | |
trigger[3]=true; | |
rectSpot[3]=120; | |
} | |
if (key == '5'){ | |
counter[4]=0; | |
interval[4]=5; | |
trigger[4]=true; | |
rectSpot[4]=90; | |
} | |
if (key == '6'){ | |
counter[5]=0; | |
interval[5]=5; | |
trigger[5]=true; | |
rectSpot[5]=60; | |
} | |
if (key == '7'){ | |
counter[6]=0; | |
interval[6]=5; | |
trigger[6]=true; | |
rectSpot[6]=30; | |
} | |
if (key == '8'){ | |
counter[7]=0; | |
interval[7]=5; | |
trigger[7]=true; | |
rectSpot[7]=0; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment