<file_sep>//
//  Bubble.cpp
//  learningBubbles
//
//  Created by <NAME> on 4/15/15.
//
//

#include "Bubble.h"


Bubble::Bubble(){
    pos = ofVec2f(300, 300);
    vel = ofVec2f(ofRandom(-10,10), ofRandom(-10,10));;
    rad = 30;
    myColor = ofColor(ofRandom(255),ofRandom(255),ofRandom(255));
    rot = 0;
    
}

void Bubble::setup(float _x, float _y){
    pos = ofVec2f(_x, _y);
    birth = pos;
}
void Bubble::update(){
    pos += vel;
    rot+=abs(vel.x);
    float distance = ofDist(birth.x,birth.y,pos.x, pos.y);
    float bright = ofMap(distance, 0, 400, 255, 0);
    myColor.a = bright;
}
void Bubble::draw(){
    ofSetColor(myColor);
    //option1
    ofPushMatrix();
    ofTranslate(pos);
    ofRotate(rot);
    ofCircle(0,0 , rad);
    ofPopMatrix();
    
    ///option2
//    ofPushMatrix();
//    ofRotate(rot);
//    ofCircle(pos, rad);
//    ofPopMatrix();
    
    
}<file_sep>#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    ofSetCircleResolution(3);
}

//--------------------------------------------------------------
void ofApp::update(){
    Bubble tempBubble;
    tempBubble.setup(ofGetMouseX(),ofGetMouseY());
    bubbles.push_back(tempBubble);
    for (int i = 0; i< bubbles.size(); i++) {
        bubbles[i].update();
        float distance = ofDist(bubbles[i].birth.x, bubbles[i].birth.y, bubbles[i].pos.x, bubbles[i].pos.y);
        if (distance>400) {
            bubbles.erase(bubbles.begin()+i);
            i--;
        }
        
        
    }
    
    
    
}

//--------------------------------------------------------------
void ofApp::draw(){
    for (int i = 0; i< bubbles.size(); i++) {
        bubbles[i].draw();
    }
}

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

}

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

}

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

}

//--------------------------------------------------------------
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::windowResized(int w, int h){

}

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

}

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

}
