Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
#include <iostream>
using namespace std;

class Dog { // Dog
public:
    string name; //        (       )
    void bark();...
software systems.



Interface and Implementation

     To invent programs, you need to be able to capture abstractions an...
::   (   ){
    //
}
#include <iostream>
using namespace std;

class Dog { // Dog
public:
    string name; //         (           )
    void ba...
#include <iostream>
using namespace std;

class Dog { // Dog
public:
    string name; //         (           )
    void ba...
#include <iostream>
using namespace std;

class Dog { // Dog
public:
    string name; //          (           )
    void b...
#include <iostream>
using namespace std;

class Dog { // Dog
public:
    string name; //          (           )
    void b...
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
    ha...
#include <iostream>
using namespace std;

class Dog { // Dog
public:
    string name; //        (       )
    void bark();...
#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();
   ...
#include "testApp.h"

void   testApp::setup(){
}
void   testApp::update(){
}
void   testApp::draw(){
}
void   testApp::key...
#ifndef _TEST_APP
#define _TEST_APP

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

class testApp : public ofBaseApp {
public:
 ...
#include "testApp.h"

void testApp::setup(){
    //
    ofBackground(0, 0, 0);
    ofSetCircleResolution(64);
    ofEnable...
#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:
...
#include "testApp.h"

void testApp::setup(){
  //
    ofBackground(0, 0, 0);
    ofSetCircleResolution(32);
    ofEnableAl...
#ifndef _OF_BLOB
#define _OF_BLOB

#include "ofMain.h"

class ofBlob {

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

pu...
#include "ofBlob.h"

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

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

void of...
#ifndef _TEST_APP
#define _TEST_APP

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

class testApp : public ofBaseApp {

public:
...
#include "testApp.h"

void testApp::setup(){
  //
    ofBackground(0, 0, 0);
    ofSetCircleResolution(32);
    ofEnableAl...
#ifndef _OF_BLOB
#define _OF_BLOB
#include "ofMain.h"

class ofBlob {

private:
   float dim; //
     ofPoint pos; //
    ...
#include "ofBlob.h"

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

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

void of...
ofPoint ofBlob::getSpeed()
{
   return speed;
}

void ofBlob::update()
{
  pos.x += speed.x;
  pos.y += speed.y;
  if(pos....
#ifndef _OF_BLOB
#define _OF_BLOB

#include "ofMain.h"

class ofBlob {

private:
   float dim; //
  ofPoint pos; //
  ofPo...
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)...
ofPoint ofBlob::getPos()
{
   return pos;
}

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

ofPoint ofBlob::...
if(pos.x < dim || pos.x > ofGetWidth()-dim){
       speed.x *= -1;
    }
    if(pos.y < dim || pos.y > ofGetHeight()-dim){...
#ifndef _TEST_APP
#define _TEST_APP


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

class testApp : public ofBaseApp {

public:...
#include "testApp.h"

void testApp::setup(){
  ofBackground(0, 0, 0);
  ofSetCircleResolution(64);
  ofEnableAlphaBlending...
void testApp::mouseReleased(int x, int y, int button){
  ofBlob b = ofBlob(); //    ofBlob
    b.setPos(ofPoint(mouseX, mo...
#ifndef _OF_BLOB
#define _OF_BLOB

#include "ofMain.h"

class ofBlob {

private:
   float dim; //
  ofPoint pos; //
  ofPo...
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)...
void ofBlob::setSpeed(ofPoint _speed)
{
  speed = _speed;
}

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

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


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

class testApp : public ofBaseApp {

public:...
#include "testApp.h"

void testApp::setup(){
  ofBackground(0, 0, 0);
  ofSetCircleResolution(64);
  ofEnableAlphaBlending...
void testApp::keyPressed(int key){
  switch (key) {
     case 'f':
        ofSetFullscreen(true);
        break;
  }
}

vo...
if(dist < dim){
        //
          blobs[i].setDim(dim*0.6);
          blobs[i].setPos(ofPoint(pos.x-dim/2,pos.y-dim/2))...
//   3
            ofBlob b3 = ofBlob();
            b3.setDim(dim*0.6);
            b3.setPos(ofPoint(pos.x+dim/2,pos.y-d...
#ifndef _OF_BLOB
#define _OF_BLOB

#include "ofMain.h"

class ofBlob {

private:
   float dim; //
  ofPoint pos; //
  ofPo...
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)...
void ofBlob::setSpeed(ofPoint _speed)
{
  speed = _speed;
}

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

void ofBlob:...
void ofBlob::draw()
{
  ofSetColor(31, 63, 255, 80);
  ofCircle(pos.x, pos.y, moveDim);
  ofSetColor(255, 63, 31);
  ofCir...
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Sbaw091006
Upcoming SlideShare
Loading in …5
×

Sbaw091006

2,794 views

Published on

  • Be the first to comment

  • Be the first to like this

Sbaw091006

  1. 1. #include <iostream> using namespace std; class Dog { // Dog public: string name; // ( ) void bark(); // ( ) }; //Dog ( ";" ) int main (int argc, char * const argv[]) { // }
  2. 2. 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
  3. 3. :: ( ){ // }
  4. 4. #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[]) { // }
  5. 5. #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 }
  6. 6. #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 " " }
  7. 7. #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() }
  8. 8. run [Switching to process xxxx] ! ... Debugger stopped. Program exited with status value:0.
  9. 9. #include "Dog.h" int main (int argc, char * const argv[]) { // Dog hachi; //Dog hachi hachi.name = " "; //hachi name " " hachi.bark(); //hachi bark() }
  10. 10. #include <iostream> using namespace std; class Dog { // Dog public: string name; // ( ) void bark(); // ( ) }; //Dog ( ";" )
  11. 11. #include "Dog.h" void Dog::bark() { //Dog bark() // cout << name << " ! " << endl; }
  12. 12. #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
  13. 13. #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){ }
  14. 14. #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
  15. 15. #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() } ...( )
  16. 16. #ifndef _OF_BLOB #define _OF_BLOB #include "ofMain.h" class ofBlob { public: // method void draw(); }; #endif
  17. 17. #include "ofBlob.h" void ofBlob::draw() { ofSetColor(31, 63, 255); ofCircle(ofGetWidth()/2, ofGetHeight()/2, 100); }
  18. 18. #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
  19. 19. #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() } ...( )
  20. 20. #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
  21. 21. #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);
  22. 22. #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 };
  23. 23. #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() } ...( )
  24. 24. #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(); // };
  25. 25. #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) {
  26. 26. 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); }
  27. 27. #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
  28. 28. ofPoint getSpeed(); //speed void update(); // void draw(); // }; #endif
  29. 29. #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; }
  30. 30. 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;
  31. 31. 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); }
  32. 32. #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 };
  33. 33. #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(); } } ...( )...
  34. 34. 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); } ...( )
  35. 35. #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
  36. 36. ofPoint getSpeed(); //speed void update(); // void draw(); // }; #endif
  37. 37. #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;
  38. 38. 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; } }
  39. 39. 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); }
  40. 40. #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 };
  41. 41. #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(); }
  42. 42. 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();
  43. 43. 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);
  44. 44. // 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){ }
  45. 45. #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
  46. 46. ofPoint getSpeed(); //speed void update(); // void draw(); // }; #endif
  47. 47. #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;
  48. 48. 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; } }
  49. 49. 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); }

×