void Plant::draw() { if (active) { ofSetColor(0, 200*(ofRandom(0.8, 1.2)), 100*(ofRandom(0.8,1.2))); ofCurve(x, y, x1, y1, x2, y2, x3, y3); } else ofCurve(0, 0, 0, 0, 0, 0, 0, 0); }
//-------------------------------------------------------------- void testApp::draw(){ for (int i=0; i<shapes.size(); i++){ if (showShape) { ofNoFill(); shapes[i].draw(); } else if (showNet) { ofFill(); ofCircle(ofGetWidth()/2+shapes[i].r*sin(shapes[i].r/500*ofGetElapsedTimef()), ofGetHeight()/2+shapes[i].r*cos(shapes[i].r/500*ofGetElapsedTimef()), shapes[i].r/70); ofSetColor(255*abs(sin(ofGetElapsedTimef())), 255*abs(sin(ofGetElapsedTimef())), 255*abs(sin(ofGetElapsedTimef()+PI/4))); ofNoFill(); //ofLine(ofGetWidth()/2+shapes[i+1].r*sin(shapes[i+1].r/500*ofGetElapsedTimef()), ofGetHeight()/2+shapes[i+1].r*cos(shapes[i+1].r/500*ofGetElapsedTimef()), ofGetWidth()/2+shapes[i+2].r*sin(shapes[i+2].r/500*ofGetElapsedTimef()), ofGetHeight()/2+shapes[i+2].r*cos(shapes[i+2].r/500*ofGetElapsedTimef())); ofCurve(ofGetWidth()/2+shapes[i-1].r*sin(shapes[i-1].r/500*ofGetElapsedTimef()), ofGetHeight()/2+shapes[i-1].r*cos(shapes[i-1].r/500*ofGetElapsedTimef()), ofGetWidth()/2+shapes[i].r*sin(shapes[i].r/500*ofGetElapsedTimef()), ofGetHeight()/2+shapes[i].r*cos(shapes[i].r/500*ofGetElapsedTimef()),ofGetWidth()/2+shapes[i+1].r*sin(shapes[i+1].r/500*ofGetElapsedTimef()), ofGetHeight()/2+shapes[i+1].r*cos(shapes[i+1].r/500*ofGetElapsedTimef()),ofGetWidth()/2+shapes[i+2].r*sin(shapes[i+2].r/500*ofGetElapsedTimef()), ofGetHeight()/2+shapes[i+2].r*cos(shapes[i+2].r/500*ofGetElapsedTimef())); } } ofSetColor(0, 0, 0); ofFill(); ofRect(15, 15, 175, 50); ofSetColor(255, 255, 255); ofDrawBitmapString(">Press 1 for Circles\n>Press 2 for Web", text); }
//------------------------------------------------------------------------------ void ofApp::draw() { ofBackground(0); ofPushStyle(); ofNoFill(); //for every user, set a color, draw a circle and draw a curve between each pair of users for(int i = 0; i < people.size(); i++) { ofSetColor(people[i].col); ofCircle(people[i].pos.x, people[i].pos.y, 2,2); ofVec2f p1 = ofVec2f(people[i].pos.x, people[i].pos.y); for(int j = 0; j < people.size(); j++) { ofVec2f p2 = ofVec2f(people[j].pos.x, people[j].pos.y); if(i!=j){ ofVec2f center = ofVec2f(ofGetWidth()/2, ofGetHeight()/2); ofVec2f curvy = p2 - center; curvy.normalize(); curvy *= people[i].curvature; ofCurve(p1.x, p1.y, p1.x, p1.y, p2.x, p2.y, p1.x+curvy.x, p1.y+curvy.y); } } } ofPopStyle(); }
static int lua_graphics_curve(lua_State *L) { float x1 = luaL_checknumber(L, 1); float y1 = luaL_checknumber(L, 2); float x2 = luaL_checknumber(L, 3); float y2 = luaL_checknumber(L, 4); float cx1 = luaL_checknumber(L, 5); float cy1 = luaL_checknumber(L, 6); float cx2 = luaL_checknumber(L, 7); float cy2 = luaL_checknumber(L, 8); ofCurve(cx1, cy1, x1, y1, x2, y2, cx2, cy2); return 0; }
//---------------------------------------------------------- void ofxVectorGraphics::curve(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4){ if(bDraw){ ofCurve(x1, y1, x2, y2, x3, y3, x4, y4); } if(bRecord){ //we treat the catmull rom curve as a bezier //by finding the approrpriate control points //to make the same curve //x1 y1 = p1 //x2 y2 = p2 //x3 y3 = p3 //x4 y4 = p4 //control point at p2 is parallel //to the line defined by p3 - p1 //control point at p3 is parallel //to the line defined by p4 - p2 ofPoint3 p1(x1, y1); ofPoint3 p2(x2, y2); ofPoint3 p3(x3, y3); ofPoint3 p4(x4, y4); //SUPER WEIRD MAGIC CONSTANT = 1/6 (this works 100% can someone explain it?) ofPoint3 cp1 = p2 + ( p3 - p1 ) * (1.0/6); ofPoint3 cp2 = p3 + ( p2 - p4 ) * (1.0/6); creeps.startPath(x2, y2); creeps.addCurve( cp1.x, cp1.y, cp2.x, cp2.y, x3, y3); if(bFill){ creeps.addLine(x2, y2); creeps.endPath(CreEPS::FILL); }else{ creeps.endPath(CreEPS::STROKE); } } }