Skip to content

Instantly share code, notes, and snippets.

@ofZach
Created January 4, 2014 12:44
Show Gist options
  • Save ofZach/8255060 to your computer and use it in GitHub Desktop.
Save ofZach/8255060 to your computer and use it in GitHub Desktop.
funky curved line via ofNode
// in .h file:
ofNode a,b,c;
float aEnergy;
float bEnergy;
float aEnergySmth;
float bEnergySmth;
float time;
ofPolyline nodeLine;
// in .cpp file:
//--------------------------------------------------------------
void testApp::setup(){
ofBackground(0);
a.setPosition(500,300,0);
b.setParent(a);
b.setPosition(0,200,0);
c.setParent(b);
c.setPosition(0,100,0);
aEnergy = 1;
bEnergy = 1;
aEnergySmth = 1;
bEnergySmth = 1;
}
//--------------------------------------------------------------
void testApp::update(){
for (int i = 0; i < nodeLine.size(); i++){
nodeLine[i] -= ofPoint(1,0);
}
aEnergySmth = 0.97 * aEnergySmth + (1-0.97) *aEnergy;
bEnergySmth = 0.97 * bEnergySmth + (1-0.97) *bEnergy;
a.roll(aEnergySmth);
b.roll(bEnergySmth);
if ( ofRandom(0,1) > 0.95 ){
aEnergy = 0.4 * ofRandom(4, 8) * (ofRandom(0,1) > 0.5 ? 1 : -1);
}
if (ofRandom(0,1) > 0.95){
bEnergy = ofRandom(4,8) * (ofRandom(0,1) > 0.5 ? 1 : -1);
}
nodeLine.addVertex(c.getGlobalPosition());
}
//--------------------------------------------------------------
void testApp::draw(){
ofCircle(a.getGlobalPosition(), 3);
ofCircle(b.getGlobalPosition(), 3);
ofCircle(c.getGlobalPosition(), 3);
ofLine(a.getGlobalPosition(), b.getGlobalPosition());
ofLine(b.getGlobalPosition(), c.getGlobalPosition());
nodeLine.draw();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment