Last active
February 11, 2018 21:08
-
-
Save stephanschulz/90aab1f96a7f8265051c49f8c93dd16d 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
| #include "ofApp.h" | |
| int speakerStates[10]; | |
| //-------------------------------------------------------------- | |
| void ofApp::setup(){ | |
| for(int i=0; i<10;i++){ | |
| speakerStates[i] = 0; | |
| } | |
| } | |
| //-------------------------------------------------------------- | |
| void ofApp::update(){ | |
| } | |
| //-------------------------------------------------------------- | |
| void ofApp::draw(){ | |
| ofPushMatrix(); | |
| ofTranslate(10,10); | |
| int y = 0; | |
| int h = 20; | |
| ofSetColor(255); | |
| //display each speaker's 7 possible states | |
| string temp_str; | |
| string key_str; | |
| for(int i=9; i>=0;i--){ | |
| temp_str += ofToString(speakerStates[i]) + " , "; | |
| key_str += ofToString(i) + " , "; | |
| } | |
| ofDrawBitmapString("key "+ key_str,0,y+=h); | |
| ofDrawBitmapString("speakerStates "+ temp_str,0,y+=h); | |
| //pass speaker state in to correct 3bit location of final integer | |
| string binaryString; | |
| int allStatesAsInt = 0; | |
| for(int i=0; i<10;i++){ | |
| binaryString = ofToBinary(speakerStates[i]); | |
| allStatesAsInt = allStatesAsInt | (speakerStates[i] << (3*i)); | |
| } | |
| //final integer as binary string | |
| binaryString = ofToBinary(allStatesAsInt); | |
| ofDrawBitmapString("allStatesAsInt "+ ofToString(allStatesAsInt),0,y+=h); | |
| ofDrawBitmapString("binaryString "+ ofToString(binaryString),0,y+=h); | |
| ofDrawBitmapString("binaryString "+ofToString(binaryString).substr(0,2),0,y += h); | |
| //display binary string seperated in groups of 3bit for better visibility | |
| int c = 0; | |
| for(int i=2; i<32;i+=3){ | |
| ofSetColor(255 * c); | |
| ofDrawBitmapString(ofToString(binaryString).substr(i,3),114 + i*8,y); | |
| c += 1; | |
| c %= 2; | |
| } | |
| ofPopMatrix(); | |
| } | |
| //-------------------------------------------------------------- | |
| void ofApp::keyReleased(int key){ | |
| if (key >= '0' && key <= '9'){ | |
| int i = key - '0'; | |
| // ofLog()<<"key "<<key<<" i "<<i; | |
| speakerStates[i] ++; | |
| speakerStates[i] %= 7; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment