Hello everyone, Im trying to port a P5 sketch that all it does is it writes to a fifo, here’s the P5 sketch:
PVector mouse = new PVector();
void setup() {
size(displayWidth/3, displayHeight/3);
fill(0);
}
void draw() {
background(255);
mouse.set(mouseX, mouseY);
ellipse(mouse.x, mouse.y, 30, 30);
thread("writeToPipe");
}
void writeToPipe() {
saveStrings("../myfifo", str(mouse.array()));
}
here’s a video of what Im trying to achieve:
https://www.youtube.com/watch?v=bB2QQrfb36s
the idea behind using a thread is for getting the program to not stall while there is nothing reading the pipe.
This is what I have in ofx:
#include "ofMain.h"
#include <iostream>
#define width 400
#define height 400
using namespace std;
class ofApp : public ofBaseApp{
ofPoint p;
ofstream myfile;
public:
void setup()
{
ofBackground(255,255,255);
ofSetColor(0,0,0);
}
void update()
{
p.set(ofGetMouseX(), ofGetMouseY());
myfile.open ("/Users/JLafarga/Documents/of_v0.8.1_osx_release/apps/myApps/FIFO_test/bin/data/myfifo");
myfile << ofToString(p.x) <<"\n"<<ofToString(p.y)<<"\n";
myfile.close();
}
void draw()
{
ofCircle(p.x, p.y, 50);
}
void keyPressed(int key) {}
void keyReleased(int key) {}
void mouseMoved(int x, int y ) {}
void mouseDragged(int x, int y, int button) {}
void mousePressed(int x, int y, int button) {}
void mouseReleased(int x, int y, int button) {}
void windowResized(int w, int h) {}
void gotMessage(ofMessage msg) {}
void dragEvent(ofDragInfo dragInfo) {}
};
int main() {
ofSetupOpenGL(width, height, OF_WINDOW);
ofRunApp(new ofApp());
}
I have no idea where to go from there, the ofThread documentation is not all that great. Please help!