#include <iostream>
using namespace std;

class Dog { // Dog
public:
    string name; //        (       )
    void bark(); //            (       )
}; //Dog               (       ";"         )


int main (int argc, char * const argv[]) { //


}
software systems.



Interface and Implementation

     To invent programs, you need to be able to capture abstractions and express them in t
     design. It’s the job of a programming language to help you do this. The language shoul
     process of invention and design by letting you encode abstractions that reveal the way
     It should let you make your ideas concrete in the code you write. Surface details shou
     the architecture of your program.

     All programming languages provide devices that help express abstractions. In essence
     are ways of grouping implementation details, hiding them, and giving them, at least t
     a common interface—much as a mechanical object separates its interface from its impl
     illustrated in “Interface and Implementation” .

     Figure 2-1            Inte rfa ce a nd Im ple m e nta tion

     interface                         implementation




                       11
                  10
                 9
                  8
                       7
                               6


     Looking at such a unit from the inside, as the implementor, you’d be concerned with w
     composed of and how it works. Looking at it from the outside, as the user, you’re conc
     with what it is and what it does. You can look past the details and think solely in term
::   (   ){
    //
}
#include <iostream>
using namespace std;

class Dog { // Dog
public:
    string name; //         (           )
    void bark(); //             (           )
}; //Dog                (       ";"                      )


void Dog::bark() { //Dog                        bark()
    //
    cout << name << "               !       " << endl;
}

int main (int argc, char * const argv[]) { //
}
#include <iostream>
using namespace std;

class Dog { // Dog
public:
    string name; //         (           )
    void bark(); //             (           )
}; //Dog                (       ";"                      )


void Dog::bark() { //Dog                        bark()
    //
    cout << name << "               !       " << endl;
}

int main (int argc, char * const argv[]) { //
    Dog hachi; //Dog                                     hachi
}
#include <iostream>
using namespace std;

class Dog { // Dog
public:
    string name; //          (           )
    void bark(); //              (           )
}; //Dog                (        ";"                       )


void Dog::bark() { //Dog                         bark()
    //
    cout << name << "                !       " << endl;
}

int main (int argc, char * const argv[]) { //
    Dog hachi; //Dog                                       hachi
    hachi.name = "      "; //hachi                        name   "   "
}
#include <iostream>
using namespace std;

class Dog { // Dog
public:
    string name; //          (           )
    void bark(); //              (           )
}; //Dog                (        ";"                       )
void Dog::bark() { //Dog                         bark()
    //
    cout << name << "                !       " << endl;
}
int main (int argc, char * const argv[]) { //
    Dog hachi; //Dog                                       hachi
    hachi.name = "      "; //hachi                        name   "   "
    hachi.bark(); //hachi                        bark()
}
run
[Switching to process xxxx]
            !
    ...


Debugger stopped.
Program exited with status value:0.
#include "Dog.h"

int main (int argc, char * const argv[]) { //
    Dog hachi; //Dog                          hachi
    hachi.name = "     "; //hachi            name   "   "
    hachi.bark(); //hachi           bark()
}
#include <iostream>
using namespace std;

class Dog { // Dog
public:
    string name; //        (       )
    void bark(); //            (       )
}; //Dog               (       ";"         )
#include "Dog.h"

void Dog::bark() { //Dog         bark()
    //
    cout << name << "      !   " << endl;
}
#ifndef _TEST_APP
#define _TEST_APP

#include "ofMain.h"

class testApp : public ofBaseApp {
public:
    void setup();
    void update();
    void draw();
    void keyPressed (int key);
    void keyReleased(int key);
    void mouseMoved(int x, int y );
    void mouseDragged(int x, int y, int button);
    void mousePressed(int x, int y, int button);
    void mouseReleased(int x, int y, int button);
    void windowResized(int w, int h);
};

#endif
#include "testApp.h"

void   testApp::setup(){
}
void   testApp::update(){
}
void   testApp::draw(){
}
void   testApp::keyPressed(int key){
}
void   testApp::keyReleased(int key){
}
void   testApp::mouseMoved(int x, int y){
}
void   testApp::mouseDragged(int x, int y, int button){
}
void   testApp::mousePressed(int x, int y, int button){
}
void   testApp::mouseReleased(int x, int y, int button){
}
void   testApp::windowResized(int w, int h){
}
#ifndef _TEST_APP
#define _TEST_APP

#include "ofMain.h"
#include "ofBlob.h"

