• Like
Sbaw091006
Upcoming SlideShare
Loading in...5
×

Sbaw091006

  • 2,294 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
2,294
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
20
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. #include <iostream> using namespace std; class Dog { // Dog public: string name; // ( ) void bark(); // ( ) }; //Dog ( ";" ) int main (int argc, char * const argv[]) { // }
  • 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. :: ( ){ // }
  • 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. #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. #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. #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. run [Switching to process xxxx] ! ... Debugger stopped. Program exited with status value:0.
  • 9. #include "Dog.h" int main (int argc, char * const argv[]) { // Dog hachi; //Dog hachi hachi.name = " "; //hachi name " " hachi.bark(); //hachi bark() }
  • 10. #include <iostream> using namespace std; class Dog { // Dog public: string name; // ( ) void bark(); // ( ) }; //Dog ( ";" )
  • 11. #include "Dog.h" void Dog::bark() { //Dog bark() // cout << name << " ! " << endl; }
  • 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. #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. #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. #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. #ifndef _OF_BLOB #define _OF_BLOB #include "ofMain.h" class ofBlob { public: // method void draw(); }; #endif
  • 17. #include "ofBlob.h" void ofBlob::draw() { ofSetColor(31, 63, 255); ofCircle(ofGetWidth()/2, ofGetHeight()/2, 100); }
  • 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. #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. #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. #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. #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. #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. #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. #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. 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. #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. ofPoint getSpeed(); //speed void update(); // void draw(); // }; #endif
  • 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. 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. 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. #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. #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. 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. #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. ofPoint getSpeed(); //speed void update(); // void draw(); // }; #endif
  • 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. 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. 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. #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. #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. 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. 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. // 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. #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. ofPoint getSpeed(); //speed void update(); // void draw(); // }; #endif
  • 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. 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. 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); }