コード例 #1
0
ファイル: testApp.cpp プロジェクト: kashimAstro/springBall
void testApp::draw(){
    ofBackgroundGradient(ofColor(0,0,0),ofColor(40,40,40));
    ofNoFill();
    ofSetColor(255,255,255);
    mesh.draw();
    ofFill();
    for (int i = 0; i < balls.size(); i++) {
        balls[i].draw();
    }
}
コード例 #2
0
//--------------------------------------------------------------
void testApp::draw(){
  // draw radius
  for (unsigned int i = 0; i < path.size()-1; i++){
      ofVec2f start = path[i];
      ofVec2f end = path[i+1];
      ofBeginShape();
      ofFill();
      ofSetColor(200);
      ofVec2f normal = (end - start).getRotated(90).getNormalized()*radius;
      ofVertex(start.x + normal.x, start.y + normal.y);
      ofVertex(start.x + normal.getRotated(180).x, start.y + normal.getRotated(180).y);
      ofVertex(end.x + normal.getRotated(180).x, end.y + normal.getRotated(180).y);
      ofVertex(end.x + normal.x, end.y + normal.y);
      ofEndShape(true);
  }
  ofSetColor(0);
  path.draw();

  for (unsigned int i = 0; i < vehicles.size(); i++){
    vehicles[i].draw(isDebugMode);
  }
  ofDrawBitmapString("Hit space bar to toggle debugging lines.\nClick the mouse to generate a new path.",10,ofGetHeight()-30);
}
コード例 #3
0
ファイル: curvedSquare.cpp プロジェクト: imclab/LaserShow
void curvedSquare::draw(){
    ofSetColor(255,0,0);
    myPoly.draw();
}
コード例 #4
0
ファイル: main.cpp プロジェクト: SAIC-ATS/ARTTECH-5010
void draw() 
{
    ofSetColor(255);

    // A few helper variables for layout.
    int hw = width / 2;  // Half width
    int hh = height / 2; // Half height.
    int qw = width / 4;  // Quarter width.
    int qh = height / 4; // Quarter height.
    int lx = 14; // Label offset x.
    int ly = 20; // Label offset y.

    grayscaleImage.draw(0, 0, qw, qh);
    ofDrawBitmapStringHighlight("0. Grayscale", lx, ly);
    
    grayscaleBackgroundImage.draw(qw, 0, qw, qh);
    ofDrawBitmapStringHighlight("1. Background\n   (spacebar)", lx + qw, ly);


	grayscaleAbsoluteDifference.draw(0, qh, qw, qh);
    ofDrawBitmapStringHighlight("2. Grayscale - Background", lx, ly + qh);


	grayscaleBinary.draw(qw, qh, qw, qh);
    ofDrawBitmapStringHighlight("3. Threshold " + ofToString(threshold) + "\n   (-/+: change threshold)\n   (  i: invert)", lx + qw, ly + qh);

    // Here we use ofPushMatrix(), ... to scale all of the contours and bounding boxes.
    ofPushStyle();
    ofPushMatrix();
    ofTranslate(hw, 0);
    ofScale(0.5, 0.5, 1);
    grayscaleBinary.draw(0, 0);
    contourFinder.draw(); // Draw all of the contours and their bounding boxes. 
    
    // Draw our line.
    ofSetColor(ofColor::yellow);
    holePositions.draw();
    ofPopMatrix();
    ofDrawBitmapStringHighlight("4. Contours and Bounding Boxes\n   Draw a yellow line to follow\n   the center of the largest blob.", lx + hw, ly);
    ofPopStyle();
  
    colorImage.draw(0, 0);//, hw, hh);
    // ofDrawBitmapStringHighlight("5. Original", lx, ly + hh);
    
    for (int i = 0; i < contourFinder.nBlobs; ++i)
    {
        ofPolyline contour(contourFinder.blobs[i].pts);
        
        // Resample to reduce the resolution.
        contour = contour.getResampledBySpacing(5);
        
        float interpolatedIndex = offset * contour.size();
        
        ofPoint position = contour.getPointAtIndexInterpolated(interpolatedIndex); 
        ofPoint normal = contour.getNormalAtIndexInterpolated(interpolatedIndex); 
        
        // Make a line pointing normal to the contour.
        ofPoint lineEnd = position - normal * 30;
        
        ofSetColor(ofColor::yellow);
        contour.draw();
            
        ofLine(position, lineEnd);
        ofCircle(lineEnd, 2);
        
    }
    
    
}
コード例 #5
0
ファイル: ofApp.cpp プロジェクト: 2bbb/openFrameworks
//--------------------------------------------------------------
void ofApp::draw(){
    if(poly.size() < 2) return;
    
    ofPushMatrix();
    ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
    ofRotateY(rotAngle);
    
    ofSetColor(255, 255, 255);
    poly.draw();
    
    ofSetColor(0, 255, 0);
    ofSetRectMode(OF_RECTMODE_CENTER);
    glPointSize(5);
    glBegin(GL_POINTS);
    for(int i=0; i<poly.size(); i++) {
        ofPoint p = poly[i];
        glVertex3f(p.x, p.y, p.z);
    }
    glEnd();
    
    for(int i=0; i<poly.size(); i++) {
        ofPoint p = poly[i];
        ofSetColor(255, 0, 0);
        ofLine(p, p + poly.getTangentAtIndex(i) * 20);
        
        ofSetColor(0, 255, 0);
        ofLine(p, p + poly.getNormalAtIndex(i) * 20);
        
        ofSetColor(0, 128, 255);
        ofLine(p, p + poly.getRotationAtIndex(i) * 20);
    }
    
    
    
    float totalLength = poly.getPerimeter();
    float totalArea = poly.getArea();
    ofPoint nearestPoint = poly.getClosestPoint(ofPoint(mouseX-ofGetWidth()/2, mouseY-ofGetHeight()/2), &nearestIndex);
    ofPoint nearestDataPoint = poly[nearestIndex];
    float lengthAtIndex = poly.getLengthAtIndex(nearestIndex);
    ofPoint pointAtIndex = poly.getPointAtIndexInterpolated(nearestIndex);
    ofPoint pointAtLength = poly.getPointAtLength(lengthAtIndex);
    ofPoint pointAtPercent = poly.getPointAtPercent(lengthAtIndex / totalLength);
    float indexAtLength = poly.getIndexAtLength(lengthAtIndex);
    
    float sinTime = ofMap(sin(ofGetElapsedTimef() * 0.5), -1, 1, 0, 1);
    float sinIndex = sinTime * (poly.isClosed() ? poly.size() : (poly.size()-1));  // sinTime mapped to indices direct
    float sinIndexLength = poly.getIndexAtPercent(sinTime); // sinTime mapped to indices based on length
    
    float lengthAtIndexSin = poly.getLengthAtIndexInterpolated(sinIndex);
    ofPoint pointAtIndexSin = poly.getPointAtIndexInterpolated(sinIndex);
    ofPoint pointAtPercentSin = poly.getPointAtPercent(sinTime);
    
    float angleAtIndex = poly.getAngleAtIndex(nearestIndex);
    float angleAtIndexSin = poly.getAngleAtIndexInterpolated(sinIndex);
    
    ofVec3f rotAtIndex = poly.getRotationAtIndex(nearestIndex);
    ofVec3f rotAtIndexSin = poly.getRotationAtIndexInterpolated(sinIndex);
    
    float rotMagAtIndex = rotAtIndex.length();
    float rotMagAtIndexSin = rotAtIndexSin.length();
    
    ofVec3f normalAtIndex = poly.getNormalAtIndex(nearestIndex);
    
    ofVec3f tangentAtIndexSin = poly.getTangentAtIndexInterpolated(sinIndex);
    ofVec3f normalAtIndexSin = poly.getNormalAtIndexInterpolated(sinIndex);
    ofVec3f rotationAtIndexSin = poly.getRotationAtIndexInterpolated(sinIndex);
    
    
    ofNoFill();
    ofSetLineWidth(2);
    
    ofSetColor(255, 0, 0);
    ofCircle(nearestPoint, 5);
    
    ofSetColor(255, 255, 0);
    ofCircle(nearestDataPoint, 7);
    
    // interpolating on indices
    {
        ofPoint p = poly.getPointAtIndexInterpolated(sinIndex);

        ofSetColor(0, 255, 255);
        ofCircle(p, 10);
        
        ofSetColor(255, 0, 0);
        ofLine(p, p + poly.getTangentAtIndexInterpolated(sinIndex) * 60);
        
        ofSetColor(0, 255, 0);
        ofLine(p, p + poly.getNormalAtIndexInterpolated(sinIndex) * 60);
        
        ofSetColor(0, 128, 255);
        ofLine(p, p + poly.getRotationAtIndexInterpolated(sinIndex) * 60);
    }
    
    // interpolating on length percentages
    {
        ofPoint p = poly.getPointAtIndexInterpolated(sinIndexLength);
        
        ofSetColor(255, 0, 255);
        ofCircle(p, 10);
        
        ofSetColor(255, 0, 0);
        ofLine(p, p + poly.getTangentAtIndexInterpolated(sinIndexLength) * 60);
        
        ofSetColor(0, 255, 0);
        ofLine(p, p + poly.getNormalAtIndexInterpolated(sinIndexLength) * 60);
        
        ofSetColor(0, 128, 255);
        ofLine(p, p + poly.getRotationAtIndexInterpolated(sinIndexLength) * 60);
    }
    
    
    ofSetColor(255, 255, 255);
    ofCircle(poly.getCentroid2D(), 20);
    
    ofPopMatrix();
    
    
    stringstream s;
    s << "Number of points: " << poly.size() << endl;
    s << "totalLength: " << totalLength << endl;
    
    s << endl;
    s << "nearestIndex: " << nearestIndex << endl;
    s << "nearestPoint: " << nearestPoint << endl;
    s << "nearestDataPoint: " << nearestDataPoint << endl;
    
    s << endl;
    s << "lengthAtIndex: " << lengthAtIndex << endl;
    s << "pointAtIndex: " << pointAtIndex << endl;
    
    s << endl;
    s << "pointAtLength: " << pointAtLength << endl;
    s << "pointAtPercent: " << pointAtPercent << endl;
    
    s << endl;
    s << "indexAtLength: " << indexAtLength << endl;
    
    
    s << endl;
    s << "sinTime: " << sinTime << endl;
    s << "sinIndex: " << sinIndex << endl;
    s << "sinIndexLength: " << sinIndexLength << endl;
    
    s << endl;
    s << "lengthAtIndexSin: " << lengthAtIndexSin << endl;
    s << "pointAtIndexSin: " << pointAtIndexSin << endl;
    s << "pointAtPercentSin: " << pointAtPercentSin << endl;
    
    s << endl;
    s << "angleAtIndex: " << angleAtIndex << endl;
    s << "angleAtIndexSin: " << angleAtIndexSin << endl;
    
    s << endl;
    s << "rotAtIndex: " << rotAtIndex << endl;
    s << "rotAtIndexSin: " << rotAtIndexSin << endl;
    
    s << endl;
    s << "rotMagAtIndex: " << rotMagAtIndex << endl;
    s << "rotMagAtIndexSin: " << rotMagAtIndexSin << endl;
    
    s << endl;
    s << "normalAtIndex: " << normalAtIndex << endl;
    s << "normalAtIndexSin: " << normalAtIndexSin << endl;
    
    ofSetColor(255);
    ofDrawBitmapString(s.str(), 10, 30);
}