class testApp : public ofBaseApp {
public:
    void setup();
    void update();
    void draw();
    void keyPressed (int key);
    void keyReleased(int key);
    void mouseMoved(int x, int y );
    void mouseDragged(int x, int y, int button);
    void mousePressed(int x, int y, int button);
    void mouseReleased(int x, int y, int button);
    void windowResized(int w, int h);
    ofBlob blob; //ofBlob
};

#endif
#include "testApp.h"

void testApp::setup(){
    //
    ofBackground(0, 0, 0);
    ofSetCircleResolution(64);
    ofEnableAlphaBlending();
    ofSetFrameRate(30);
}

void testApp::update(){
}

void testApp::draw(){
    blob.draw(); //blob      draw()
}

...(   )
#ifndef _OF_BLOB
#define _OF_BLOB

#include "ofMain.h"

class ofBlob {
public:
    // method
    void draw();
};

#endif
#include "ofBlob.h"

void ofBlob::draw()
{
    ofSetColor(31, 63, 255);
    ofCircle(ofGetWidth()/2, ofGetHeight()/2, 100);
}
#ifndef _TEST_APP
#define _TEST_APP

#include "ofMain.h"
#include "ofBlob.h"

class testApp : public ofBaseApp {

public:
  void    setup();
  void    update();
  void    draw();
  void    keyPressed (int key);
  void    keyReleased(int key);
  void    mouseMoved(int x, int y );
  void    mouseDragged(int x, int y, int button);
  void    mousePressed(int x, int y, int button);
  void    mouseReleased(int x, int y, int button);
  void    windowResized(int w, int h);

     ofBlob blob; //ofBlob
};

#endif
#include "testApp.h"

void testApp::setup(){
  //
    ofBackground(0, 0, 0);
    ofSetCircleResolution(32);
    ofEnableAlphaBlending();
    ofSetFrameRate(30);
    blob.setPos(ofPoint(300, 400)); //blob
    blob.setDim(80); //blob
}

void testApp::update(){
}

void testApp::draw(){
  blob.draw(); //blob          draw()
}

...(    )
#ifndef _OF_BLOB
#define _OF_BLOB

#include "ofMain.h"

class ofBlob {

private:
   float dim; //
     ofPoint pos; //

public:
  void setDim(float dim); //dim
     float getDim(); //dim
     void setPos(ofPoint pos); //pos
     ofPoint getPos(); //pos
     void draw(); //
};

#endif
#include "ofBlob.h"

void ofBlob::setDim(float _dim)
{
  dim = _dim;
}

float ofBlob::getDim()
{
   return dim;
}

void ofBlob::setPos(ofPoint _pos)
{
  pos = _pos;
}

ofPoint ofBlob::getPos()
{
   return pos;
}

