diff --git a/example_BigGrid/src/ofApp.cpp b/example_BigGrid/src/ofApp.cpp index 43f2819..ef79b34 100644 --- a/example_BigGrid/src/ofApp.cpp +++ b/example_BigGrid/src/ofApp.cpp @@ -12,6 +12,8 @@ void ofApp::setup() // You define the stage size and draw into the stage opcClient.setupStage(320, 320); + defaultEffects.setup(opcClient.getStageCenterX(), opcClient.getStageCenterY(), opcClient.getStageWidth(), opcClient.getStageHeight()); + grid32x32.setupLedGrid(32, 32, 1, 1, 10); } //-------------------------------------------------------------- @@ -19,12 +21,14 @@ void ofApp::update() { ofSetWindowTitle("example_BigGrid"); + opcClient.update(); + // Now Draw the effects to the stage opcClient.beginStage(); // Draw what you want rendered here // For now here are some default effects - opcClient.drawDefaultEffects(effect); + defaultEffects.draw(effect); opcClient.endStage(); @@ -40,7 +44,6 @@ void ofApp::update() // Write out the first set of data // To do! } - opcClient.update(); } //-------------------------------------------------------------- void ofApp::draw() diff --git a/example_BigGrid/src/ofApp.h b/example_BigGrid/src/ofApp.h index c84f1cf..a65e617 100644 --- a/example_BigGrid/src/ofApp.h +++ b/example_BigGrid/src/ofApp.h @@ -2,6 +2,7 @@ #include "ofMain.h" #include "ofxOPC.h" +#include "Effects.h" class ofApp : public ofBaseApp{ @@ -15,6 +16,7 @@ class ofApp : public ofBaseApp{ void exit(); ofxOPC opcClient; + Effects defaultEffects; ofxNeoPixelGrid grid32x32; int effect; diff --git a/example_chaining/src/ofApp.cpp b/example_chaining/src/ofApp.cpp index bf5f247..feead53 100644 --- a/example_chaining/src/ofApp.cpp +++ b/example_chaining/src/ofApp.cpp @@ -12,6 +12,8 @@ void ofApp::setup() // You define the stage size and draw into the stage opcClient.setupStage(250, 250); + defaultEffects.setup(opcClient.getStageCenterX(), opcClient.getStageCenterY(), opcClient.getStageWidth(), opcClient.getStageHeight()); + // Setup the Grabbing positions for (int y = 0; y < 5; y++) { for (int x = 0; x < 5; x++) { @@ -35,7 +37,7 @@ void ofApp::update() // Draw what you want rendered here // For now here are some default effects - opcClient.drawDefaultEffects(effect); + defaultEffects.draw(effect); opcClient.endStage(); diff --git a/example_chaining/src/ofApp.h b/example_chaining/src/ofApp.h index d8b8873..c178e17 100644 --- a/example_chaining/src/ofApp.h +++ b/example_chaining/src/ofApp.h @@ -17,6 +17,8 @@ class ofApp : public ofBaseApp{ map neoPixels; vector ringOrigins; + Effects defaultEffects; + int effect; bool hide; }; diff --git a/example_generic_neopixels/example_generic_neopixels.xcodeproj/project.pbxproj b/example_generic_neopixels/example_generic_neopixels.xcodeproj/project.pbxproj index 448cd9d..e2bd7c1 100644 --- a/example_generic_neopixels/example_generic_neopixels.xcodeproj/project.pbxproj +++ b/example_generic_neopixels/example_generic_neopixels.xcodeproj/project.pbxproj @@ -65,6 +65,7 @@ 3C98599F512D19BB57939D95 /* ofxNeoPixelGrid.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 30; name = ofxNeoPixelGrid.h; path = ../../../addons/ofxOPC/src/ofxNeoPixelGrid.h; sourceTree = SOURCE_ROOT; }; 3EFD920E7CFE6B6B1066E3BA /* ofxNeoPixelRing.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.cpp; fileEncoding = 30; name = ofxNeoPixelRing.cpp; path = ../../../addons/ofxOPC/src/ofxNeoPixelRing.cpp; sourceTree = SOURCE_ROOT; }; 5E31517C6C120F6DEBCCB9CC /* ofxNeoPixelRing.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 30; name = ofxNeoPixelRing.h; path = ../../../addons/ofxOPC/src/ofxNeoPixelRing.h; sourceTree = SOURCE_ROOT; }; + 63E65F661C8B56FF00C2E22A /* Effects.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Effects.h; path = ../src/Effects.h; sourceTree = ""; }; BF88F02779DD820913ACEA06 /* ofxTCPClient.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.cpp; fileEncoding = 30; name = ofxTCPClient.cpp; path = ../../../addons/ofxNetwork/src/ofxTCPClient.cpp; sourceTree = SOURCE_ROOT; }; C8C9B823D7872F9CBF03A813 /* ofxTCPClient.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 30; name = ofxTCPClient.h; path = ../../../addons/ofxNetwork/src/ofxTCPClient.h; sourceTree = SOURCE_ROOT; }; C8E2BE30E0CBB25AA8972B43 /* ofxNeoPixels.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 30; name = ofxNeoPixels.h; path = ../../../addons/ofxOPC/src/ofxNeoPixels.h; sourceTree = SOURCE_ROOT; }; @@ -141,6 +142,7 @@ FDDA157BEF92629BF3E6A80D /* ofxNeoPixelStrip.h */, 2C24C81D88B85EC85495F7CA /* ofxOPC.cpp */, 33F3EFB014D3C27B5DEAB7C8 /* ofxOPC.h */, + 63E65F661C8B56FF00C2E22A /* Effects.h */, ); name = src; sourceTree = ""; diff --git a/example_generic_neopixels/src/ofApp.cpp b/example_generic_neopixels/src/ofApp.cpp index 27b78dc..41963f7 100644 --- a/example_generic_neopixels/src/ofApp.cpp +++ b/example_generic_neopixels/src/ofApp.cpp @@ -13,6 +13,8 @@ void ofApp::setup() // You define the stage size and draw into the stage opcClient.setupStage(500, 500); + defaultEffects.setup(opcClient.getStageCenterX(), opcClient.getStageCenterY(), opcClient.getStageWidth(), opcClient.getStageHeight()); + // Construct the objects neoPixelObjects.insert( std::pair(0,new ofxNeoPixelStrip(50, opcClient.getStageCenterY()-(30*5), 60, 5)) ); neoPixelObjects.insert( std::pair(1,new ofxNeoPixelStrip(opcClient.getStageWidth()-50, opcClient.getStageCenterY()-(30*5), 60, 5)) ); @@ -26,9 +28,11 @@ void ofApp::update() { ofSetWindowTitle("example_generic_neopixels"); + opcClient.update(); + // Now Draw the effects to the stage opcClient.beginStage(); - opcClient.drawDefaultEffects(effect); + defaultEffects.draw(effect); opcClient.endStage(); // Get Objects @@ -47,8 +51,6 @@ void ofApp::update() opcClient.writeChannel(i, neoPixelObjects[i]->colorData()); } } - - opcClient.update(); } //-------------------------------------------------------------- void ofApp::draw() diff --git a/example_generic_neopixels/src/ofApp.h b/example_generic_neopixels/src/ofApp.h index 3148b43..af92ece 100644 --- a/example_generic_neopixels/src/ofApp.h +++ b/example_generic_neopixels/src/ofApp.h @@ -15,6 +15,7 @@ class ofApp : public ofBaseApp{ void exit(); ofxOPC opcClient; + Effects defaultEffects; map neoPixelObjects; int effect; diff --git a/example_multiple_ofxNeoPixelStrips/src/ofApp.cpp b/example_multiple_ofxNeoPixelStrips/src/ofApp.cpp index 1355a2b..7912e09 100644 --- a/example_multiple_ofxNeoPixelStrips/src/ofApp.cpp +++ b/example_multiple_ofxNeoPixelStrips/src/ofApp.cpp @@ -12,6 +12,8 @@ void ofApp::setup() // You define the stage size and draw into the stage opcClient.setupStage(500, 500); + defaultEffects.setup(opcClient.getStageCenterX(), opcClient.getStageCenterY(), opcClient.getStageWidth(), opcClient.getStageHeight()); + for (int x = 0; x < 8; x++) { strips.push_back(ofxNeoPixelStrip(((opcClient.getStageWidth()/8)/2)+(x*(opcClient.getStageWidth()/8)), opcClient.getStageCenterY()-(30*5), 60, 5)); } @@ -22,12 +24,14 @@ void ofApp::update() { ofSetWindowTitle("example_ofxNeoPixelStrips"); + opcClient.update(); + // Now Draw the effects to the stage opcClient.beginStage(); // Draw what you want rendered here // For now here are some default effects - opcClient.drawDefaultEffects(effect); + defaultEffects.draw(effect); opcClient.endStage(); @@ -47,8 +51,6 @@ void ofApp::update() opcClient.writeChannel(i, strips[i].colorData()); } } - - opcClient.update(); } //-------------------------------------------------------------- void ofApp::draw() diff --git a/example_multiple_ofxNeoPixelStrips/src/ofApp.h b/example_multiple_ofxNeoPixelStrips/src/ofApp.h index 72bf46d..17d9196 100644 --- a/example_multiple_ofxNeoPixelStrips/src/ofApp.h +++ b/example_multiple_ofxNeoPixelStrips/src/ofApp.h @@ -16,6 +16,7 @@ class ofApp : public ofBaseApp{ ofxOPC opcClient; deque strips; + Effects defaultEffects; int effect; bool hide; diff --git a/example_ofxNeoPixelGrids/src/ofApp.cpp b/example_ofxNeoPixelGrids/src/ofApp.cpp index 67aae66..92da209 100644 --- a/example_ofxNeoPixelGrids/src/ofApp.cpp +++ b/example_ofxNeoPixelGrids/src/ofApp.cpp @@ -12,6 +12,8 @@ void ofApp::setup() // You define the stage size and draw into the stage opcClient.setupStage(500, 500); + defaultEffects.setup(opcClient.getStageCenterX(), opcClient.getStageCenterY(), opcClient.getStageWidth(), opcClient.getStageHeight()); + grid5x7.setupLedGrid(5, 7, 10, 10, 8); grid8x8.setupLedGrid(8, 8, 10+(7*8), 10, 8); grid32x32.setupLedGrid(32, 32, 10, 10+(10*8), 8); @@ -21,13 +23,14 @@ void ofApp::update() { ofSetWindowTitle("example_ofxNeoPixelGrids"); + opcClient.update(); + // Now Draw the effects to the stage opcClient.beginStage(); // Draw what you want rendered here - // For now here are some default effects - opcClient.drawDefaultEffects(effect); + defaultEffects.draw(effect); opcClient.endStage(); @@ -46,8 +49,6 @@ void ofApp::update() opcClient.writeChannelOne(grid5x7.colorData()); opcClient.writeChannelTwo(grid8x8.colorData()); } - - opcClient.update(); } //-------------------------------------------------------------- void ofApp::draw() diff --git a/example_ofxNeoPixelGrids/src/ofApp.h b/example_ofxNeoPixelGrids/src/ofApp.h index a2085a8..f798035 100644 --- a/example_ofxNeoPixelGrids/src/ofApp.h +++ b/example_ofxNeoPixelGrids/src/ofApp.h @@ -17,6 +17,8 @@ class ofApp : public ofBaseApp{ ofxNeoPixelGrid grid5x7; ofxNeoPixelGrid grid32x32; + Effects defaultEffects; + int effect; bool hide; }; diff --git a/example_ofxNeoPixelRings/src/ofApp.cpp b/example_ofxNeoPixelRings/src/ofApp.cpp index 2e96b18..98a19bf 100644 --- a/example_ofxNeoPixelRings/src/ofApp.cpp +++ b/example_ofxNeoPixelRings/src/ofApp.cpp @@ -12,6 +12,8 @@ void ofApp::setup() // You define the stage size and draw into the stage opcClient.setupStage(500, 500); + defaultEffects.setup(opcClient.getStageCenterX(), opcClient.getStageCenterY(), opcClient.getStageWidth(), opcClient.getStageHeight()); + // Setup the rings ring12px.setupLedRing(opcClient.getStageCenterX(),opcClient.getStageCenterY(), 12, 12); jewel.setupLedJewel(opcClient.getStageCenterX(),opcClient.getStageCenterY(), 28); @@ -24,13 +26,14 @@ void ofApp::setup() void ofApp::update() { ofSetWindowTitle("example_ofxNeoPixelRings"); + opcClient.update(); // Now Draw the effects to the stage opcClient.beginStage(); // Draw what you want rendered here // For now here are some default effects - opcClient.drawDefaultEffects(effect); + defaultEffects.draw(effect); opcClient.endStage(); @@ -55,7 +58,7 @@ void ofApp::update() opcClient.writeChannelFive(jewel.colorData()); } - opcClient.update(); + } //-------------------------------------------------------------- void ofApp::draw() diff --git a/example_ofxNeoPixelRings/src/ofApp.h b/example_ofxNeoPixelRings/src/ofApp.h index a949f86..8062c9c 100644 --- a/example_ofxNeoPixelRings/src/ofApp.h +++ b/example_ofxNeoPixelRings/src/ofApp.h @@ -18,9 +18,10 @@ class ofApp : public ofBaseApp{ ofxNeoPixelRing ring16px; ofxNeoPixelRing ring24px; ofxNeoPixelRing ring60px; - ofxNeoPixelJewel jewel; + Effects defaultEffects; + int effect; bool hide; }; diff --git a/example_ofxNeoPixelStrips/src/ofApp.cpp b/example_ofxNeoPixelStrips/src/ofApp.cpp index 35ff7e7..a43e569 100644 --- a/example_ofxNeoPixelStrips/src/ofApp.cpp +++ b/example_ofxNeoPixelStrips/src/ofApp.cpp @@ -12,6 +12,8 @@ void ofApp::setup() // You define the stage size and draw into the stage opcClient.setupStage(500, 500); + defaultEffects.setup(opcClient.getStageCenterX(), opcClient.getStageCenterY(), opcClient.getStageWidth(), opcClient.getStageHeight()); + stick.setupLedStrip(50, 50, 8, 7); strip40px.setupLedStrip(100,50, 40, 7); strip60px.setupLedStrip(150,50, 60, 7); @@ -22,13 +24,15 @@ void ofApp::update() { ofSetWindowTitle("example_ofxNeoPixelStrips"); + opcClient.update(); + // Now Draw the effects to the stage opcClient.beginStage(); // Draw what you want rendered here // For now here are some default effects - opcClient.drawDefaultEffects(effect); + defaultEffects.draw(effect); opcClient.endStage(); @@ -49,8 +53,6 @@ void ofApp::update() opcClient.writeChannelTwo(strip40px.colorData()); opcClient.writeChannelThree(strip60px.colorData()); } - - opcClient.update(); } //-------------------------------------------------------------- void ofApp::draw() diff --git a/example_ofxNeoPixelStrips/src/ofApp.h b/example_ofxNeoPixelStrips/src/ofApp.h index c5ac10b..7a55b33 100644 --- a/example_ofxNeoPixelStrips/src/ofApp.h +++ b/example_ofxNeoPixelStrips/src/ofApp.h @@ -19,6 +19,8 @@ class ofApp : public ofBaseApp{ ofxNeoPixelStrip strip60px; ofxNeoPixelStrip strip144px; + Effects defaultEffects; + int effect; bool hide; }; diff --git a/example_syphon_input/src/ofApp.cpp b/example_syphon_input/src/ofApp.cpp index 2c36414..3d2f0aa 100644 --- a/example_syphon_input/src/ofApp.cpp +++ b/example_syphon_input/src/ofApp.cpp @@ -14,6 +14,8 @@ void ofApp::setup() // You define the stage size and draw into the stage opcClient.setupStage(500, 500); + defaultEffects.setup(opcClient.getStageCenterX(), opcClient.getStageCenterY(), opcClient.getStageWidth(), opcClient.getStageHeight()); + //Construct the objects leftStrip.setupLedStrip(50, opcClient.getStageCenterY()-(30*5), 60, 5); rightStrip.setupLedStrip(opcClient.getStageWidth()-50, opcClient.getStageCenterY()-(30*5), 60, 5); @@ -22,8 +24,6 @@ void ofApp::setup() centerRing.setupLedRing(opcClient.getStageCenterX(), opcClient.getStageCenterY(), 60, 50); centerGrid.setupLedGrid(8, 8, opcClient.getStageCenterX()-(4*25)+(25/2), opcClient.getStageCenterY()-(4*25)+(25/2), 25); - - // Setup Syphon dir.setup(); ofAddListener(dir.events.serverAnnounced, this, &ofApp::serverAnnounced); @@ -38,6 +38,8 @@ void ofApp::update() { ofSetWindowTitle("example_syphon_input"); + opcClient.update(); + // Now Draw the effects to the stage opcClient.beginStage(); if (syphonActive) { @@ -47,7 +49,7 @@ void ofApp::update() syphonClient.draw(0, 0); } else { - opcClient.drawDefaultEffects(effect); + defaultEffects.draw(effect); } opcClient.endStage(); @@ -78,8 +80,6 @@ void ofApp::update() opcClient.writeChannelFive(rightStrip.colorData()); opcClient.writeChannelSix(centerGrid.colorData()); } - - opcClient.update(); } //-------------------------------------------------------------- void ofApp::draw() diff --git a/example_syphon_input/src/ofApp.h b/example_syphon_input/src/ofApp.h index 7c1d5ff..f6a0605 100644 --- a/example_syphon_input/src/ofApp.h +++ b/example_syphon_input/src/ofApp.h @@ -31,6 +31,8 @@ class ofApp : public ofBaseApp{ ofxNeoPixelRing rightRing; ofxNeoPixelGrid centerGrid; + Effects defaultEffects; + int effect; bool hide; bool syphonActive; diff --git a/src/ofxOPC.cpp b/src/ofxOPC.cpp index 01f36ec..b81778e 100644 --- a/src/ofxOPC.cpp +++ b/src/ofxOPC.cpp @@ -12,10 +12,9 @@ void ofxOPC::setup(string address, int port) _port = port; _address = address; - moveCounter = 0; + labels.load( "../../../resources/Verdana.ttf", 13); - dot.load("../../../resources/dot.png"); - ringImage.load("../../../resources/ring.png"); + connectionAttempts = 0; tryReconnecting = false; startTime = ofGetElapsedTimeMillis(); // get the start time @@ -47,29 +46,7 @@ void ofxOPC::setupStage(int width,int height) { _stageWidth = width; _stageHeight = height; - noiseImage.allocate(_stageWidth/4, _stageHeight/4, OF_IMAGE_GRAYSCALE); - colorFadeImage.allocate(_stageWidth/4, _stageHeight/4, OF_IMAGE_COLOR_ALPHA); - - ofSetCircleResolution(200); - for(int x = 0; x < noiseImage.getWidth(); x++) { - for(int y = 0; y < noiseImage.getHeight(); y++) { - ofColor initialColor = ofColor(255*ofNoise(x/100.0,y/100.0,ofGetElapsedTimef()),255); - noiseImage.setColor((int)(x+y*noiseImage.getWidth()), initialColor); - } - } - - pos_y = 0; - noiseImage.update(); - for(int y = 0; y < colorFadeImage.getHeight(); y++) { - for(int x = 0; x < colorFadeImage.getWidth(); x++) { - ofColor initialColor; - int value = 255*(float)x/colorFadeImage.getWidth(); - initialColor.setHsb(value, 200, 200); - colorFadeImage.setColor((int)(x+y*colorFadeImage.getWidth()), initialColor); - } - } - colorFadeImage.update(); screenPixels = new unsigned char [_stageWidth*_stageHeight*4]; screenCapture.allocate(_stageWidth, _stageHeight,GL_RGBA); screenCapture.begin(); @@ -411,281 +388,4 @@ void ofxOPC::disconnect() { client.close(); cleanup(); -} -//-------------------------------------------------------------- -void ofxOPC::drawDefaultEffects(int mode) -{ - switch (mode) { - case 0: - { - // Mouse Circle - ofPushStyle(); - float hue = fmodf(ofGetElapsedTimef()*10,255); - ofColor c = ofColor::fromHsb(hue, 255, 255); - ofSetColor(c); - ofDrawCircle(ofGetMouseX(),ofGetMouseY(),70); - ofPopStyle(); - } - break; - // Rotating Dots - case 1: - { - // Like the processing example draw dot images and rotate - int size = (_stageWidth+_stageHeight)/2; - ofPushMatrix(); - ofTranslate(0, 0); - ofPushMatrix(); - ofTranslate(getStageCenterX(),getStageCenterY()); - ofRotateZ(ofGetElapsedTimeMillis()/10); - ofPushMatrix(); - ofTranslate(-size,-size); - ofEnableBlendMode(OF_BLENDMODE_SCREEN); - ofSetColor(0, 255,20); - dot.draw(size/4, size/4, size,size); - ofSetColor(255, 0,20); - dot.draw((size/4*3), size/4, size,size); - ofSetColor(0, 0,255); - dot.draw(size/4, (size/4*3), size,size); - ofSetColor(255, 0,255); - dot.draw((size/4*3),(size/4*3), size,size); - ofDisableBlendMode(); - ofPopMatrix(); - ofPopMatrix(); - ofPopMatrix(); - } - break; - // Block Circle - case 2: - { - // Changes the color of a Circle - ofPushStyle(); - float hue = fmodf(ofGetElapsedTimef()*10,255); - ofColor c = ofColor::fromHsb(hue, 255, 255); - ofSetColor(c); - ofDrawRectangle(0,0,_stageWidth,_stageHeight); - ofPopStyle(); - } - break; - // Fade to White - case 3: - { - // Fade to full brightness then to zero - ofPushStyle(); - ofSetColor((int)(128 + 128 * sin(ofGetElapsedTimef()))); - ofDrawRectangle(0,0,_stageWidth,_stageHeight); - ofPopStyle(); - } - break; - // Rotating Circle - case 4: - { - ofEnableBlendMode(OF_BLENDMODE_ADD); - float rotationAmount = ofGetElapsedTimeMillis()/10; - ofSetColor(255, 0, 0); - ofPushMatrix(); - ofTranslate(getStageCenterX(), getStageCenterY()); - ofRotateZ(rotationAmount); - ofPushMatrix(); - ofTranslate(-getStageCenterX(), -getStageCenterY()); - ofDrawCircle(getStageCenterX(), getStageCenterY()-40, 40); - ofPopMatrix(); - ofPopMatrix(); - ofSetColor(0, 0, 255); - ofPushMatrix(); - ofTranslate(getStageCenterX(), getStageCenterY()); - ofRotateZ(-rotationAmount); - ofPushMatrix(); - ofTranslate(-getStageCenterX(), -getStageCenterY()); - ofDrawCircle(getStageCenterX(), getStageCenterY()+40, 40); - ofPopMatrix(); - ofPopMatrix(); - ofDisableBlendMode(); - } - break; - // Dot Image - case 5: - { - int w = 300; - int h = 300; - ofPushStyle(); - float hue = fmodf(ofGetElapsedTimef()*10,255); - ofColor c = ofColor::fromHsb(hue, 255, 255); - ofSetColor(c); - dot.draw(ofGetMouseX()-(w*0.5), ofGetMouseY()-(h*0.5), w,h); - ofPopStyle(); - } - break; - // Rotating Line - case 6: - { - float rotationAmount = ofGetElapsedTimeMillis()/5; - float hue = fmodf(ofGetElapsedTimef()*10,255); - ofColor c = ofColor::fromHsb(hue, 255, 255); - ofSetColor(c); - ofPushMatrix(); - ofTranslate(getStageCenterX(), getStageCenterY()); - ofRotateZ(rotationAmount); - ofPushMatrix(); - ofTranslate(-getStageCenterX(), -getStageCenterY()); - int w = (int)(28 + 128 * sin(ofGetElapsedTimef())); - ofDrawRectangle(getStageCenterX()-(w/2), getStageCenterY()-_stageHeight, w, _stageHeight*2); - ofPopMatrix(); - ofPopMatrix(); - } - break; - // Moving Text - case 7: - { - if (moveCounter < -labels.getStringBoundingBox("Hello World", 0, 0).width) { - moveCounter = _stageWidth; - } - else { - moveCounter--; - } - - float hue = fmodf(ofGetElapsedTimef()*10,255); - ofColor c = ofColor::fromHsb(hue, 255, 255); - ofSetColor(c); - ofPushMatrix(); - ofScale(4, 4); - ofTranslate(moveCounter, _stageHeight/8); - labels.drawString("Hello World", 0, 0); - ofPopMatrix(); - } - break; - // Noise Image - case 8: - { - for(int x = 0; x < noiseImage.getWidth(); x++) { - for(int y = 0; y < noiseImage.getHeight(); y++) { - ofColor initialColor = ofColor(255*ofNoise(x/100.0,y/100.0,ofGetElapsedTimef()),255); - noiseImage.setColor((int)(x+y*noiseImage.getWidth()), initialColor); - } - } - noiseImage.update(); - ofPushMatrix(); - ofScale(4, 4); - ofSetColor(255, 255, 255); - noiseImage.draw(0, 0); - ofPopMatrix(); - } - break; - // Wavefront - case 9: - { - float prevX = smoothX; - float prevY = smoothY; - smoothX += (ofGetMouseX() - smoothX) * 0.1; - smoothY += (ofGetMouseY() - smoothY) * 0.1; - - // At every frame, randomly respawn one ring - rings[int(ofRandom(100))].respawn(getStageHeight(),prevX, prevY, smoothX, smoothY); - - // Give each ring a chance to redraw and update - for (int i = 0; i < 100; i++) { - rings[i].draw(ringImage); - } - } - break; - // Color changing moving lines (horizontal) - case 10: - { - float hue = fmodf(ofGetElapsedTimef()*10,255); - ofColor c = ofColor::fromHsb(hue, 255, 255); - ofSetColor(c); - ofPushMatrix(); - int x = (int)(getStageWidth()/2 + getStageWidth()/2 * sin(ofGetElapsedTimef())); - int x1 = (int)(getStageWidth()/2 + getStageWidth()/2 * sin(ofGetElapsedTimef()*2)); - int x2 = (int)(getStageWidth()/2 + getStageWidth()/2 * sin(ofGetElapsedTimef()*4)); - int w = (int)(35 + 30 * sin(ofGetElapsedTimef()*0.6)); - ofDrawRectangle(x, getStageCenterY()-_stageHeight, w, _stageHeight*2); - ofDrawRectangle(x1, getStageCenterY()-_stageHeight, w, _stageHeight*2); - ofDrawRectangle(x2, getStageCenterY()-_stageHeight, w, _stageHeight*2); - ofPopMatrix(); - } - break; - // Color changing moving lines (vertical) - case 11: - { - float hue = fmodf(ofGetElapsedTimef()*10,255); - ofColor c = ofColor::fromHsb(hue, 255, 255); - ofSetColor(c); - ofPushMatrix(); - int y = (int)(getStageHeight()/2 + getStageHeight()/2 * sin(ofGetElapsedTimef())); - int y1 = (int)(getStageHeight()/2 + getStageHeight()/2 * sin(ofGetElapsedTimef()*2)); - int y2 = (int)(getStageHeight()/2 + getStageHeight()/2 * sin(ofGetElapsedTimef()*4)); - int h = (int)(35 + 30 * sin(ofGetElapsedTimef()*0.6)); - ofDrawRectangle(getStageCenterX()-(_stageWidth/2), y, _stageWidth, h); - ofDrawRectangle(getStageCenterX()-(_stageWidth/2), y1, _stageWidth, h); - ofDrawRectangle(getStageCenterX()-(_stageWidth/2), y2, _stageWidth, h); - ofPopMatrix(); - } - break; - // Horizontal Filling Box - case 12: - { - float hue = fmodf(ofGetElapsedTimef()*10,255); - ofColor c = ofColor::fromHsb(hue, 255, 255); - ofSetColor(c); - ofPushMatrix(); - int x = (int)(getStageWidth()/2 + getStageWidth()/2 * sin(ofGetElapsedTimef())); - int w = (int)(_stageWidth/2 + _stageWidth/2 * sin(ofGetElapsedTimef()*0.6)); - ofDrawRectangle(0, getStageCenterY()-_stageHeight, w, _stageHeight*2); - ofPopMatrix(); - } - break; - // Vertical Filling Box - case 13: - { - float hue = fmodf(ofGetElapsedTimef()*10,255); - ofColor c = ofColor::fromHsb(hue, 255, 255); - ofSetColor(c); - ofPushMatrix(); - int h = (int)(_stageHeight/2 + _stageHeight/2 * sin(ofGetElapsedTimef()*0.6)); - ofDrawRectangle(0, 0, _stageWidth, h); - ofPopMatrix(); - } - break; - // Color Scroll - case 14: - { - ofPushMatrix(); - ofPushStyle(); - ofEnableBlendMode(OF_BLENDMODE_ALPHA); - int linesInterval = getStageHeight()/2; - int step = 255/linesInterval; - int indents = getStageHeight()/linesInterval; - pos_y = int(ofGetElapsedTimef()*32); - for (int y = 0; y < getStageHeight(); y++) { - - ofColor c = ofColor::fromHsb((pos_y+y*step)%255, 255, 255); - ofSetColor(c); - ofDrawRectangle(0, y, _stageWidth, y); - } - ofDisableBlendMode(); - ofPopMatrix(); - ofPopStyle(); - } - break; - // Strobe - case 15: - { - ofPushMatrix(); - ofPushStyle(); - - int probability = 100-10; - if (ofRandom(0,100) > probability) { - ofSetColor(ofColor::white); - } - else { - ofSetColor(ofColor::black); - } - ofDrawRectangle(0, 0, getStageWidth(), getStageHeight()); - ofPopStyle(); - ofPopMatrix(); - } - break; - default: - break; - } -} +} \ No newline at end of file diff --git a/src/ofxOPC.h b/src/ofxOPC.h index e81c827..f96d2a8 100644 --- a/src/ofxOPC.h +++ b/src/ofxOPC.h @@ -5,58 +5,12 @@ // Created by David Haylock on 25/05/2014. // #include "ofMain.h" +#include "Effects.h" #include "ofxNetwork.h" #include "ofxNeoPixelStrip.h" #include "ofxNeoPixelRing.h" #include "ofxNeoPixelGrid.h" -class Ring { -public: - - Ring() {} - ~Ring() {} - - void respawn(int stageHeight,float x1,float y1,float x2,float y2) { - - _stageHeight = stageHeight; - // Start at the newer mouse position - x = x2; - y = y2; - - // Intensity is just the distance between mouse points - intensity = ofDist(x1, y1, x2, y2); - intensity = intensity * 2; - - // Hue is the angle of mouse movement, scaled from -PI..PI to 0..100 - hue = ofMap(atan2(y2 - y1, x2 - x1), -PI, PI, 0, 255); - - // Default size is based on the screen size - size = _stageHeight * 0.1; - } - - void draw(ofImage ringImage) { - ofPushStyle(); - // Particles fade each frame - intensity *= 0.95; - - // They grow at a rate based on their intensity - size += _stageHeight * intensity * 0.01; - - // If the particle is still alive, draw it - if (intensity >= 1) { - ofEnableBlendMode(OF_BLENDMODE_ADD); - ofColor c; - c.setHsb(hue, 200, intensity); - ofSetColor(c); - ringImage.draw(x - size/2, y - size/2, size,size); - ofDisableBlendMode(); - } - ofPopStyle(); - } -private: - float x, y, size, intensity, hue,_stageHeight; -}; - //------------------------------------------------------------------------------ typedef struct OPCPacket_Header { // Standard OPC-packet header @@ -92,8 +46,6 @@ class ofxOPC { void setup(string address,int port); void update(); void draw(); - void drawDefaultEffects(int mode); - ofImage dot; //! Set the FBOS Size void setupStage(int width, int height); @@ -154,29 +106,20 @@ class ofxOPC { vector error; int _port; int _w,_h; - int pos_y; private: ofTrueTypeFont labels; void connect(); void disconnect(); - int moveCounter; ofFbo screenCapture; int _stageWidth; int _stageHeight; unsigned char * screenPixels; - ofImage noiseImage; - ofImage colorFadeImage; - ofImage ringImage; - deque gloriousColor; // For sending our data packets out to the Server ofxTCPClient client; - Ring rings[100]; - float smoothX, smoothY; - // Reconnection Stuff float timer; bool tryReconnecting;