Skip to content

Instantly share code, notes, and snippets.

@ofZach
Created June 10, 2016 17:59
Show Gist options
  • Select an option

  • Save ofZach/c66baf5b28da39fcd014377f1a63b21a to your computer and use it in GitHub Desktop.

Select an option

Save ofZach/c66baf5b28da39fcd014377f1a63b21a to your computer and use it in GitHub Desktop.

Revisions

  1. ofZach created this gist Jun 10, 2016.
    133 changes: 133 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,133 @@
    #include "ofApp.h"


    vector < vector < float > > energies;



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

    ofSetCircleResolution(100);

    for (int i = 0; i < 5; i++){

    int howMany = ofRandom(3, 7);

    vector < float > energy;

    for (int j = 0; j < howMany; j++){
    energy.push_back( ofRandom(0.05, 1.0));
    if (energy[j] < 0.3){
    energy[j] = powf(energy[j], 1.2);
    }
    }

    energies.push_back(energy);
    }


    }

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

    }

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

    float h = ofGetHeight()/energies.size();

    for (int i = 0; i < energies.size(); i++){

    float total = 0;
    for (auto a: energies[i]){
    total += a;
    }

    float pos = 0;
    for (auto a: energies[i]){
    float pct = a / total;


    ofDrawEllipse( ofPoint(pos + pct*ofGetWidth()/2, i*h + h/2), pct*ofGetWidth(),h);
    pos += pct * ofGetWidth();
    }
    }

    }

    //--------------------------------------------------------------
    void ofApp::keyPressed(int key){

    }

    //--------------------------------------------------------------
    void ofApp::keyReleased(int key){

    }

    //--------------------------------------------------------------
    void ofApp::mouseMoved(int x, int y ){

    energies.clear();


    for (int i = 0; i < 5; i++){

    int howMany = ofRandom(3, 7);

    vector < float > energy;

    for (int j = 0; j < howMany; j++){
    energy.push_back( ofRandom(0.05, 1.0));
    if (energy[j] < 0.3){
    energy[j] = powf(energy[j], 1.2);
    }
    }

    energies.push_back(energy);
    }

    }

    //--------------------------------------------------------------
    void ofApp::mouseDragged(int x, int y, int button){

    }

    //--------------------------------------------------------------
    void ofApp::mousePressed(int x, int y, int button){

    }

    //--------------------------------------------------------------
    void ofApp::mouseReleased(int x, int y, int button){

    }

    //--------------------------------------------------------------
    void ofApp::mouseEntered(int x, int y){

    }

    //--------------------------------------------------------------
    void ofApp::mouseExited(int x, int y){

    }

    //--------------------------------------------------------------
    void ofApp::windowResized(int w, int h){

    }

    //--------------------------------------------------------------
    void ofApp::gotMessage(ofMessage msg){

    }

    //--------------------------------------------------------------
    void ofApp::dragEvent(ofDragInfo dragInfo){

    }