void ofBlob::draw()
{
  ofSetColor(31, 63, 255);
  ofCircle(pos.x, pos.y, dim);
#ifndef _TEST_APP
#define _TEST_APP

#include "ofMain.h"
#include "ofBlob.h"

class testApp : public ofBaseApp {

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

     void   keyPressed (int key);
     void   keyReleased(int key);
     void   mouseMoved(int x, int y );
     void   mouseDragged(int x, int y, int button);
     void   mousePressed(int x, int y, int button);
     void   mouseReleased(int x, int y, int button);
     void   windowResized(int w, int h);

     ofBlob blob; //ofBlob
};
#include "testApp.h"

void testApp::setup(){
  //
    ofBackground(0, 0, 0);
    ofSetCircleResolution(32);
    ofEnableAlphaBlending();
    ofSetFrameRate(30);
    blob.setPos(ofPoint(300, 400)); //blob
    blob.setDim(80); //blob
    blob.setSpeed(ofPoint(8,5)); //
}

void testApp::update(){
  blob.update();
}

void testApp::draw(){
  blob.draw(); //blob          draw()
}

...(    )
#ifndef _OF_BLOB
#define _OF_BLOB
#include "ofMain.h"

class ofBlob {

private:
   float dim; //
     ofPoint pos; //
     ofPoint speed; //


public:
  void setDim(float dim); //dim
     float getDim(); //dim
     void setPos(ofPoint pos); //pos
     ofPoint getPos(); //pos
     void setSpeed(ofPoint speed); //speed
     ofPoint getSpeed(); //speed
     void update(); //
     void draw(); //
};
#include "ofBlob.h"

void ofBlob::setDim(float _dim)
{
  dim = _dim;
}

float ofBlob::getDim()
{
   return dim;
}

void ofBlob::setPos(ofPoint _pos)
{
  pos = _pos;
}

ofPoint ofBlob::getPos()
{
   return pos;
}

void ofBlob::setSpeed(ofPoint _speed)
{
ofPoint ofBlob::getSpeed()
{
   return speed;
}

void ofBlob::update()
{
  pos.x += speed.x;
  pos.y += speed.y;
  if(pos.x < dim || pos.x > ofGetWidth()-dim){
     speed.x *= -1;
  }
  if(pos.y < dim || pos.y > ofGetHeight()-dim){
     speed.y *= -1;
  }
}

void ofBlob::draw()
{
  ofSetColor(31, 63, 255);
  ofCircle(pos.x, pos.y, dim);
}
#ifndef _OF_BLOB
#define _OF_BLOB

#include "ofMain.h"

class ofBlob {

private:
   float dim; //
  ofPoint pos; //
  ofPoint speed; //
  float moveDim; //
  float phase; //
  float phaseSpeed; //


public:
  ofBlob(); //
  void setDim(float dim); //dim
  float getDim(); //dim
  void setPos(ofPoint pos); //pos
  ofPoint getPos(); //pos
ofPoint getSpeed(); //speed
     void update(); //
     void draw(); //
};

#endif
#include "ofBlob.h"

ofBlob::ofBlob()
{
  phaseSpeed = ofRandom(0.1, 0.2);
  phase = 0;
}

void ofBlob::setDim(float _dim)
{
  dim = _dim;
}

float ofBlob::getDim()
{
   return dim;
}

void ofBlob::setPos(ofPoint _pos)
{
  pos = _pos;
}
ofPoint ofBlob::getPos()
{
   return pos;
}

void ofBlob::setSpeed(ofPoint _speed)
{
  speed = _speed;
}

ofPoint ofBlob::getSpeed()
{
   return speed;
}

void ofBlob::update()
{
  moveDim = dim + sin(phase)*dim/4;
  phase += phaseSpeed;
  if(phase > TWO_PI){
     phase -= TWO_PI;
  }
  pos.x += speed.x;
  pos.y += speed.y;
if(pos.x < dim || pos.x > ofGetWidth()-dim){
       speed.x *= -1;
    }
    if(pos.y < dim || pos.y > ofGetHeight()-dim){
       speed.y *= -1;
    }
}

void ofBlob::draw()
{
  ofSetColor(31, 63, 255, 200);
  ofCircle(pos.x, pos.y, moveDim);
}
#ifndef _TEST_APP
#define _TEST_APP


#include "ofMain.h"
#include "ofBlob.h"

class testApp : public ofBaseApp {

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

     void   keyPressed (int key);
     void   keyReleased(int key);
     void   mouseMoved(int x, int y );
     void   mouseDragged(int x, int y, int button);
     void   mousePressed(int x, int y, int button);
     void   mouseReleased(int x, int y, int button);
     void   windowResized(int w, int h);

     vector <ofBlob> blobs; //ofBlob              Vector
};
#include "testApp.h"

void testApp::setup(){
  ofBackground(0, 0, 0);
  ofSetCircleResolution(64);
  ofEnableAlphaBlending();
  ofSetFrameRate(30);
}

void testApp::update(){
  for (int i = 0; i < blobs.size(); i++) {
     blobs[i].update();
  }
}

void testApp::draw(){
  for (int i = 0; i < blobs.size(); i++) {
     blobs[i].draw();
  }
}

...(   )...
void testApp::mouseReleased(int x, int y, int button){
  ofBlob b = ofBlob(); //    ofBlob
    b.setPos(ofPoint(mouseX, mouseY)); //
    b.setDim(ofRandom(10,40)); //
    b.setSpeed(ofPoint(ofRandom(-5, 5), ofRandom(-5, 5))); //
    blobs.push_back(b);
}

...(    )
#ifndef _OF_BLOB
#define _OF_BLOB

#include "ofMain.h"

class ofBlob {

private:
   float dim; //
  ofPoint pos; //
  ofPoint speed; //
  float moveDim; //
  float phase; //
  float phaseSpeed; //


public:
  ofBlob(); //
  void setDim(float dim); //dim
  float getDim(); //dim
  void setPos(ofPoint pos); //pos
  ofPoint getPos(); //pos
ofPoint getSpeed(); //speed
     void update(); //
     void draw(); //
};

#endif
#include "ofBlob.h"

ofBlob::ofBlob()
{
  phaseSpeed = ofRandom(0.1, 0.2);
  phase = 0;
}

void ofBlob::setDim(float _dim)
{
  dim = _dim;
}

float ofBlob::getDim()
{
   return dim;
}

void ofBlob::setPos(ofPoint _pos)
{
  pos = _pos;
}

ofPoint ofBlob::getPos()
{
   return pos;
void ofBlob::setSpeed(ofPoint _speed)
{
  speed = _speed;
}

ofPoint ofBlob::getSpeed()
{
   return speed;
}

void ofBlob::update()
{
  moveDim = dim + sin(phase)*dim/4;
  phase += phaseSpeed;
  if(phase > TWO_PI){
     phase -= TWO_PI;
  }
  pos.x += speed.x;
  pos.y += speed.y;
  if(pos.x < dim || pos.x > ofGetWidth()-dim){
     speed.x *= -1;
  }
  if(pos.y < dim || pos.y > ofGetHeight()-dim){
     speed.y *= -1;
  }
}
void ofBlob::draw()
{
  ofSetColor(31, 63, 255, 80);
  ofCircle(pos.x, pos.y, moveDim);
  ofSetColor(255, 63, 31);
  ofCircle(pos.x, pos.y, dim/10);
}
#ifndef _TEST_APP
#define _TEST_APP


#include "ofMain.h"
#include "ofBlob.h"

class testApp : public ofBaseApp {

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

     void   keyPressed (int key);
     void   keyReleased(int key);
     void   mouseMoved(int x, int y );
     void   mouseDragged(int x, int y, int button);
     void   mousePressed(int x, int y, int button);
     void   mouseReleased(int x, int y, int button);
     void   windowResized(int w, int h);

     vector <ofBlob> blobs; //ofBlob              Vector
};
#include "testApp.h"

void testApp::setup(){
  ofBackground(0, 0, 0);
  ofSetCircleResolution(64);
  ofEnableAlphaBlending();
  ofSetFrameRate(30);

    ofBlob b = ofBlob();
    b.setPos(ofPoint(ofGetWidth()/2, ofGetHeight()/2));
    b.setDim(ofGetHeight()/3);
    blobs.push_back(b);
}

void testApp::update(){
  for (int i = 0; i < blobs.size(); i++) {
     blobs[i].update();
  }
}

void testApp::draw(){
  for (int i = 0; i < blobs.size(); i++) {
     blobs[i].draw();
  }
void testApp::keyPressed(int key){
  switch (key) {
     case 'f':
        ofSetFullscreen(true);
        break;
  }
}

void testApp::keyReleased(int key){
}

void testApp::mouseMoved(int x, int y){
}

void testApp::mouseDragged(int x, int y, int button){
}

void testApp::mousePressed(int x, int y, int button){
  int bSize = blobs.size();
  for (int i = 0; i < bSize; i++) {
     ofPoint p = blobs[i].getPos();
     float dist = ofDist(p.x, p.y, mouseX, mouseY);
     float dim = blobs[i].getDim();
     ofPoint pos = blobs[i].getPos();
if(dist < dim){
        //
          blobs[i].setDim(dim*0.6);
          blobs[i].setPos(ofPoint(pos.x-dim/2,pos.y-dim/2));
          blobs[i].setSpeed(ofPoint(ofRandom(-dim/150,dim/150),ofRandom(-dim/150,dim/
150)));

          //   1
          ofBlob b1 = ofBlob();
          b1.setDim(dim*0.6);
          b1.setPos(ofPoint(pos.x+dim/2,pos.y+dim/2));
          b1.setSpeed(ofPoint(ofRandom(-dim/150,dim/150),ofRandom(-dim/150,dim/
150)));
          blobs.push_back(b1);

          //   2
          ofBlob b2 = ofBlob();
          b2.setDim(dim*0.6);
          b2.setPos(ofPoint(pos.x-dim/2,pos.y+dim/2));
          b2.setSpeed(ofPoint(ofRandom(-dim/150,dim/150),ofRandom(-dim/150,dim/
150)));
          blobs.push_back(b2);
//   3
            ofBlob b3 = ofBlob();
            b3.setDim(dim*0.6);
            b3.setPos(ofPoint(pos.x+dim/2,pos.y-dim/2));
            b3.setSpeed(ofPoint(ofRandom(-dim/150,dim/150),ofRandom(-dim/150,dim/
150)));
            blobs.push_back(b3);
        }
    }
}

void testApp::mouseReleased(int x, int y, int button){
  //ofBlob b = ofBlob(ofPoint(mouseX, mouseY));
  //blobs.push_back(b);
}

void testApp::windowResized(int w, int h){
}
#ifndef _OF_BLOB
#define _OF_BLOB

#include "ofMain.h"

class ofBlob {

private:
   float dim; //
  ofPoint pos; //
  ofPoint speed; //
  float moveDim; //
  float phase; //
  float phaseSpeed; //


public:
  ofBlob(); //
  void setDim(float dim); //dim
  float getDim(); //dim
  void setPos(ofPoint pos); //pos
  ofPoint getPos(); //pos
ofPoint getSpeed(); //speed
     void update(); //
     void draw(); //
};

#endif
#include "ofBlob.h"

ofBlob::ofBlob()
{
  phaseSpeed = ofRandom(0.1, 0.2);
  phase = 0;
}

void ofBlob::setDim(float _dim)
{
  dim = _dim;
}

float ofBlob::getDim()
{
   return dim;
}

void ofBlob::setPos(ofPoint _pos)
{
  pos = _pos;
}

ofPoint ofBlob::getPos()
{
   return pos;
void ofBlob::setSpeed(ofPoint _speed)
{
  speed = _speed;
}

ofPoint ofBlob::getSpeed()
{
   return speed;
}

void ofBlob::update()
{
  moveDim = dim + sin(phase)*dim/4;
  phase += phaseSpeed;
  if(phase > TWO_PI){
     phase -= TWO_PI;
  }
  pos.x += speed.x;
  pos.y += speed.y;
  if(pos.x < dim || pos.x > ofGetWidth()-dim){
     speed.x *= -1;
  }
  if(pos.y < dim || pos.y > ofGetHeight()-dim){
     speed.y *= -1;
  }
}
void ofBlob::draw()
{
  ofSetColor(31, 63, 255, 80);
  ofCircle(pos.x, pos.y, moveDim);
  ofSetColor(255, 63, 31);
  ofCircle(pos.x, pos.y, dim/10);
}
Sbaw091006

Sbaw091006

  • 13.
    #include <iostream> using namespacestd; class Dog { // Dog public: string name; // ( ) void bark(); // ( ) }; //Dog ( ";" ) int main (int argc, char * const argv[]) { // }
  • 14.
    software systems. Interface andImplementation To invent programs, you need to be able to capture abstractions and express them in t design. It’s the job of a programming language to help you do this. The language shoul process of invention and design by letting you encode abstractions that reveal the way It should let you make your ideas concrete in the code you write. Surface details shou the architecture of your program. All programming languages provide devices that help express abstractions. In essence are ways of grouping implementation details, hiding them, and giving them, at least t a common interface—much as a mechanical object separates its interface from its impl illustrated in “Interface and Implementation” . Figure 2-1 Inte rfa ce a nd Im ple m e nta tion interface implementation 11 10 9 8 7 6 Looking at such a unit from the inside, as the implementor, you’d be concerned with w composed of and how it works. Looking at it from the outside, as the user, you’re conc with what it is and what it does. You can look past the details and think solely in term
  • 15.
    :: ( ){ // }
  • 16.
    #include <iostream> using namespacestd; class Dog { // Dog public: string name; // ( ) void bark(); // ( ) }; //Dog ( ";" ) void Dog::bark() { //Dog bark() // cout << name << " ! " << endl; } int main (int argc, char * const argv[]) { // }
  • 17.
    #include <iostream> using namespacestd; class Dog { // Dog public: string name; // ( ) void bark(); // ( ) }; //Dog ( ";" ) void Dog::bark() { //Dog bark() // cout << name << " ! " << endl; } int main (int argc, char * const argv[]) { // Dog hachi; //Dog hachi }
  • 18.
    #include <iostream> using namespacestd; class Dog { // Dog public: string name; // ( ) void bark(); // ( ) }; //Dog ( ";" ) void Dog::bark() { //Dog bark() // cout << name << " ! " << endl; } int main (int argc, char * const argv[]) { // Dog hachi; //Dog hachi hachi.name = " "; //hachi name " " }
  • 19.
    #include <iostream> using namespacestd; class Dog { // Dog public: string name; // ( ) void bark(); // ( ) }; //Dog ( ";" ) void Dog::bark() { //Dog bark() // cout << name << " ! " << endl; } int main (int argc, char * const argv[]) { // Dog hachi; //Dog hachi hachi.name = " "; //hachi name " " hachi.bark(); //hachi bark() }
  • 20.
    run [Switching to processxxxx] ! ... Debugger stopped. Program exited with status value:0.
  • 22.
    #include "Dog.h" int main(int argc, char * const argv[]) { // Dog hachi; //Dog hachi hachi.name = " "; //hachi name " " hachi.bark(); //hachi bark() }
  • 23.
    #include <iostream> using namespacestd; class Dog { // Dog public: string name; // ( ) void bark(); // ( ) }; //Dog ( ";" )
  • 24.
    #include "Dog.h" void Dog::bark(){ //Dog bark() // cout << name << " ! " << endl; }
  • 26.
    #ifndef _TEST_APP #define _TEST_APP #include"ofMain.h" class testApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed (int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); }; #endif
  • 27.
    #include "testApp.h" void testApp::setup(){ } void testApp::update(){ } void testApp::draw(){ } void testApp::keyPressed(int key){ } void testApp::keyReleased(int key){ } void testApp::mouseMoved(int x, int y){ } void testApp::mouseDragged(int x, int y, int button){ } void testApp::mousePressed(int x, int y, int button){ } void testApp::mouseReleased(int x, int y, int button){ } void testApp::windowResized(int w, int h){ }
  • 36.
    #ifndef _TEST_APP #define _TEST_APP #include"ofMain.h" #include "ofBlob.h" class testApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed (int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); ofBlob blob; //ofBlob }; #endif
  • 37.
    #include "testApp.h" void testApp::setup(){ // ofBackground(0, 0, 0); ofSetCircleResolution(64); ofEnableAlphaBlending(); ofSetFrameRate(30); } void testApp::update(){ } void testApp::draw(){ blob.draw(); //blob draw() } ...( )
  • 38.
    #ifndef _OF_BLOB #define _OF_BLOB #include"ofMain.h" class ofBlob { public: // method void draw(); }; #endif
  • 39.
    #include "ofBlob.h" void ofBlob::draw() { ofSetColor(31, 63, 255); ofCircle(ofGetWidth()/2, ofGetHeight()/2, 100); }
  • 43.
    #ifndef _TEST_APP #define _TEST_APP #include"ofMain.h" #include "ofBlob.h" class testApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed (int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); ofBlob blob; //ofBlob }; #endif
  • 44.
    #include "testApp.h" void testApp::setup(){ // ofBackground(0, 0, 0); ofSetCircleResolution(32); ofEnableAlphaBlending(); ofSetFrameRate(30); blob.setPos(ofPoint(300, 400)); //blob blob.setDim(80); //blob } void testApp::update(){ } void testApp::draw(){ blob.draw(); //blob draw() } ...( )
  • 45.
    #ifndef _OF_BLOB #define _OF_BLOB #include"ofMain.h" class ofBlob { private: float dim; // ofPoint pos; // public: void setDim(float dim); //dim float getDim(); //dim void setPos(ofPoint pos); //pos ofPoint getPos(); //pos void draw(); // }; #endif
  • 46.
    #include "ofBlob.h" void ofBlob::setDim(float_dim) { dim = _dim; } float ofBlob::getDim() { return dim; } void ofBlob::setPos(ofPoint _pos) { pos = _pos; } ofPoint ofBlob::getPos() { return pos; } void ofBlob::draw() { ofSetColor(31, 63, 255); ofCircle(pos.x, pos.y, dim);
  • 50.
    #ifndef _TEST_APP #define _TEST_APP #include"ofMain.h" #include "ofBlob.h" class testApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed (int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); ofBlob blob; //ofBlob };
  • 51.
    #include "testApp.h" void testApp::setup(){ // ofBackground(0, 0, 0); ofSetCircleResolution(32); ofEnableAlphaBlending(); ofSetFrameRate(30); blob.setPos(ofPoint(300, 400)); //blob blob.setDim(80); //blob blob.setSpeed(ofPoint(8,5)); // } void testApp::update(){ blob.update(); } void testApp::draw(){ blob.draw(); //blob draw() } ...( )
  • 52.
    #ifndef _OF_BLOB #define _OF_BLOB #include"ofMain.h" class ofBlob { private: float dim; // ofPoint pos; // ofPoint speed; // public: void setDim(float dim); //dim float getDim(); //dim void setPos(ofPoint pos); //pos ofPoint getPos(); //pos void setSpeed(ofPoint speed); //speed ofPoint getSpeed(); //speed void update(); // void draw(); // };
  • 53.
    #include "ofBlob.h" void ofBlob::setDim(float_dim) { dim = _dim; } float ofBlob::getDim() { return dim; } void ofBlob::setPos(ofPoint _pos) { pos = _pos; } ofPoint ofBlob::getPos() { return pos; } void ofBlob::setSpeed(ofPoint _speed) {
  • 54.
    ofPoint ofBlob::getSpeed() { return speed; } void ofBlob::update() { pos.x += speed.x; pos.y += speed.y; if(pos.x < dim || pos.x > ofGetWidth()-dim){ speed.x *= -1; } if(pos.y < dim || pos.y > ofGetHeight()-dim){ speed.y *= -1; } } void ofBlob::draw() { ofSetColor(31, 63, 255); ofCircle(pos.x, pos.y, dim); }
  • 58.
    #ifndef _OF_BLOB #define _OF_BLOB #include"ofMain.h" class ofBlob { private: float dim; // ofPoint pos; // ofPoint speed; // float moveDim; // float phase; // float phaseSpeed; // public: ofBlob(); // void setDim(float dim); //dim float getDim(); //dim void setPos(ofPoint pos); //pos ofPoint getPos(); //pos
  • 59.
    ofPoint getSpeed(); //speed void update(); // void draw(); // }; #endif
  • 60.
    #include "ofBlob.h" ofBlob::ofBlob() { phaseSpeed = ofRandom(0.1, 0.2); phase = 0; } void ofBlob::setDim(float _dim) { dim = _dim; } float ofBlob::getDim() { return dim; } void ofBlob::setPos(ofPoint _pos) { pos = _pos; }
  • 61.
    ofPoint ofBlob::getPos() { return pos; } void ofBlob::setSpeed(ofPoint _speed) { speed = _speed; } ofPoint ofBlob::getSpeed() { return speed; } void ofBlob::update() { moveDim = dim + sin(phase)*dim/4; phase += phaseSpeed; if(phase > TWO_PI){ phase -= TWO_PI; } pos.x += speed.x; pos.y += speed.y;
  • 62.
    if(pos.x < dim|| pos.x > ofGetWidth()-dim){ speed.x *= -1; } if(pos.y < dim || pos.y > ofGetHeight()-dim){ speed.y *= -1; } } void ofBlob::draw() { ofSetColor(31, 63, 255, 200); ofCircle(pos.x, pos.y, moveDim); }
  • 65.
    #ifndef _TEST_APP #define _TEST_APP #include"ofMain.h" #include "ofBlob.h" class testApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed (int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); vector <ofBlob> blobs; //ofBlob Vector };
  • 66.
    #include "testApp.h" void testApp::setup(){ ofBackground(0, 0, 0); ofSetCircleResolution(64); ofEnableAlphaBlending(); ofSetFrameRate(30); } void testApp::update(){ for (int i = 0; i < blobs.size(); i++) { blobs[i].update(); } } void testApp::draw(){ for (int i = 0; i < blobs.size(); i++) { blobs[i].draw(); } } ...( )...
  • 67.
    void testApp::mouseReleased(int x,int y, int button){ ofBlob b = ofBlob(); // ofBlob b.setPos(ofPoint(mouseX, mouseY)); // b.setDim(ofRandom(10,40)); // b.setSpeed(ofPoint(ofRandom(-5, 5), ofRandom(-5, 5))); // blobs.push_back(b); } ...( )
  • 68.
    #ifndef _OF_BLOB #define _OF_BLOB #include"ofMain.h" class ofBlob { private: float dim; // ofPoint pos; // ofPoint speed; // float moveDim; // float phase; // float phaseSpeed; // public: ofBlob(); // void setDim(float dim); //dim float getDim(); //dim void setPos(ofPoint pos); //pos ofPoint getPos(); //pos
  • 69.
    ofPoint getSpeed(); //speed void update(); // void draw(); // }; #endif
  • 70.
    #include "ofBlob.h" ofBlob::ofBlob() { phaseSpeed = ofRandom(0.1, 0.2); phase = 0; } void ofBlob::setDim(float _dim) { dim = _dim; } float ofBlob::getDim() { return dim; } void ofBlob::setPos(ofPoint _pos) { pos = _pos; } ofPoint ofBlob::getPos() { return pos;
  • 71.
    void ofBlob::setSpeed(ofPoint _speed) { speed = _speed; } ofPoint ofBlob::getSpeed() { return speed; } void ofBlob::update() { moveDim = dim + sin(phase)*dim/4; phase += phaseSpeed; if(phase > TWO_PI){ phase -= TWO_PI; } pos.x += speed.x; pos.y += speed.y; if(pos.x < dim || pos.x > ofGetWidth()-dim){ speed.x *= -1; } if(pos.y < dim || pos.y > ofGetHeight()-dim){ speed.y *= -1; } }
  • 72.
    void ofBlob::draw() { ofSetColor(31, 63, 255, 80); ofCircle(pos.x, pos.y, moveDim); ofSetColor(255, 63, 31); ofCircle(pos.x, pos.y, dim/10); }
  • 75.
    #ifndef _TEST_APP #define _TEST_APP #include"ofMain.h" #include "ofBlob.h" class testApp : public ofBaseApp { public: void setup(); void update(); void draw(); void keyPressed (int key); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void windowResized(int w, int h); vector <ofBlob> blobs; //ofBlob Vector };
  • 76.
    #include "testApp.h" void testApp::setup(){ ofBackground(0, 0, 0); ofSetCircleResolution(64); ofEnableAlphaBlending(); ofSetFrameRate(30); ofBlob b = ofBlob(); b.setPos(ofPoint(ofGetWidth()/2, ofGetHeight()/2)); b.setDim(ofGetHeight()/3); blobs.push_back(b); } void testApp::update(){ for (int i = 0; i < blobs.size(); i++) { blobs[i].update(); } } void testApp::draw(){ for (int i = 0; i < blobs.size(); i++) { blobs[i].draw(); }
  • 77.
    void testApp::keyPressed(int key){ switch (key) { case 'f': ofSetFullscreen(true); break; } } void testApp::keyReleased(int key){ } void testApp::mouseMoved(int x, int y){ } void testApp::mouseDragged(int x, int y, int button){ } void testApp::mousePressed(int x, int y, int button){ int bSize = blobs.size(); for (int i = 0; i < bSize; i++) { ofPoint p = blobs[i].getPos(); float dist = ofDist(p.x, p.y, mouseX, mouseY); float dim = blobs[i].getDim(); ofPoint pos = blobs[i].getPos();
  • 78.
    if(dist < dim){ // blobs[i].setDim(dim*0.6); blobs[i].setPos(ofPoint(pos.x-dim/2,pos.y-dim/2)); blobs[i].setSpeed(ofPoint(ofRandom(-dim/150,dim/150),ofRandom(-dim/150,dim/ 150))); // 1 ofBlob b1 = ofBlob(); b1.setDim(dim*0.6); b1.setPos(ofPoint(pos.x+dim/2,pos.y+dim/2)); b1.setSpeed(ofPoint(ofRandom(-dim/150,dim/150),ofRandom(-dim/150,dim/ 150))); blobs.push_back(b1); // 2 ofBlob b2 = ofBlob(); b2.setDim(dim*0.6); b2.setPos(ofPoint(pos.x-dim/2,pos.y+dim/2)); b2.setSpeed(ofPoint(ofRandom(-dim/150,dim/150),ofRandom(-dim/150,dim/ 150))); blobs.push_back(b2);
  • 79.
    // 3 ofBlob b3 = ofBlob(); b3.setDim(dim*0.6); b3.setPos(ofPoint(pos.x+dim/2,pos.y-dim/2)); b3.setSpeed(ofPoint(ofRandom(-dim/150,dim/150),ofRandom(-dim/150,dim/ 150))); blobs.push_back(b3); } } } void testApp::mouseReleased(int x, int y, int button){ //ofBlob b = ofBlob(ofPoint(mouseX, mouseY)); //blobs.push_back(b); } void testApp::windowResized(int w, int h){ }
  • 80.
    #ifndef _OF_BLOB #define _OF_BLOB #include"ofMain.h" class ofBlob { private: float dim; // ofPoint pos; // ofPoint speed; // float moveDim; // float phase; // float phaseSpeed; // public: ofBlob(); // void setDim(float dim); //dim float getDim(); //dim void setPos(ofPoint pos); //pos ofPoint getPos(); //pos
  • 81.
    ofPoint getSpeed(); //speed void update(); // void draw(); // }; #endif
  • 82.
    #include "ofBlob.h" ofBlob::ofBlob() { phaseSpeed = ofRandom(0.1, 0.2); phase = 0; } void ofBlob::setDim(float _dim) { dim = _dim; } float ofBlob::getDim() { return dim; } void ofBlob::setPos(ofPoint _pos) { pos = _pos; } ofPoint ofBlob::getPos() { return pos;
  • 83.
    void ofBlob::setSpeed(ofPoint _speed) { speed = _speed; } ofPoint ofBlob::getSpeed() { return speed; } void ofBlob::update() { moveDim = dim + sin(phase)*dim/4; phase += phaseSpeed; if(phase > TWO_PI){ phase -= TWO_PI; } pos.x += speed.x; pos.y += speed.y; if(pos.x < dim || pos.x > ofGetWidth()-dim){ speed.x *= -1; } if(pos.y < dim || pos.y > ofGetHeight()-dim){ speed.y *= -1; } }
  • 84.
    void ofBlob::draw() { ofSetColor(31, 63, 255, 80); ofCircle(pos.x, pos.y, moveDim); ofSetColor(255, 63, 31); ofCircle(pos.x, pos.y, dim/10); }