noc02-force

Strange Attractor

0

0

Source Code

ofApp.cpp

    //--------------------------------------------------------------
    void ofApp::setup(){

        ofEnableDepthTest(); // z index
       light.setSpecularColor(ofFloatColor(1.0,1.0,1.0));
       light.setAmbientColor(ofFloatColor(1.0,1.0,1.0));
        light.setDiffuseColor(ofFloatColor(1.0,1.0,1.0));
        light.enable();

        ofBackground(0);
     //   ofSetBackgroundAuto(false);
        ofSetColor(255);

        for (int i = 0; i<3; i++) {
            ofVec3f pos;
            pos.set(ofRandom(6),ofRandom(6),ofRandom(6));
    //        pos.set(10,10,10);
            pList.push_back(pos);

        }

        mesh.setMode(OF_PRIMITIVE_LINE_STRIP);

        ofDrawAxis(200);

        col.set(0,0.3215,0.6118,0.2);
    //    col.set(0.09,0.2745,0.4863,0.2);
    }

    //--------------------------------------------------------------
    void ofApp::update(){

        ofSetWindowTitle(ofToString(ofGetFrameRate()));

    //t = ofGetElapsedTimef() * 0.1;
        dt = 0.01;

    //Lorenz attactor
        a = 10;
        b = 28;
        c = -2.666666;

    //black hole
    //    a = 45;
    //    b = 49;
    //    c =-15;


        for (int i=0; i<pList.size(); i++) {
            pList[i].x = pList[i].x + a*(-pList[i].x+pList[i].y)*dt;
            pList[i].y = pList[i].y + (b*pList[i].x-pList[i].y-pList[i].z*pList[i].x)*dt;
            pList[i].z= pList[i].z + (c*pList[i].z+pList[i].x*pList[i].y)*dt;

    //        cout << dt << endl;
    //        cout << i << endl;
    //        cout << pList[i].x << endl;
    //        cout << pList[i].y << endl;
    //        cout << pList[i].z << endl;

            mesh.addVertex(pList[0]* 6);
    //        mesh.addColor(col);

            //  ofDrawSphere(pList[i] *5, 1);

        }

    }

    //--------------------------------------------------------------
    void ofApp::draw(){
        //      ofPushMatrix();
       // ofTranslate(ofGetWidth()/2 -200,ofGetHeight()/2);
        ofRotateX(ofGetElapsedTimef());



        cam.begin();
        mesh.draw();

        cam.end();
    //      ofPopMatrix();
}

ofApp.h

class ofApp : public ofBaseApp{

public:
    void setup();
    void update();
    void draw();

    ofLight light;
    ofEasyCam cam;
    vector<ofVec3f>pList;

    float a,b,c;
    float dt;

    ofMesh mesh;

    ofFloatColor col;

};