Last active
October 15, 2019 16:03
-
-
Save prisonerjohn/069e469f7d421bff6f906089192f695d to your computer and use it in GitHub Desktop.
Sensing Machines OSC
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" | |
void ofApp::setup() | |
{ | |
ofSetWindowShape(640, 480); | |
// Make the circle smoother by increasing the resolution. | |
ofSetCircleResolution(128); | |
// Set up the OSC receiver. | |
recvPort = 3030; | |
receiver.setup(recvPort); | |
} | |
void ofApp::update() | |
{ | |
while (receiver.hasWaitingMessages()) | |
{ | |
// Get the next message. | |
ofxOscMessage msg; | |
receiver.getNextMessage(msg); | |
if (msg.getAddress() == "/cursor/move") | |
{ | |
cursorX = msg.getArgAsInt(0); | |
cursorY = msg.getArgAsInt(1); | |
} | |
else if (msg.getAddress() == "/cursor/color") | |
{ | |
// Generate a new random color. | |
cursorColor = ofColor(ofRandom(127, 255), ofRandom(127, 255), ofRandom(127, 255)); | |
} | |
else | |
{ | |
ofLogWarning(__FUNCTION__) << "Unrecognized message " << msg.getAddress(); | |
} | |
} | |
} | |
void ofApp::draw() | |
{ | |
ofBackground(0); | |
// Draw a circle at the cursor position. | |
ofSetColor(cursorColor); | |
ofDrawCircle(cursorX, cursorY, 50); | |
} |
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
#pragma once | |
#include "ofMain.h" | |
#include "ofxOsc.h" | |
class ofApp : public ofBaseApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
int recvPort; | |
ofxOscReceiver receiver; | |
int cursorX; | |
int cursorY; | |
ofColor cursorColor; | |
}; |
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" | |
void ofApp::setup() | |
{ | |
ofSetWindowShape(640, 480); | |
// Make the circle smoother by increasing the resolution. | |
ofSetCircleResolution(128); | |
// Set up the OSC sender. | |
sendAddr = "localhost"; | |
sendPort = 3030; | |
sender.setup(sendAddr, sendPort); | |
} | |
void ofApp::update() | |
{ | |
} | |
void ofApp::draw() | |
{ | |
ofBackground(0); | |
// Draw a circle at the mouse position. | |
if (ofGetMousePressed()) | |
{ | |
ofFill(); | |
} | |
else | |
{ | |
ofNoFill(); | |
} | |
ofSetColor(255); | |
ofDrawCircle(ofGetMouseX(), ofGetMouseY(), 50); | |
ofFill(); | |
} | |
void ofApp::keyPressed(int key) | |
{ | |
if (key == ' ') | |
{ | |
ofxOscMessage msg; | |
msg.setAddress("/cursor/color"); | |
sender.sendMessage(msg); | |
} | |
} | |
void ofApp::mouseDragged(int x, int y, int button) | |
{ | |
ofxOscMessage msg; | |
msg.setAddress("/cursor/move"); | |
msg.addIntArg(ofGetMouseX()); | |
msg.addIntArg(ofGetMouseY()); | |
sender.sendMessage(msg); | |
} |
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
#pragma once | |
#include "ofMain.h" | |
#include "ofxOsc.h" | |
class ofApp : public ofBaseApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
void keyPressed(int key); | |
void mouseDragged(int x, int y, int button); | |
std::string sendAddr; | |
int sendPort; | |
ofxOscSender sender; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment