void Tree::seed2(float dotSize, float angle, float x, float y){ if(dotSize > 1.0f){ float r = ofRandomuf(); // will give a random number between 0 and 1 if(r > 0.5){ ofCircle(x, y, dotSize); float newX = x + cos(angle)*dotSize; float newY = y + sin(angle)*dotSize; seed2(dotSize*0.9f, angle - angleOffSetA, newX, newY); // changing the position of x and y each time } else { ofCircle(x, y, dotSize); float newX = x + cos(angle)*dotSize; float newY = y + sin(angle)*dotSize; seed2(dotSize*0.5f, angle - angleOffSetA, newX, newY); seed1(dotSize*0.7f, angle + angleOffSetB, newX, newY); seed2(dotSize*0.3f, angle - angleOffSetB, newX, newY); } } }
void liveApp::seed2(float dotSize, float angle, float x, float y) { if (dotSize > 1.0) { // Create a random numbers between 0 and 1 float r = ofRandom(0, 1.0); // 5% chance this will happen if (r > 0.05) { ofEllipse(x, y, dotSize, dotSize); float newx = x + cos(angle) * dotSize; float newy = y + sin(angle) * dotSize; seed2(dotSize * 0.99, angle + angleOffsetA, newx, newy); } // 95% chance this will happen else { ofEllipse(x, y, dotSize, dotSize); float newx = x + cos(angle); float newy = y + sin(angle); seed1(dotSize * 0.99, angle + angleOffsetA, newx, newy); seed2(dotSize * 0.60, angle + angleOffsetB, newx, newy); seed1(dotSize * 0.50, angle - angleOffsetB, newx, newy); } } }
void liveApp::seed1(float dotSize, float angle, float x, float y) { if (dotSize > 1.0) { // Create a random numbers between 0 and 1 float r = ofRandom(0, 1.0); // 02% chance this will happen if (r > 0.04) { ofFill(); //ofSetColor(coldColor[int(ofRandom(0,11))]); ofSetColor(255,255,255,225); ofEllipse(x, y, dotSize, dotSize); float newx = x + cos(angle) * dotSize; float newy = y + sin(angle) * dotSize; seed1(dotSize * 0.99, angle - angleOffsetA, newx, newy); } // 98% chance this will happen else { ofEllipse(x, y, dotSize, dotSize); float newx = x + cos(angle); float newy = y + sin(angle); seed2(dotSize * 0.99, angle + angleOffsetA, newx, newy); seed1(dotSize * 0.60, angle + angleOffsetB, newx, newy); seed2(dotSize * 0.50, angle - angleOffsetB, newx, newy); } } }
// void Tree:: functios from the header file void Tree::seed1(float dotSize, float angle, float x, float y) { // nested if statment if(dotSize > 1.0f){ float r = ofRandomuf(); // will give a random number between 0 and 1 // first if statement will happpen 98% of the time if(r > 0.02) { ofCircle(x, y, dotSize); float newX = x + cos(angle)*dotSize; float newY = y + sin(angle)*dotSize; seed1(dotSize*0.9f, angle - angleOffSetA, newX, newY); // changing the position of x and y each time } else { ofCircle(x, y, dotSize); float newX = x + cos(angle)*dotSize; float newY = y + sin(angle)*dotSize; seed1(dotSize*0.3f, angle - angleOffSetA, newX, newY); seed2(dotSize*0.7f, angle + angleOffSetB, newX, newY); seed1(dotSize*0.1f, angle - angleOffSetB, newX, newY); } } }
void Tree::seed1(float dotSize, float angle, float x, float y) { ofSetColor(255, 0, 0); ofFill(); //nested if statement if(dotSize >1.0f) { float r = ofRandomuf(); // gives you a random number between 0 & 1 //first if statement will happen 98 of time if(r>0.02f) { ofDrawCircle(x,y,dotSize); float newX = x + cos(angle) * dotSize; float newY = y + sin(angle) * dotSize; seed1(dotSize*0.99f, angle+angleOffSetA, newX, newY); //- and + changes the angle of rotating } else { ofDrawCircle(x,y,dotSize); float newX = x + cos(angle) * dotSize; float newY = y + sin(angle) * dotSize; seed1(dotSize*0.99f, angle-angleOffSetA, newX, newY); seed2(dotSize*0.4f, angle+angleOffSetB, newX, newY); seed1(dotSize*0.6f, angle-angleOffSetB, newX, newY); } } }
void Tree:: seed2(float dotSize, float angle, float x, float y){ if(dotSize > 1.0f){ float r = ofRandomuf(); if(r > 0.05f){ ofCircle(x, y, dotSize); float newX = x + cos(angle)*dotSize; float newY = y + sin(angle)*dotSize; seed2(dotSize*0.99f, angle + angleOffSetA, newX, newY); } else { ofCircle(x, y, dotSize); float newX = x + cos(angle); float newY = y + sin(angle); seed2(dotSize*0.99f, angle - angleOffSetA, newX, newY); seed1(dotSize*0.6f, angle + angleOffSetB, newX, newY); seed2(dotSize*0.5f, angle - angleOffSetB, newX, newY); } } }
void Tree::seed2(float dotSize, float angle, float x, float y) { ofSetColor(0, 0, 255); ofFill(); if (dotSize > 1.0f) { float r = ofRandomuf(); if(r>0.05f) { ofDrawCircle(x,y,dotSize); float newX = x + cos(angle) * dotSize; float newY = y + sin(angle) * dotSize; seed2(dotSize*0.99f, angle-angleOffSetA, newX, newY); } else { ofDrawCircle(x,y,dotSize); float newX = x + cos(angle) * dotSize; float newY = y + sin(angle) * dotSize; seed2(dotSize*0.99f, angle-angleOffSetA, newX, newY); seed1(dotSize*0.7f, angle+angleOffSetB, newX, newY); seed2(dotSize*0.9f, angle-angleOffSetB, newX, newY); } } }
int main( ){ DifferentialState phi, dphi; Control u; Parameter p; TIME t; IntermediateState x(5); x(0) = t ; x(1) = phi ; x(2) = dphi; x(3) = u ; x(4) = p ; CFunction pendulumModel( 2, ffcn_model ); // Define a Right-Hand-Side: // ------------------------- DifferentialEquation f; f << pendulumModel(x); // DEFINE AN INTEGRATOR: // --------------------- IntegratorRK45 integrator( f ); integrator.set(INTEGRATOR_PRINTLEVEL, HIGH ); // DEFINE INITIAL VALUES: // ---------------------- double x_start[2] = { 0.0, 0.0 }; double u_ [1] = { 1.0 }; double p_ [1] = { 1.0 }; double t_start = 0.0; double t_end = 1.0; // START THE INTEGRATION: // ---------------------- integrator.freezeAll(); integrator.integrate( t_start, t_end, x_start, 0, p_, u_ ); // DEFINE A SEED MATRIX: // --------------------- Vector seed1(2); Vector seed2(2); seed1(0) = 1.0; seed1(1) = 0.0; seed2(0) = 1.0; seed2(1) = 0.0; // COMPUTE FIRST ORDER DERIVATIVES: // -------------------------------- integrator.setForwardSeed(1,seed1); integrator.integrateSensitivities(); // COMPUTE SECOND ORDER DERIVATIVES: // --------------------------------- integrator.setForwardSeed(2,seed2); integrator.integrateSensitivities(); // GET THE RESULTS // --------------- VariablesGrid differentialStates; integrator.getX( differentialStates ); Vector Dx( 2 ), DDx( 2 ); integrator.getForwardSensitivities( Dx,1 ); integrator.getForwardSensitivities( DDx,2 ); differentialStates.print( "x" ); Dx.print( "Dx" ); DDx.print( "DDx" ); return 0; }