Skip to content

Instantly share code, notes, and snippets.

@ofZach
Created June 10, 2016 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ofZach/c66baf5b28da39fcd014377f1a63b21a to your computer and use it in GitHub Desktop.
Save ofZach/c66baf5b28da39fcd014377f1a63b21a to your computer and use it in GitHub Desktop.
ovals!
#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){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment