void Branch::draw() { ofPushStyle(); switch (drawMode) { case CL_BRANCH_DRAW_LEAVES: { ofFill(); ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofBeginShape(); for (auto p : positions) { ofSetColor(color); ofVertex(p->x, p->y); } ofEndShape(false); break; } case CL_BRANCH_DRAW_CIRCLES: { float alpha = ofMap(age, 0, ageOfDeath, 0, 150.0); float radius = ofMap(age, 0, ageOfDeath, 10.0f, 0.1f); ofFill(); ofSetColor(color, alpha); for (auto p : positions) { ofDrawCircle(p->x, p->y, radius); } break; } default : break; } ofPopStyle(); }
void TargetCursor::draw() { // Losange au bout, vecteur des 10 dernières coordonnées ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofBeginShape(); // Draw only if we have enough leftCoordinates if(leftCoordinates.size() >= 5) { for(int i = 0; i < leftCoordinates.size()-1; i++) ofLine(leftCoordinates.at(i)->x, leftCoordinates.at(i)->y, leftCoordinates.at(i+1)->x, leftCoordinates.at(i+1)->y); } ofEndShape(); ofBeginShape(); // Draw only if we have enough leftCoordinates if(rightCoordinates.size() >= 5) { for(int i = 0; i < rightCoordinates.size()-1; i++) ofLine(rightCoordinates.at(i)->x, rightCoordinates.at(i)->y, rightCoordinates.at(i+1)->x, rightCoordinates.at(i+1)->y); } ofEndShape(); }
void QuestionBox::drawShape() { ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofBeginShape(); ofVertex(bounds.x, bounds.y); if (_arrowPosition==1) { ofVertex(bounds.x + bounds.width/2-ARROW_SIZE, bounds.y); ofVertex(bounds.x + bounds.width/2, bounds.y-ARROW_SIZE); ofVertex(bounds.x + bounds.width/2+ARROW_SIZE, bounds.y); } ofVertex(bounds.x + bounds.width, bounds.y); ofVertex(bounds.x + bounds.width, bounds.y + bounds.height); if (_arrowPosition==0) { ofVertex(bounds.x + bounds.width/2+ARROW_SIZE, bounds.y + bounds.height); ofVertex(bounds.x + bounds.width/2, bounds.y+bounds.height+ARROW_SIZE); ofVertex(bounds.x + bounds.width/2-ARROW_SIZE, bounds.y+bounds.height); } ofVertex(bounds.x, bounds.y + bounds.height); ofEndShape(); }
//-------------------------------------------------------------- void ofApp::draw(){ string tempStr = "click to 's' to start music"; ofDrawBitmapString(tempStr, ofGetWindowWidth()-250,ofGetWindowHeight()-100); string temStr = "click to 'p' to pause music"; ofDrawBitmapString(temStr, ofGetWindowWidth()-250,ofGetWindowHeight()-75); string teStr = "click to 'r' to resume music"; ofDrawBitmapString(teStr, ofGetWindowWidth()-250,ofGetWindowHeight()-50); r = ofRandom(255); g = ofRandom(255); b = ofRandom(255); for(int i = 0; i<ofGetWindowHeight() && i<ofGetWindowWidth(); i+=100){ ofRotate(ang); ofSetColor(r, g, b, 150); ofRect(0, 0, ang+i, ang+i); ang++; } ofSetHexColor(0x0cb0b6); ofSetPolyMode(OF_POLY_WINDING_ODD); ofBeginShape(); for (int i = 0; i < 10; i++){ ofVertex(ofRandom(0,ofGetWindowHeight()), ofRandom(ofGetWidth(),0)); } ofEndShape(); }
//-------------------------------------------------------------- void testApp::setup(){ ofBackground(255); ofSetFrameRate(30); ofSetPolyMode(OF_POLY_WINDING_NONZERO); //research whoy enabling depth test creates artifacts int he lines, proibably we will ened ofMesh? glEnable(GL_DEPTH_TEST); land = Landscape(20,800,400); }
//---------------------------------------------------- void ofxCvCoordWarpingGui::draw(float passedX, float passedY, float scaleWidth, float scaleHeight, int red, int green, int blue, int thickness){ getScaledQuadPoints(scaleWidth, scaleHeight); ofPushMatrix(); ofPushStyle(); ofTranslate(passedX, passedY); ofNoFill(); ofSetColor(red, green, blue); ofSetLineWidth(thickness); ofBeginShape(); for(int i = 0; i < 4; i++){ ofVertex(srcScaled[i].x, srcScaled[i].y); } ofEndShape(true); ofFill(); glLineWidth(1); ofSetRectMode(OF_RECTMODE_CENTER); for(int i = 0; i < 4; i++){ if(i == 0)ofSetColor(255, 0, 0); if(i == 1)ofSetColor(0, 255, 0); if(i == 2)ofSetColor(255, 255, 0); if(i == 3)ofSetColor(0, 255, 255); ofRect(srcScaled[i].x, srcScaled[i].y, 8, 8); } ofSetRectMode(OF_RECTMODE_CORNER); ofFill(); ofSetColor(255,255,255,50); ofSetPolyMode(OF_POLY_WINDING_ODD); ofBeginShape(); ofVertex(0, 0); ofVertex(scaleWidth, 0); ofVertex(scaleWidth, scaleHeight); ofVertex(0, scaleHeight); ofVertex(0, 0); for(int i = 0; i < 4; i++){ ofVertex(srcScaled[i].x, srcScaled[i].y); } ofVertex(srcScaled[0].x+1, srcScaled[0].y+1); ofEndShape(); ofSetHexColor(0xffffff); ofPopStyle(); ofPopMatrix(); }
//-------------------------------------------------------------- void testApp::setup() { //ofBackground(0, 0, 0); ofBackground(255, 255, 255); //--------------------------------panel set up panel.setup("shader settings", 720, 0, 300, 748); panel.addPanel("shader", 1, false); panel.setWhichPanel("control"); panel.setWhichColumn(0); //panel.addSlider("LightPosition ", "LIGHTPOSITION", 1.648, 0.28, 1.0f, true); panel.addSlider("surfaceColorR", "SURFACECOLORR", 1.0f, 0.,5., true); panel.addSlider("surfaceColorG", "SURFACECOLORG", 1.0f, 0.,5., true); panel.addSlider("surfaceColorB", "SURFACECOLORB", 1.0f, 0.,5., true); panel.addSlider("surfaceColorE", "SURFACECOLORE", 1.0f, 0.,5., true); panel.addSlider("offset1","OFFSET1", -1.857f, -5.f, 5.f, true); panel.addSlider("offset2","OFFSET2", 100.5f, 50.f, 500.f, true); panel.addSlider("offset3","OFFSET3", 0.5f, -5.f, 100.f, true); panel.addSlider("scaleIn","SCALEIN", -5.873,-10,100, true); panel.addSlider("scaleOut","SCALEOUT", 10.f,0,800, true); panel.addSlider("Freq","FREQ",0.f, 0,200.f,true); panel.addSlider("Width","WIDTH",1.f,0,5,true); panel.addSlider("Width1","WIDTH1",400.f,0.,800.,true); panel.addSlider("Height","HEIGHT",400.f,0.,800.,true); panel.addSlider("StripeShift","STRIPESHIFT",100.f,50.f,200.f,true); panel.loadSettings("cvSettings.xml"); //-------------------------------- ofDisableArbTex(); ofEnableAlphaBlending(); ofSetFrameRate(30); ofSetPolyMode(OF_POLY_WINDING_POSITIVE); glEnable(GL_DEPTH_TEST); quadric = gluNewQuadric(); gluQuadricTexture(quadric, GL_TRUE); gluQuadricNormals(quadric, GLU_SMOOTH); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); shader.load("shaders/vnoise.vert", "shaders/vnoise.frag"); counter = 0; blendValue = 0; }
void SMUPentagon::display() { // fill shape ofSetColor(255, 100, 255); ofFill(); ofSetPolyMode(OF_POLY_WINDING_ODD); // normal mode ofBeginShape(); for(int i=0; i<5; i++){ ofVertex(loc.x + vecs[i].x, loc.y + vecs[i].y); } ofEndShape(OF_CLOSE); }
//-------------------------------------------------------------- void ofApp::setup() { ofBackground(0); ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofSetLineWidth(0.1); ofNoFill(); gui.setup(); // most of the time you don't need a name gui.add(stageSlider.setup("stage", 4, 1, 30)); gui.add(deltaSlider.setup("delta", 27, 1, 30)); gui.add(xSlider.setup("xPos", 716, 0, ofGetWidth())); gui.add(ySlider.setup("yPos", 44, 0, ofGetHeight())); hilbertCurve = new ofxHilbertCurve; font.loadFont("futura_book.otf", 11); }
void ofxPentagon::pentagon(float centerX, float centerY, float size) { float cos[] = {0.95105654, 0.5877853, -0.5877852, -0.95105654, 0}; float sin[] = {-0.309017, 0.809017, 0.809017, -0.30901697, -1}; float radius = size / 2; ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofNoFill(); ofBeginShape(); for(int i = 0; i < 5; i++){ float tx = cos[i] * radius + centerX; float ty = sin[i] * radius + centerY; ofVertex(tx, ty); } ofEndShape(); }
void GReaf::draw(){ ofRotateZ(rotZ); ofSetPolyMode(OF_POLY_WINDING_NONZERO); glPushMatrix(); ofSetColor(255, 255, 255); ofRotateZ(180); myImage.draw(0, 0, 100, reafTopMov); glImage.draw(0, 105, 50, reafTopMov+100); glPopMatrix(); // ofSetColor(213, 255, 155, 70); ofFill(); //ofSetLineWidth(1); //ofSetColor(0, 123, 80, 70); //ofNoFill(); ofSetLineWidth(6); ofBeginShape(); ofVertex(0, -105); ofBezierVertex(0, -105, reafLeftMov, -105, reafTopRLMov, reafTopMov); ofVertex(reafTopRLMov, reafTopMov); ofBezierVertex(reafTopRLMov, reafTopMov, reafRightMov, -105, 0, -105); ofEndShape(); // /* ofBeginShape(); ofVertex(0, -135); ofBezierVertex(0, -135, reafLeftMov, -135, reafTopRLMov, reafTopMov); ofVertex(reafTopRLMov, reafTopMov); ofBezierVertex(reafTopRLMov, reafTopMov, reafRightMov, -135, 0, -135); ofEndShape(); //ofNextContour();// ofBeginShape(); ofVertex(0, -135); ofBezierVertex(0, -135, (reafLeftMov+reafRightMov)/2, -135, reafTopRLMov, reafTopMov); ofVertex(reafTopRLMov, reafTopMov); ofBezierVertex(reafTopRLMov, reafTopMov, (reafLeftMov+reafRightMov)/2, -135, 0, -135); ofEndShape(); */ }
void TriParticle::draw(){ ofSetColor(color); ofPushMatrix(); ofTranslate(position); ofRotateX(rot.x); ofRotateY(rot.y); ofRotateZ(rot.z); ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofNoFill(); ofSetLineWidth(3); ofBeginShape(); ofScale(scale * 5.0, scale * 2.0); ofVertex(-1, -0.5); ofVertex(1, 0); ofVertex(-1, 0.5); ofEndShape(); ofFill(); ofSetLineWidth(1); ofPopMatrix(); }
void AppControls::draw(){ projectionControls.draw(); if (!btnHideVideoControls.getParameter().cast<bool>()) { videoControls.draw(); ct->rgb.draw(videoControls.getPosition().x, videoControls.getPosition().y + videoControls.getHeight() + 10); ofSetColor(255, 100, 100, 70); ofSetLineWidth(3); ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofBeginShape(); for (int i = 0; i < videoBounds.size(); i++) { ofVertex(videoControls.getPosition().x + videoBounds[i].x, videoControls.getPosition().y + videoControls.getHeight() + 10 + videoBounds[i].y); } ofEndShape(); ofSetColor(100, 255, 100); for (int i = 0; i < videoBounds.size(); i++) { ofCircle(videoControls.getPosition().x + videoBounds[i].x, videoControls.getPosition().y + videoControls.getHeight() + 10 + videoBounds[i].y, 3); } } }
//-------------------------------------------------------------- void testApp::draw(){ ofBackground(0); ofSetHexColor(0xffffff); bikers.draw(0, 0); quad1.beginDraw(); bikers.draw(0, 0); quad1.endDraw(); quad1.drawInputConfig(); quad1.drawOutputConfig(); fingerMovie.draw(510, 0); quad2.beginDraw(); fingerMovie.draw(510, 0); quad2.endDraw(); quad2.drawInputConfig(); quad2.drawOutputConfig(); ofSetHexColor(0x0cb0b6); ofSetPolyMode(OF_POLY_WINDING_ODD); ofBeginShape(); for (int i = 0; i < 10; i++){ ofVertex(ofRandom(850,1050), ofRandom(20,200)); } ofEndShape(); quad3.beginDraw(); ofBeginShape(); for (int i = 0; i < 10; i++){ ofVertex(ofRandom(850,1050), ofRandom(20,200)); } ofEndShape(); quad3.endDraw(); quad3.drawInputConfig(); quad3.drawOutputConfig(); }
//-------------------------------------------------------------- void ofApp::draw(){ ofBackground(255); ofNoFill(); ofSetColor(0x000000); ofRect(boxX, boxY, boxWidth, boxHeight); ofFill(); ofSetColor(0x000000); ofSetPolyMode(OF_POLY_WINDING_ODD); // this is the normal mode for(int i=4; i<25; i++){ ofBeginShape(); ofVertex(boxX,boxY); ofVertex(boxX+boxWidth,boxY+nZigZagsY); ofVertex(boxX,boxY+(boxHeight/2)); ofVertex(boxX+boxWidth,boxY+((boxHeight/4)*3)); ofVertex(boxX,boxY+boxHeight); ofVertex(boxX,boxY); ofVertex(boxX+(boxWidth/4),boxY+boxHeight); ofVertex(boxX+(boxWidth/2),boxY); ofVertex((boxX+(boxWidth/4)*3),boxY+boxHeight); ofVertex(boxX+boxWidth,boxY); ofEndShape(); } cout << nZigZagsY; }
void noiseBlob::draw(){ if (blob.size() == 0) return; ofPushStyle(); ofPushMatrix(); ofFill(); if (trFadeOutLastMaho) { if(c.r > 0)c.r--; if(c.g > 0)c.g--; if(c.b > 0)c.b--; if(c.r > 0)c.r--; if(c.g > 0)c.g--; if(c.b > 0)c.b--; if(c.r > 0)c.r--; if(c.g > 0)c.g--; if(c.b > 0)c.b--; if(c.r > 0)c.r--; if(c.g > 0)c.g--; if(c.b > 0)c.b--; } ofSetColor(c); ofSetPolyMode(OF_POLY_WINDING_ODD); ofBeginShape(); for (int i = 0; i < blob.size(); i++) { if (i % 2 == 0) continue; if (i == blob.size() - 1) { ofVertex(blob[i]); ofVertex(blob[0]); } else { ofVertex(blob[i]); } } ofEndShape(); ofPopMatrix(); ofPopStyle(); }
//-------------------------------------------------------------- void testApp::draw(){ ofSetPolyMode(OF_POLY_WINDING_ODD); //if we are smoothing the pts - might as well draw the line smooth too :) ofEnableSmoothing(); //if we are recording we just draw all points as a red line if(recording){ ofSetColor(255, 50, 50); ofNoFill(); ofBeginShape(); for( unsigned int i = 0; i < ptsList.size(); i++){ ofVertex(ptsList[i].x, ptsList[i].y); } ofEndShape(false); }else{ ofSetColor(255, 255, 255); float max = MIN(1, playPos); int drawTo = max * (float)ptsList.size(); // Drawing with GL triangle strips // // glBegin(GL_TRIANGLE_STRIP); // for(int i = 0; i < drawTo; i++){ // ofxVec2f pt1; // pt1 = ptsList[i] + leftNormals[i] * speedList[i] * 2; // // ofxVec2f pt2; // pt2 = ptsList[i] + rightNormals[i] * speedList[i] * 2; // // glVertex2f(pt1.x, pt1.y); // glVertex2f(pt2.x, pt2.y); // } // glEnd(); //For Evan Roth Style Rotating Stroke glTranslated(ofGetWidth()/2, ofGetHeight()/2, 0); glRotatef( -20 * ( ofGetElapsedTimef()-storeTime), 0, 1, 0); float midX = ofGetWidth()/2; float midY = ofGetHeight()/2; //float speed = 2; ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofFill(); ofBeginShape(); for(int i = 0; i < drawTo; i++){ ofxVec2f pt; pt = ptsList[i] + leftNormals[i] * speedList[i]; ofVertex(pt.x-midX, pt.y-midY); } for(int i = drawTo-1; i >= 0; i--){ ofxVec2f pt; pt = ptsList[i] + rightNormals[i] * speedList[i]; ofVertex(pt.x-midX, pt.y-midY); } ofEndShape(false); } }
//---------------------------------------------------------------------------------- void ofxCvBlobFinder::draw(float x, float y, float w, float h) { // draw blobs //ofxCvContourFinder::draw(x, y, w, h); // scale blob float scalex = 0.0f; float scaley = 0.0f; if (_width != 0) { scalex = w / _width; } else { scalex = 1.0f; } if (_height != 0) { scaley = h / _height; } else { scaley = 1.0f; } ofSetPolyMode(OF_POLY_WINDING_NONZERO); // apply transformation glPushMatrix(); glTranslatef(x, y, 0.0); glScalef(scalex, scaley, 0.0); #define DRAW_BLOB_VECTOR(points) do{ \ ofBeginShape(); \ for(int i = 0; i < (points).size(); i++){ \ ofVertex((points[i]).x, (points[i]).y); \ } \ ofEndShape(true); \ } while(0) ofNoFill(); for (int j = 0; j < blobz.size(); j++) { ofSetColor(0xFF0000); DRAW_BLOB_VECTOR( blobz[j].getPoints()); ofSetColor(0x00FF00); DRAW_BLOB_VECTOR(blobz[j].getHullPoints()); ofSetColor(0x0000FF); DRAW_BLOB_VECTOR( blobz[j].getApproxPoints()); ofSetColor(0x00ffae); ofRectangle c = blobz[j].getBoundingBox(); ostringstream s; s << j << "Area = " << blobz[j].getArea(); ofDrawBitmapString(s.str(), c.x, c.y); ofRect(c.x, c.y, c.width, c.height); } glPopMatrix(); }
//-------------------------------------------------------------- void testApp::setup() { ofSetLogLevel(OF_LOG_VERBOSE); ofEnableAlphaBlending(); ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofTrueTypeFont::setGlobalDpi(72); font.loadFont("GUI/dinnextroundedltprolight.ttf", 28, true, true); // enable depth->rgb image calibration kinect.setRegistration(true); //kinect.init(); //kinect.init(true); // shows infrared instead of RGB video image kinect.init(false, false); // disable video image (faster fps) kinect.open(); angle=kinect.getCurrentCameraTiltAngle(); //kinect.setCameraTiltAngle(angle); //ofSleepMillis(1000); kinect.enableDepthNearValueWhite(true); ofAddListener(blob2DTracker.blobAdded, this, &testApp::blob2DAdded); ofAddListener(blob2DTracker.blobMoved, this, &testApp::blob2DMoved); ofAddListener(blob2DTracker.blobDeleted, this, &testApp::blob2DDeleted); blobFinder.init(&kinect, true); // standarized coordinate system: z in the direction of gravity blobFinder.setResolution(BF_LOW_RES); blobFinder.setRotation( ofVec3f( angle, 0, 0) ); blobFinder.setTranslation(ofVec3f(0,0,0)); blobFinder.setScale(ofVec3f(0.001, 0.001, 0.001)); // mm to meters // bind our kinect to the blob finder // in order to do this we need to declare in testApp.h: class testApp : public ofBaseApp, public ofxKinectBlobListener blobTracker.setListener( this ); blobImage.allocate(kinect.width, kinect.height, OF_IMAGE_GRAYSCALE); background.allocate(kinect.width, kinect.height, OF_IMAGE_GRAYSCALE); backgroundTex.allocate(kinect.width, kinect.height);//,OF_IMAGE_GRAYSCALE); inPainter.setup(kinect.width, kinect.height); tmpMapMask = new unsigned char[kinect.width*kinect.height]; tmpZonesMask = new unsigned char[kinect.width*kinect.height]; nearThreshold=10000.; farThreshold=10000.; diffThreshold=100.; maxBlobs = 10; minBlobPoints=250; maxBlobPoints=1000000; // NOTE: measurement units in meters!!! minBlobVol = 0.02f; maxBlobVol = 2.0f; damping=10.; mass=1.; K=30.; /*zonesCols=3; zonesRows=3; zonesColSpacing=20; zonesRowSpacing=20;*/ dilate=10; erode=10; getPitchAndRoll=false; pitch=0.; roll=0.; mapPoint=0; mapFbo.allocate(kinect.width,kinect.height); mapPixels.allocate(kinect.width,kinect.height,OF_IMAGE_GRAYSCALE); mapMask.allocate(kinect.width, kinect.height); zonesDistance=10.; zonesFbo.allocate(kinect.width,kinect.height); gui = new ofxUISuperCanvas("kinectMap", OFX_UI_FONT_MEDIUM); gui->addSpacer(); gui->addTextArea("CONTROL", "Control de parametros de kinectMap"); gui->addSpacer(); gui->addSlider("angle", -30, 30, &angle); gui->addLabelToggle("learnBackground", &learnBackground); gui->addSlider("backFrames", 0.0, BACKGROUND_FRAMES, &backFrames); gui->addSpacer(); gui->addSlider("maxBlobs", 0, 20, &maxBlobs); gui->addSlider("min blob points", 0, 2000, &minBlobPoints); gui->addSlider("min blob vol", 0.0, 0.2, &minBlobVol); gui->addSlider("max blob vol", 1., 10., &maxBlobVol); gui->addSpacer(); gui->addRangeSlider("near and far threshold", 0., 5000., &nearThreshold,&farThreshold); gui->addSlider("diff threshold", 0., 1000., &diffThreshold); gui->addSpacer(); gui->addSlider("person damping", 0., 10., &damping); gui->addSlider("person mass", 1., 10., &mass); gui->addSlider("person K", 1., 30., &K); gui->addSpacer(); gui->addLabelToggle("get pitch and roll",&getPitchAndRoll); gui->addSlider("pitch", -180., 180., &pitch); gui->addSlider("roll", -180., 180., &roll); gui->addSpacer(); gui->addLabelToggle("mapOpen", &mapOpen); gui->addSpacer(); gui->addLabelButton("zonesNew", &zonesNew); gui->addLabelButton("zonesClear", &zonesClear); gui->addSpacer(); gui->addSlider("dilate", 0, 20, &dilate); gui->addSlider("erode", 0, 20, &erode); gui->autoSizeToFitWidgets(); ofAddListener(gui->newGUIEvent,this,&testApp::guiEvent); if(ofFile::doesFileExist("GUI/guiSettings.xml")) gui->loadSettings("GUI/guiSettings.xml"); loadMap(); loadZones(); sender.setup(IP,PORT); mapOpen=false; zonesNew=false; zonesClear=false; rotation.makeRotationMatrix(-90-pitch,ofVec3f(1,0,0),0,ofVec3f(0,1,0),-roll,ofVec3f(0,0,1)); learnBackground = true; backFrames=0.; ofSetFrameRate(60); }
void Ball::Draw(float sizem){ int size = sizem+_size; ofSetColor(_color); if(_point == 2){ ofDrawCircle(_x, _y, size); } else if(_point == 3){ ofDrawTriangle(_x+size, _y+size, _x-size, _y+size, _x, _y-size); }else if(_point==4){ ofDrawRectangle(_x-(size/2), _y-(size/2), size, size); }else if(_point==5){ ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofBeginShape(); ofVertex((_x + size * cos(1 * 2 * PI / 5)), (_y + size * sin(1 * 2 * PI / 5))); ofVertex((_x + size * cos(2 * 2 * PI / 5)), (_y + size * sin(2 * 2 * PI / 5))); ofVertex((_x + size * cos(3 * 2 * PI / 5)), (_y + size * sin(3 * 2 * PI / 5))); ofVertex((_x + size * cos(4 * 2 * PI / 5)), (_y + size * sin(4 * 2 * PI / 5))); ofVertex((_x + size * cos(5 * 2 * PI / 5)), (_y + size * sin(5 * 2 * PI / 5))); ofEndShape(); }else if(_point==6){ ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofBeginShape(); ofVertex((_x + size * cos(1 * 2 * PI / 6)), (_y + size * sin(1 * 2 * PI / 6))); ofVertex((_x + size * cos(2 * 2 * PI / 6)), (_y + size * sin(2 * 2 * PI / 6))); ofVertex((_x + size * cos(3 * 2 * PI / 6)), (_y + size * sin(3 * 2 * PI / 6))); ofVertex((_x + size * cos(4 * 2 * PI / 6)), (_y + size * sin(4 * 2 * PI / 6))); ofVertex((_x + size * cos(5 * 2 * PI / 6)), (_y + size * sin(5 * 2 * PI / 6))); ofVertex((_x + size * cos(6 * 2 * PI / 6)), (_y + size * sin(6 * 2 * PI / 6))); ofEndShape(); }else if(_point==7){ ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofBeginShape(); ofVertex((_x + size * cos(1 * 2 * PI / 7)), (_y + size * sin(1 * 2 * PI / 7))); ofVertex((_x + size * cos(2 * 2 * PI / 7)), (_y + size * sin(2 * 2 * PI / 7))); ofVertex((_x + size * cos(3 * 2 * PI / 7)), (_y + size * sin(3 * 2 * PI / 7))); ofVertex((_x + size * cos(4 * 2 * PI / 7)), (_y + size * sin(4 * 2 * PI / 7))); ofVertex((_x + size * cos(5 * 2 * PI / 7)), (_y + size * sin(5 * 2 * PI / 7))); ofVertex((_x + size * cos(6 * 2 * PI / 7)), (_y + size * sin(6 * 2 * PI / 7))); ofVertex((_x + size * cos(7 * 2 * PI / 7)), (_y + size * sin(7 * 2 * PI / 7))); ofEndShape(); }else if(_point==8){ ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofBeginShape(); ofVertex((_x + size * cos(1 * 2 * PI / 8)), (_y + size * sin(1 * 2 * PI / 8))); ofVertex((_x + size * cos(2 * 2 * PI / 8)), (_y + size * sin(2 * 2 * PI / 8))); ofVertex((_x + size * cos(3 * 2 * PI / 8)), (_y + size * sin(3 * 2 * PI / 8))); ofVertex((_x + size * cos(4 * 2 * PI / 8)), (_y + size * sin(4 * 2 * PI / 8))); ofVertex((_x + size * cos(5 * 2 * PI / 8)), (_y + size * sin(5 * 2 * PI / 8))); ofVertex((_x + size * cos(6 * 2 * PI / 8)), (_y + size * sin(6 * 2 * PI / 8))); ofVertex((_x + size * cos(7 * 2 * PI / 8)), (_y + size * sin(7 * 2 * PI / 8))); ofVertex((_x + size * cos(8 * 2 * PI / 8)), (_y + size * sin(8 * 2 * PI / 8))); ofEndShape(); } }
//-------------------------------------------------------------- void ofApp::draw(){ //Merci Ludo pour ton aide currentFrame = vidGrabber.getPixelsRef(); currentFrameCopy.allocate(currentFrame.getWidth(), currentFrame.getHeight(), OF_IMAGE_GRAYSCALE); for(int x=0 ; x < 256 ; x++) { histogram[x] = 0; } for (int i = 0; i < camWidth; i++){ for (int j = 0; j < camHeight; j++){ int lightness = currentFrame.getColor(i,j).getLightness(); histogram[lightness] = histogram[lightness]+1; ofColor pixel; pixel.set(lightness, lightness, lightness); currentFrame.setColor(i, j, pixel); } } ofSetHexColor(0xffffff); currentFrame.reloadTexture(); currentFrame.draw(0,0); ofFill(); ofSetHexColor(0x000000); ofSetPolyMode(OF_POLY_WINDING_ODD); ofLine(770, 400, 770, 400-255); ofLine(770, 400, 770+255, 400); histogramMax = 0; maxIndex = 0; for(int x = 0 ; x < 256 ; x++) { if (histogram[x]>histogramMax) { histogramMax = histogram[x]; maxIndex = x; } histogram[x] = histogram[x]/100; //cout << x << " : " << histogram[x] << "\n"; ofLine(x+770, 400-histogram[x], x+770, 400); } ofSetColor(255,0,0); ofLine(maxIndex+770, 400-histogram[maxIndex], maxIndex+770, 400); ofSetColor(0); ofDrawBitmapString("Histogram : ", 770, 100); ofDrawBitmapString("0 255 ", 770, 415); ofDrawBitmapString("0", 755, 400); ofDrawBitmapString("???", 773, 150); threshold = 128; for(int y = 0; y < camHeight; y++) { for(int x = 0; x < camWidth; x++) { ofColor cur = currentFrame.getColor(x, y); int lightness = cur.getLightness(); ofColor pixel; if (lightness<threshold) pixel.set(0, 0, 0); else pixel.set(255, 255, 255); currentFrameCopy.setColor(x, y, pixel); } } ofSetColor(255); currentFrameCopy.reloadTexture(); currentFrameCopy.draw(0, 480); }
void Groove::draw(){ ofSetColor(50); ofFill(); ofSetSphereResolution(20); ofDrawSphere(0, 0, disc->origin); for(int i = 0; i < disc->getDiscIndex(); i++){ //rotate disc->setRotation(i, disc->getRotationSpeed(i)); if(turn) ofRotate(disc->getRotation(i), 0, 0, 1); else ofRotate(disc->getRotation(i), 0, 0, 1); mesh[i].draw(); //draw circles ofSetLineWidth(3); ofNoFill(); ofColor fillColor = 50; if( i != me->getDiscIndex() && disc->isMute(i) == 1) fillColor = ofColor::lightGrey; if( otherPlayers.size() > 0){ for (int j = 0; j < otherPlayers.size(); j++) { if( i == otherPlayers[j]->getDiscIndex() && disc->isMute(otherPlayers[j]->getDiscIndex()) == 0) fillColor = otherPlayers[j]->getColor(); else if( i == otherPlayers[j]->getDiscIndex() && disc->isMute(otherPlayers[j]->getDiscIndex()) == 1){ ofColor pale = otherPlayers[j]->getColor(); pale.setSaturation(pale.getSaturation() - 110); fillColor = pale; } } } if( i == me->getDiscIndex() && disc->isMute(me->getDiscIndex()) == 0) fillColor = me->getColor(); if( i == me->getDiscIndex() && disc->isMute(me->getDiscIndex()) == 1) { ofColor pale = me->getColor(); pale.setSaturation(pale.getSaturation() - 110); fillColor = pale; } ofSetColor(fillColor); ofSetCircleResolution(70); //front ofCircle(0,0,disc->getPosition(i), disc->getRadius(i-1)); ofCircle(0,0,disc->getPosition(i), disc->getRadius(i)); //back ofCircle(0,0,disc->getPosition(i)-.2, disc->getRadius(i-1)); ofCircle(0,0,disc->getPosition(i)-.2, disc->getRadius(i)); ofFill(); //get texture type and draw switch(disc->getTexture(i)){ case 0: //blank break; case 1: //line for(int a = 0; a < 360; a++){ if(fmodf(a, disc->getDensity(i)) == 0){ double spikePoint = (disc->getRadius(i)+disc->getRadius(i-1))/2; ofPoint p1, p2, p3; ofPoint rp1, rp2, rp3; p1.set(disc->getRadius(i-1)*cos(a*PI/180) , //x1 disc->getRadius(i-1)*sin(a*PI/180), //y1 disc->getPosition(i)); p2.set(disc->getRadius(i)*cos(a*PI/180), //x2 disc->getRadius(i)*sin(a*PI/180), //y2 disc->getPosition(i)); p3.set(spikePoint*cos(a*PI/180), spikePoint*sin(a*PI/180), disc->getPosition(i)+ disc->getSpikeDistance(i)); rp1.set(p1.x, p1.y, p1.z-flipsideDist); rp2.set(p2.x, p2.y, p2.z-flipsideDist); rp3.set(p3.x, p3.y, p3.z-(flipsideDist+2*disc->getSpikeDistance(i))); ofLine(p1,p2); //reverse ofLine(rp1,rp2); if(disc->getSpikeDistance(i) != 0){ ofSetColor(fillColor, 70); ofBeginShape(); ofVertex(p1); ofVertex(p3); ofVertex(p2); ofEndShape(); ofBeginShape(); ofVertex(rp1); ofVertex(rp3); ofVertex(rp2); ofEndShape(); ofSetColor(fillColor, 255); } } } break; case 2: //triangle for(int a = 0; a < 360; a++){ if(fmodf(a, disc->getDensity(i)) == 0){ //spike locted at center of gravity double spikePoint = (disc->getRadius(i-1)+(disc->getRadius(i)-disc->getRadius(i-1))/3); ofPoint p1, p2, p3, p4, p5; p1.set(disc->getRadius(i-1)*cos((a - disc->getDensity(i))*PI/180), disc->getRadius(i-1)*sin((a - disc->getDensity(i))*PI/180), disc->getPosition(i)); p2.set(disc->getRadius(i-1)*cos((a - disc->getDensity(i)/2)*PI/180), disc->getRadius(i-1)*sin((a - disc->getDensity(i)/2)*PI/180), disc->getPosition(i)); p3.set(disc->getRadius(i-1)*cos(a*PI/180), disc->getRadius(i-1)*sin(a*PI/180), disc->getPosition(i)); p4.set(disc->getRadius(i)*cos((a - disc->getDensity(i)/2)*PI/180), disc->getRadius(i)*sin((a - disc->getDensity(i)/2)*PI/180), disc->getPosition(i)); p5.set(spikePoint*cos((a - disc->getDensity(i)/2)*PI/180), spikePoint*sin((a - disc->getDensity(i)/2)*PI/180), disc->getPosition(i) + disc->getSpikeDistance(i)); ofPoint rp1, rp2, rp3, rp4, rp5; rp1.set(p1.x, p1.y, p1.z-flipsideDist); rp2.set(p2.x, p2.y, p2.z-flipsideDist); rp3.set(p3.x, p3.y, p3.z-flipsideDist); rp4.set(p4.x, p4.y, p4.z-flipsideDist); rp5.set(p5.x, p5.y, p5.z-(flipsideDist+2*disc->getSpikeDistance(i))); ofSetPolyMode(OF_POLY_WINDING_ODD); ofFill(); ofBeginShape(); //base ofVertex(p1); ofVertex(p2); ofVertex(p3); ofVertex(p4); ofEndShape(); //reverse ofBeginShape(); //base ofVertex(rp1); ofVertex(rp2); ofVertex(rp3); ofVertex(rp4); ofEndShape(); if(disc->getSpikeDistance(i) != 0){ ofSetColor(fillColor, 70); ofBeginShape(); //spike ofVertex(p4); ofVertex(p5); ofVertex(p3); ofEndShape(); ofBeginShape(); //spike ofVertex(p4); ofVertex(p5); ofVertex(p1); ofEndShape(); ofBeginShape(); //spike ofVertex(rp4); ofVertex(rp5); ofVertex(rp3); ofEndShape(); ofBeginShape(); //spike ofVertex(rp4); ofVertex(rp5); ofVertex(rp1); ofEndShape(); ofSetColor(fillColor, 255); } } } break; case 3: //saw for(int a = 0; a < 360; a++){ if(fmodf(a, disc->getDensity(i)) == 0){ //spike locted at center of gravity double spikePoint = (disc->getRadius(i-1)+(disc->getRadius(i)-disc->getRadius(i-1))/3); ofPoint p1, p2, p3, p4, p5; p1.set(disc->getRadius(i)*cos((a - disc->getDensity(i))*PI/180), disc->getRadius(i)*sin((a - disc->getDensity(i))*PI/180), disc->getPosition(i)); p2.set(disc->getRadius(i)*cos((a - disc->getDensity(i)/2)*PI/180), disc->getRadius(i)*sin((a - disc->getDensity(i)/2)*PI/180), disc->getPosition(i)); p3.set(disc->getRadius(i)*cos(a*PI/180), disc->getRadius(i)*sin(a*PI/180), disc->getPosition(i)); p4.set(disc->getRadius(i-1)*cos((a - disc->getDensity(i))*PI/180), disc->getRadius(i-1)*sin((a - disc->getDensity(i))*PI/180), disc->getPosition(i)); p5.set(spikePoint*cos((a - 2*disc->getDensity(i)/3)*PI/180), spikePoint*sin((a - 2*disc->getDensity(i)/3)*PI/180), disc->getPosition(i) + disc->getSpikeDistance(i)); ofPoint rp1, rp2, rp3, rp4, rp5; rp1.set(p1.x, p1.y, p1.z-flipsideDist); rp2.set(p2.x, p2.y, p2.z-flipsideDist); rp3.set(p3.x, p3.y, p3.z-flipsideDist); rp4.set(p4.x, p4.y, p4.z-flipsideDist); rp5.set(p5.x, p5.y, p5.z-(flipsideDist+2*disc->getSpikeDistance(i))); ofSetPolyMode(OF_POLY_WINDING_ODD); ofFill(); ofBeginShape(); //base ofVertex(p1); ofVertex(p2); ofVertex(p3); ofVertex(p4); ofEndShape(); //reverse ofBeginShape(); //base ofVertex(rp1); ofVertex(rp2); ofVertex(rp3); ofVertex(rp4); ofEndShape(); if(disc->getSpikeDistance(i) != 0){ ofSetColor(fillColor, 70); ofBeginShape(); //spike ofVertex(p4); ofVertex(p5); ofVertex(p3); ofEndShape(); ofBeginShape(); //spike ofVertex(p4); ofVertex(p5); ofVertex(p1); ofEndShape(); ofBeginShape(); //spike ofVertex(rp4); ofVertex(rp5); ofVertex(rp3); ofEndShape(); ofBeginShape(); //spike ofVertex(rp4); ofVertex(rp5); ofVertex(rp1); ofEndShape(); ofSetColor(fillColor, 255); } } } break; { case 4: //rectangle bool space = false; for(int a = 0; a < 360; a++){ if(space == false && fmodf(a, disc->getDensity(i)) == 0){ //spike locted at center of gravity double spikePoint = (disc->getRadius(i)+disc->getRadius(i-1))/2; ofPoint p1, p2, p3, p4, p5, p6, p7; p1.set(disc->getRadius(i-1)*cos((a - disc->getDensity(i))*PI/180), disc->getRadius(i-1)*sin((a - disc->getDensity(i))*PI/180), disc->getPosition(i)); p2.set(disc->getRadius(i-1)*cos((a - disc->getDensity(i)/2)*PI/180), disc->getRadius(i-1)*sin((a - disc->getDensity(i)/2)*PI/180), disc->getPosition(i)); p3.set(disc->getRadius(i-1)*cos(a*PI/180), disc->getRadius(i-1)*sin(a*PI/180), disc->getPosition(i)); p4.set(disc->getRadius(i)*cos(a*PI/180), disc->getRadius(i)*sin(a*PI/180), disc->getPosition(i)); p5.set(disc->getRadius(i)*cos((a - disc->getDensity(i)/2)*PI/180), disc->getRadius(i)*sin((a - disc->getDensity(i)/2)*PI/180), disc->getPosition(i)); p6.set(disc->getRadius(i)*cos((a - disc->getDensity(i))*PI/180), disc->getRadius(i)*sin((a - disc->getDensity(i))*PI/180), disc->getPosition(i)); p7.set(spikePoint*cos((a - disc->getDensity(i)/2)*PI/180), spikePoint*sin((a - disc->getDensity(i)/2)*PI/180), disc->getPosition(i) + disc->getSpikeDistance(i)); ofPoint rp1, rp2, rp3, rp4, rp5, rp6, rp7; rp1.set(p1.x, p1.y, p1.z-flipsideDist); rp2.set(p2.x, p2.y, p2.z-flipsideDist); rp3.set(p3.x, p3.y, p3.z-flipsideDist); rp4.set(p4.x, p4.y, p4.z-flipsideDist); rp5.set(p5.x, p5.y, p5.z-flipsideDist); rp6.set(p6.x, p6.y, p6.z-flipsideDist); rp7.set(p7.x, p7.y, p7.z-(flipsideDist+2*disc->getSpikeDistance(i))); ofSetPolyMode(OF_POLY_WINDING_ODD); ofFill(); ofBeginShape(); //base ofVertex(p1); ofVertex(p2); ofVertex(p3); ofVertex(p4); ofVertex(p5); ofVertex(p6); ofEndShape(); //reverse ofBeginShape(); //base ofVertex(rp1); ofVertex(rp2); ofVertex(rp3); ofVertex(rp4); ofVertex(rp5); ofVertex(rp6); ofEndShape(); if(disc->getSpikeDistance(i) != 0){ ofSetColor(fillColor, 70); ofBeginShape(); //spike ofVertex(p6); ofVertex(p7); ofVertex(p4); ofEndShape(); ofBeginShape(); ofVertex(p6); ofVertex(p7); ofVertex(p1); ofEndShape(); ofBeginShape(); ofVertex(p4); ofVertex(p7); ofVertex(p3); ofEndShape(); ofBeginShape(); //spike ofVertex(rp6); ofVertex(rp7); ofVertex(rp4); ofEndShape(); ofBeginShape(); ofVertex(rp6); ofVertex(rp7); ofVertex(rp1); ofEndShape(); ofBeginShape(); ofVertex(rp4); ofVertex(rp7); ofVertex(rp3); ofEndShape(); ofSetColor(fillColor, 255); } space = true; } else if (space == true && fmodf(a, disc->getDensity(i)) == 0) space = false; } break; } default: //something something break; } } }
//---------------------------------------------------------------------------------- void ofxCvBlobFinder::draw(float x, float y, float w, float h) { // draw blobs //ofxCvContourFinder::draw(x, y, w, h); // scale blob float scalex = 0.0f; float scaley = 0.0f; if (_width != 0) { scalex = w / _width; } else { scalex = 1.0f; } if (_height != 0) { scaley = h / _height; } else { scaley = 1.0f; } ofSetPolyMode(OF_POLY_WINDING_NONZERO); // apply transformation glPushMatrix(); glTranslatef(x, y, 0.0); glScalef(scalex, scaley, 0.0); #define DRAW_BLOB_VECTOR(points) do{ \ ofBeginShape(); \ for(int i = 0; i < (points).size(); i++){ \ ofVertex((points[i]).x, (points[i]).y); \ } \ ofEndShape(true); \ } while(0) ofNoFill(); for (int j = 0; j < blobz.size(); j++) { ofSetHexColor(0xFF0000); DRAW_BLOB_VECTOR( blobz[j].getPoints()); ofSetHexColor(0x00FF00); DRAW_BLOB_VECTOR(blobz[j].getHullPoints()); ofSetHexColor(0x0000FF); DRAW_BLOB_VECTOR( blobz[j].getApproxPoints()); ofSetHexColor(0x00ffae); ofRectangle c = blobz[j].getBoundingBox(); // draw bounding box ostringstream s; s << j << "Area = " << blobz[j].getArea(); ofDrawBitmapString(s.str(), c.x, c.y + 50); ofRect(c.x, c.y, c.width, c.height); // get convexity defects vector<ofxCvConvexityDefect> cd = blobz[j].getConvexityDefects(); ofSetHexColor(0x00effe); for(int i=0; i < cd.size(); i++){ ofLine(cd[i].start.x, cd[i].start.y, cd[i].end.x, cd[i].end.y); ofCircle(cd[i].defect.x, cd[i].defect.y, 2); float angle = atan2f( ( (float) (cd[i].end.y - cd[i].start.y) ) , ( (float) (cd[i].end.x - cd[i].start.x))); float x = cd[i].defect.x - sinf(angle) * cd[i].length; float y = cd[i].defect.y + cosf(angle) * cd[i].length; ofSetHexColor(0xF0F0F0); ofLine(cd[i].defect.x, cd[i].defect.y, x, y); } } for (int k = 0; k < blobParams.size(); k++){ ofDrawBitmapString("Blob:" + ofToString(blobParams[k].id), blobParams[k].position); } glPopMatrix(); }
//-------------------------------------------------------------- void testApp::draw(){ ofSetColor(255, 255, 255); ofPushMatrix(); // draw debug (ie., image, depth, skeleton) openNIDevice.drawDebug(); ofPopMatrix(); ofPushMatrix(); // use a blend mode so we can see 'through' the mask(s) ofEnableBlendMode(OF_BLENDMODE_ALPHA); // get number of current users int numUsers = openNIDevice.getNumTrackedUsers(); // iterate through users for (int i = 0; i < numUsers; i++){ // get a reference to this user ofxOpenNIUser & user = openNIDevice.getTrackedUser(i); // draw the mask texture for this user user.drawMask(); // get joint position head = user.getJoint(JOINT_HEAD).getProjectivePosition(); leftHand = user.getJoint(JOINT_LEFT_HAND).getProjectivePosition(); rightHand = user.getJoint(JOINT_RIGHT_HAND).getProjectivePosition(); leftFoot = user.getJoint(JOINT_LEFT_FOOT).getProjectivePosition(); rightFoot = user.getJoint(JOINT_RIGHT_FOOT).getProjectivePosition(); torso = user.getJoint(JOINT_TORSO).getProjectivePosition(); // OSC stuff m.setAddress("/nodes"); m.addIntArg(head.x); m.addIntArg(head.y); m.addIntArg(leftHand.x); m.addIntArg(leftHand.y); m.addIntArg(rightHand.x); m.addIntArg(rightHand.y); m.addIntArg(leftFoot.x); m.addIntArg(leftFoot.y); m.addIntArg(rightFoot.x); m.addIntArg(rightFoot.y); sender.sendMessage(m); // array_head.push_back(head); // array_leftFoot.push_back(leftFoot); // array_leftHand.push_back(leftHand); // array_rightFoot.push_back(rightFoot); // array_rightHand.push_back(rightHand); // array_torso.push_back(torso); // // if(array_head.size() > array_size) { // array_head.erase(array_head.begin()); // } // // if(array_leftHand.size() > array_size) { // array_leftHand.erase(array_leftHand.begin()); // } // // if(array_leftFoot.size() > array_size) { // array_leftFoot.erase(array_leftFoot.begin()); // } // // if(array_rightFoot.size() > array_size) { // array_rightFoot.erase(array_rightFoot.begin()); // } // // if(array_rightHand.size() > array_size) { // array_rightHand.erase(array_rightHand.begin()); // } // if(array_torso.size() > array_size) { // array_torso.erase(array_torso.begin()); // } // you can also access the pixel and texture references individually: // TEXTURE REFERENCE //ofTexture & tex = user.getMaskTextureReference(); // do something with texture... // PIXEL REFERENCE //ofPixels & pix = user.getMaskPixels(); // do something with the pixels... // and point clouds: ofPushMatrix(); // move it a bit more central ofTranslate(320, 240, 10); user.drawPointCloud(); // you can also access the mesh: // MESH REFERENCE //ofMesh & mesh = user.getPointCloud(); // do something with the point cloud mesh ofPopMatrix(); } ofDisableBlendMode(); ofPopMatrix(); // draw some info regarding frame counts etc // ofSetColor(0, 255, 0); // string msg = " MILLIS: " + ofToString(ofGetElapsedTimeMillis()) + " FPS: " + ofToString(ofGetFrameRate()) + " Device FPS: " + ofToString(openNIDevice.getFrameRate()); // // verdana.drawString(msg, 20, openNIDevice.getNumDevices() * 480 - 20); //ofSetColor(leftHand.y,torso.x/10,rightHand.y*20); // draw the ploy circle(sh) // ofBeginShape(); // // for (int i = 0; i <6; i++){ // // if (i == 0){ // ofCurveVertex(leftFoot.x,leftFoot.y); // we need to duplicate 0 for the curve to start at point 0 // ofCurveVertex(leftHand.x,leftHand.y); // we need to duplicate 0 for the curve to start at point 0 // } else if (i == 5){ // ofCurveVertex(head.x,head.y); // ofCurveVertex(torso.x, torso.y); // to draw a curve from pt 6 to pt 0 // ofCurveVertex(rightHand.x,rightHand.y); // we duplicate the first point twice // }else { // ofCurveVertex(rightFoot.x,rightHand.y); // } // // } // // ofEndShape(); //SH group adding parts~ ofSetColor(leftHand.y,torso.x,rightHand.y*2); //ofSetColor(255, 255, 255); //ofRect(0, 0,1000, 1000); bg.draw(-200, 0); ofSetColor(255,255,255); ofSetLineWidth(3); ofLine(leftHand.x+10, leftHand.y+10, head.x+10, head.y+10); ofLine(head.x+20, head.y+10, rightHand.x+10, rightHand.y+15); ofLine(rightHand.x+8, rightHand.y+10, rightFoot.x+20, rightFoot.y+10); ofLine(rightFoot.x, rightFoot.y, leftFoot.x, leftFoot.y); ofLine(leftFoot.x,leftFoot.y, leftHand.x, leftHand.y); ofSetColor(255,255,255); ofCircle(leftHand.x+20, leftHand.y+20,10); ofCircle(rightHand.x+10, rightHand.y+10,6); ofSetColor(leftHand.y,torso.x/10,rightHand.y*20); ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofBeginShape(); ofVertex(leftFoot.x,leftFoot.y); ofVertex(leftHand.x,leftHand.y); ofVertex(head.x,head.y); ofVertex(rightHand.x,rightHand.y); ofVertex(rightFoot.x,rightFoot.y); ofEndShape(); // for(int i=0; i<array_head.size();i++) { // if(i > 1) { // ofLine(array_head[i-1].x, array_head[i-1].y, array_head[i].x, array_head[i].y); // } // } // for(int i=0; i<array_leftFoot.size();i++) { // if(i > 1) { // ofLine(array_leftFoot[i-1].x, array_leftFoot[i-1].y, array_leftFoot[i].x, array_leftFoot[i].y); // } // } // for(int i=0; i<array_rightFoot.size();i++) { // if(i > 1) { // ofLine(array_rightFoot[i-1].x, array_rightFoot[i-1].y, array_rightFoot[i].x, array_rightFoot[i].y); // } // } // for(int i=0; i<array_leftHand.size();i++) { // if(i > 1) { // ofLine(array_leftHand[i-1].x, array_leftHand[i-1].y, array_leftHand[i].x, array_leftHand[i].y); // } // } // for(int i=0; i<array_rightHand.size();i++) { // if(i > 1) { // ofLine(array_rightHand[i-1].x, array_rightHand[i-1].y, array_rightHand[i].x, array_rightHand[i].y); // } // } // for(int i=0; i<array_torso.size();i++) { // if(i > 1) { // ofLine(array_torso[i-1].x, array_torso[i-1].y, array_torso[i].x, array_torso[i].y); // } // } //// // for (int i=1;i<60 ; i+=10) { // CX=i+40; // CY=i; // ofCircle(CX, CY, 20); // } // CX=ofRandom(50,400); // CY=ofRandom(0,600); // ofCircle(40 ,80, 20); //ofSetColor(100); ofCircle(100, 100, 20); ofCircle(250, 100, 20); ofCircle(400, 100, 20); a=rightHand.y; b=head.y; c=leftHand.y; if (abs(a-b<10)) { la.play(); } if (abs(c-b<10)) { so.play(); } if (abs(leftHand.x-100)<10&&abs(leftHand.y-100)<10) { Do.play(); } if (abs(leftHand.x-250)<10&&abs(leftHand.y-100)<10) { re.play(); } if (abs(leftHand.x-400)<10&&abs(leftHand.y-100)<10) { Mi.play(); } if (abs(rightHand.x-100)<10&&abs(rightHand.y-100)<10) { Do.play(); } if (abs(rightHand.x-250)<10&&abs(rightHand.y-100)<10) { re.play(); } if (abs(rightHand.x-400)<10&&abs(rightHand.y-100)<10) { Mi.play(); } }
//-------------------------------------------------------------- void testApp::draw(){ ofFill(); ofSetHexColor(0xe0be21); //------(a)-------------------------------------- // // draw a star // // use poly winding odd, the default rule // // info about the winding rules is here: // http://glprogramming.com/red/images/Image128.gif // ofSetPolyMode(OF_POLY_WINDING_ODD); // this is the normal mode ofBeginShape(); ofVertex(200,135); ofVertex(15,135); ofVertex(165,25); ofVertex(105,200); ofVertex(50,25); ofEndShape(); //------(b)-------------------------------------- // // draw a star // // use poly winding nonzero // // info about the winding rules is here: // http://glprogramming.com/red/images/Image128.gif // ofSetHexColor(0xb5de10); ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofBeginShape(); ofVertex(400,135); ofVertex(215,135); ofVertex(365,25); ofVertex(305,200); ofVertex(250,25); ofEndShape(); //------------------------------------- //------(c)-------------------------------------- // // draw a star dynamically // // use the mouse position as a pct // to calc nPoints and internal point radius // float xPct = (float)(mouseX) / (float)(ofGetWidth()); float yPct = (float)(mouseY) / (float)(ofGetHeight()); int nTips = 5 + xPct * 60; int nStarPts = nTips * 2; float angleChangePerPt = TWO_PI / (float)nStarPts; float innerRadius = 0 + yPct*80; float outerRadius = 80; float origx = 525; float origy = 100; float angle = 0; ofSetHexColor(0xa16bca); ofBeginShape(); for (int i = 0; i < nStarPts; i++){ if (i % 2 == 0) { // inside point: float x = origx + innerRadius * cos(angle); float y = origy + innerRadius * sin(angle); ofVertex(x,y); } else { // outside point float x = origx + outerRadius * cos(angle); float y = origy + outerRadius * sin(angle); ofVertex(x,y); } angle += angleChangePerPt; } ofEndShape(); //------------------------------------- //------(d)-------------------------------------- // // poylgon of random points // // lots of self intersection, 500 pts is a good stress test // // ofSetHexColor(0x0cb0b6); ofSetPolyMode(OF_POLY_WINDING_ODD); ofBeginShape(); for (int i = 0; i < 10; i++){ ofVertex(ofRandom(650,850), ofRandom(20,200)); } ofEndShape(); //------------------------------------- //------(e)-------------------------------------- // // use sin cos and time to make some spirally shape // glPushMatrix(); glTranslatef(100,300,0); ofSetHexColor(0xff2220); ofFill(); ofSetPolyMode(OF_POLY_WINDING_ODD); ofBeginShape(); float angleStep = TWO_PI/(100.0f + sin(ofGetElapsedTimef()/5.0f) * 60); float radiusAdder = 0.5f; float radius = 0; for (int i = 0; i < 200; i++){ float anglef = (i) * angleStep; float x = radius * cos(anglef); float y = radius * sin(anglef); ofVertex(x,y); radius += radiusAdder; } ofEndShape(OF_CLOSE); glPopMatrix(); //------------------------------------- //------(f)-------------------------------------- // // ofCurveVertex // // because it uses catmul rom splines, we need to repeat the first and last // items so the curve actually goes through those points // ofSetHexColor(0x2bdbe6); ofBeginShape(); for (int i = 0; i < nCurveVertexes; i++){ // sorry about all the if/states here, but to do catmull rom curves // we need to duplicate the start and end points so the curve acutally // goes through them. // for i == 0, we just call the vertex twice // for i == nCurveVertexes-1 (last point) we call vertex 0 twice // otherwise just normal ofCurveVertex call if (i == 0){ ofCurveVertex(curveVertices[0].x, curveVertices[0].y); // we need to duplicate 0 for the curve to start at point 0 ofCurveVertex(curveVertices[0].x, curveVertices[0].y); // we need to duplicate 0 for the curve to start at point 0 } else if (i == nCurveVertexes-1){ ofCurveVertex(curveVertices[i].x, curveVertices[i].y); ofCurveVertex(curveVertices[0].x, curveVertices[0].y); // to draw a curve from pt 6 to pt 0 ofCurveVertex(curveVertices[0].x, curveVertices[0].y); // we duplicate the first point twice } else { ofCurveVertex(curveVertices[i].x, curveVertices[i].y); } } ofEndShape(); // show a faint the non-curve version of the same polygon: ofEnableAlphaBlending(); ofNoFill(); ofSetColor(0,0,0,40); ofBeginShape(); for (int i = 0; i < nCurveVertexes; i++){ ofVertex(curveVertices[i].x, curveVertices[i].y); } ofEndShape(true); ofSetColor(0,0,0,80); for (int i = 0; i < nCurveVertexes; i++){ if (curveVertices[i].bOver == true) ofFill(); else ofNoFill(); ofCircle(curveVertices[i].x, curveVertices[i].y,4); } ofDisableAlphaBlending(); //------------------------------------- //------(g)-------------------------------------- // // ofBezierVertex // // with ofBezierVertex we can draw a curve from the current vertex // through the the next three vertexes we pass in. // (two control points and the final bezier point) // float x0 = 500; float y0 = 300; float x1 = 550+50*cos(ofGetElapsedTimef()*1.0f); float y1 = 300+100*sin(ofGetElapsedTimef()/3.5f); float x2 = 600+30*cos(ofGetElapsedTimef()*2.0f); float y2 = 300+100*sin(ofGetElapsedTimef()); float x3 = 650; float y3 = 300; ofFill(); ofSetHexColor(0xFF9933); ofBeginShape(); ofVertex(x0,y0); ofBezierVertex(x1,y1,x2,y2,x3,y3); ofEndShape(); ofEnableAlphaBlending(); ofFill(); ofSetColor(0,0,0,40); ofCircle(x0,y0,4); ofCircle(x1,y1,4); ofCircle(x2,y2,4); ofCircle(x3,y3,4); ofDisableAlphaBlending(); //------(h)-------------------------------------- // // holes / ofNextContour // // with ofNextContour we can create multi-contour shapes // this allows us to draw holes, for example... // ofFill(); ofSetHexColor(0xd3ffd3); ofRect(80,480,140,70); ofSetHexColor(0xff00ff); ofBeginShape(); ofVertex(100,500); ofVertex(180,550); ofVertex(100,600); ofNextContour(true); ofVertex(120,520); ofVertex(160,550); ofVertex(120,580); ofEndShape(true); //------------------------------------- //------(i)-------------------------------------- // // CSG / ofNextContour // // with different winding rules, you can even use ofNextContour to // perform constructive solid geometry // // be careful, the clockwiseness or counter clockwisenss of your multiple // contours matters with these winding rules. // // for csg ideas, see : http://glprogramming.com/red/chapter11.html // // info about the winding rules is here: // http://glprogramming.com/red/images/Image128.gif // ofNoFill(); glPushMatrix(); ofSetPolyMode(OF_POLY_WINDING_ODD); ofBeginShape(); ofVertex(300,500); ofVertex(380,550); ofVertex(300,600); ofNextContour(true); for (int i = 0; i < 20; i++){ float anglef = ((float)i / 19.0f) * TWO_PI; float x = 340 + 30 * cos(anglef); float y = 550 + 30 * sin(anglef); ofVertex(x,y); radius += radiusAdder; } ofEndShape(true); glTranslatef(100,0,0); ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofBeginShape(); ofVertex(300,500); ofVertex(380,550); ofVertex(300,600); ofNextContour(true); for (int i = 0; i < 20; i++){ float anglef = ((float)i / 19.0f) * TWO_PI; float x = 340 + 30 * cos(anglef); float y = 550 + 30 * sin(anglef); ofVertex(x,y); radius += radiusAdder; } ofEndShape(true); glTranslatef(100,0,0); ofSetPolyMode(OF_POLY_WINDING_ABS_GEQ_TWO); ofBeginShape(); ofVertex(300,500); ofVertex(380,550); ofVertex(300,600); ofNextContour(true); for (int i = 0; i < 20; i++){ float anglef = ((float)i / 19.0f) * TWO_PI; float x = 340 + 30 * cos(anglef); float y = 550 + 30 * sin(anglef); ofVertex(x,y); radius += radiusAdder; } ofEndShape(true); glPopMatrix(); //------------------------------------- ofSetHexColor(0x000000); ofDrawBitmapString("(a) star\nwinding rule odd", 20,210); ofSetHexColor(0x000000); ofDrawBitmapString("(b) star\nwinding rule nonzero", 220,210); ofSetHexColor(0x000000); ofDrawBitmapString("(c) dynamically\ncreated shape", 420,210); ofSetHexColor(0x000000); ofDrawBitmapString("(d) random points\npoly", 670,210); ofSetHexColor(0x000000); ofDrawBitmapString("(e) fun with sin/cos", 20,410); ofSetHexColor(0x000000); ofDrawBitmapString("(f) ofCurveVertex\nuses catmull rom\nto make curved shapes", 220,410); ofSetHexColor(0x000000); ofDrawBitmapString("(g) ofBezierVertex\nuses bezier to draw curves", 460,410); ofSetHexColor(0x000000); ofDrawBitmapString("(h) ofNextContour\nallows for holes", 20,610); ofSetHexColor(0x000000); ofDrawBitmapString("(i) ofNextContour\ncan even be used for CSG operations\nsuch as union and intersection", 260,620); }
//-------------------------------------------------------------- void ofApp::draw() { //drawTile( 1, 4, 8 ); //for( auto iter = tileset->GetTiles().begin(); iter != tileset->GetTiles().end(); iter++ ) // Iterate through the layers. for (int i = 0; i < map->GetNumLayers(); ++i) { const Tmx::Layer *layer = map->GetLayer(i); for (int y = 0; y < layer->GetHeight(); ++y) { for (int x = 0; x < layer->GetWidth(); ++x) { drawTile( i, layer, x, y ); } } } // Iterate through all of the object groups. for (int i = 0; i < map->GetNumObjectGroups(); ++i) { // Get an object group. const Tmx::ObjectGroup *objectGroup = map->GetObjectGroup(i); // Iterate through all objects in the object group. for (int j = 0; j < objectGroup->GetNumObjects(); ++j) { // Get an object. const Tmx::Object *object = objectGroup->GetObject(j); // Print information about the object. printf("Object Name: %s\n", object->GetName().c_str()); printf("Object Position: (%03d, %03d)\n", object->GetX(), object->GetY()); printf("Object Size: (%03d, %03d)\n", object->GetWidth(), object->GetHeight()); ofPushMatrix(); ofTranslate(object->GetX(), object->GetY()); ofPushStyle(); ofNoFill(); ofSetColor(255,0,0); ofSetPolyMode(OF_POLY_WINDING_ODD); // this is the normal mode // Print Polygon points. const Tmx::Polygon *polygon = object->GetPolygon(); if (polygon != 0) { ofBeginShape(); for (int i = 0; i < polygon->GetNumPoints(); i++) { const Tmx::Point &point = polygon->GetPoint(i); ofVertex(point.x, point.y); } ofEndShape(); } // Print Polyline points. const Tmx::Polyline *polyline = object->GetPolyline(); if (polyline != 0) { ofBeginShape(); for (int i = 0; i < polyline->GetNumPoints(); i++) { const Tmx::Point &point = polyline->GetPoint(i); ofVertex(point.x, point.y); } ofEndShape(); } ofPopStyle(); ofPopMatrix(); } } }
//-------------------------------------------------------------- void testApp::setup() { ofEnableAlphaBlending(); ofSetPolyMode(OF_POLY_WINDING_NONZERO); ofSetLogLevel(OF_LOG_VERBOSE); // enable depth->rgb image calibration kinect.setRegistration(true); //kinect.init(); //kinect.init(true); // shows infrared instead of RGB video image kinect.init(false, false); // disable video image (faster fps) kinect.open(); angle=-30; kinect.setCameraTiltAngle(angle); //ofSleepMillis(1000); kinect.enableDepthNearValueWhite(true); ofAddListener(touchTracker.blobAdded, this, &testApp::touchOn); ofAddListener(touchTracker.blobMoved, this, &testApp::touchMoved); ofAddListener(touchTracker.blobDeleted, this, &testApp::touchOff); background.allocate(kinect.width, kinect.height, OF_IMAGE_GRAYSCALE); backgroundTex.allocate(kinect.width,kinect.height);//,OF_IMAGE_GRAYSCALE); diffMask.allocate(kinect.width, kinect.height); thresMask.allocate(kinect.width, kinect.height); nearThreshold=560.; farThreshold=880.; touchDiffFarThreshold=120.; touchDiffNearThreshold=7.; numPixels = kinect.width*kinect.height; maxBlobs = 10; minBlobPoints=0; maxBlobPoints=1000000; bLearnBackground = true; backFrames=0; marksOpen=false; fboZones.allocate(kinect.width,kinect.height); zoneID=0; zones.allocate(kinect.width,kinect.height); t=100; for(int i=0;i<SOUNDS;i++) { stringstream name; name << "sounds/" << i << ".wav"; sounds[i].loadSound(name.str()); sounds[i].setVolume(0.75f); sounds[i].setMultiPlay(true); } ready=false; ofSetFrameRate(60); }