メディア・アートII 第3回 openFrameworks基礎 OOoF : オブジェクト指向 oF

download メディア・アートII 第3回 openFrameworks基礎 OOoF : オブジェクト指向 oF

If you can't read please download the document

Transcript of メディア・アートII 第3回 openFrameworks基礎 OOoF : オブジェクト指向 oF

  • 1. II 3 openFrameworks OOoF : oF 2013930

2. ! 3. Gist https://gist.github.com/tado/6709400 Gist - GitHub 4. OOoF = Object Oriented + openFrameworks 5. Object Oriented Programming (OOP) Processing ? ? 6. 7. OOP - () - () - 8. () () OOP5 9. 1 OOP1 10. 2 ()( ) 1 2 3 1 2 3 4 OOP2 11. 5.0 4.0 OOP2 12. 3 () () To invent programs, you need to be able to capture abstractions and ex design. Its the job of a programming language to help you do this. The process of invention and design by letting you encode abstractions tha It should let you make your ideas concrete in the code you write. Surf the architecture of your program. All programming languages provide devices that help express abstrac are ways of grouping implementation details, hiding them, and giving a common interfacemuch as a mechanical object separates its interfa illustrated in Interface and Implementation . Figure 2-1 Interface and Implementation 9 10 11 8 7 6 implementationinterface OOP3 13. 4 () OOP4 14. 5 () getName() A getName() B OOP5 15. () () (g) () 5.0 () 4.0 () 16. testApp - setup(), update(), draw() ...etc. - testApp testApp setup() update() draw () exit() testApp 17. testApp ..etc. testApp testApp testApp 18. testApp testApp Rectangle Particle Control Panel 19. OOP 20. OOP - 1() OOP 21. OOP - 1 https://gist.github.com/tado/6709701 22. #include "testApp.h" void testApp::setup(){ // ofSetFrameRate(60); ofBackground(63); ofSetCircleResolution(32); // position.x = ofRandom(ofGetWidth()); position.y = ofRandom(ofGetHeight()); } ... void testApp::draw(){ // ofSetHexColor(0x3399cc); ofCircle(position, 10); } OOP - testApp.cpp - 23. OOP - Particle () ofVec2f position : () draw( ) : 24. OOP - (UML) Particle + position:ofVec2f + draw():void 25. OOP - Xcode ! 26. OOP - src New File () 27. OOP - Mac OS X > C and C++ > C++ File 28. OOP - Particlesrc 29. OOP - 30. 31. (Particle.h) ! () () public: 32. #pragma once #include "ofMain.h" class Particle { public: void draw(); ofVec2f position; }; Particle.h https://gist.github.com/tado/6710045 33. #pragma once #include "ofMain.h" class Particle { public: void draw(); ofVec2f position; }; Particle.h https://gist.github.com/tado/6710045 Build 34. #pragma once #include "ofMain.h" class Particle { public: void draw(); ofVec2f position; }; Particle.h https://gist.github.com/tado/6710045 oF 35. #pragma once #include "ofMain.h" class Particle { public: void draw(); ofVec2f position; }; Particle.h https://gist.github.com/tado/6710045 36. #pragma once #include "ofMain.h" class Particle { public: void draw(); ofVec2f position; }; Particle.h https://gist.github.com/tado/6710045 public: 37. #pragma once #include "ofMain.h" class Particle { public: void draw(); ofVec2f position; }; Particle.h https://gist.github.com/tado/6710045 draw() - 38. #pragma once #include "ofMain.h" class Particle { public: void draw(); ofVec2f position; }; Particle.h https://gist.github.com/tado/6710045 position - 39. #pragma once #include "ofMain.h" class Particle { public: void draw(); ofVec2f position; }; Particle.h https://gist.github.com/tado/6710045#le-oneparticleclass01-particle-h 40. (Particle.cpp) draw() 41. #include "Particle.h" void Particle::draw(){ ofSetHexColor(0x3399cc); ofCircle(position, 10); } Particle.cpp https://gist.github.com/tado/6710045#le-oneparticleclass01-particle-cpp 42. #include "Particle.h" void Particle::draw(){ ofSetHexColor(0x3399cc); ofCircle(position, 10); } Particle.cpp https://gist.github.com/tado/6710045#le-oneparticleclass01-particle-cpp 43. #include "Particle.h" void Particle::draw(){ ofSetHexColor(0x3399cc); ofCircle(position, 10); } Particle.cpp https://gist.github.com/tado/6710045#le-oneparticleclass01-particle-cpp ::() draw() 44. #include "Particle.h" void Particle::draw(){ ofSetHexColor(0x3399cc); ofCircle(position, 10); } Particle.cpp https://gist.github.com/tado/6710045#le-oneparticleclass01-particle-cpp 45. testApp testApp.h MoveCircle () Particle particle testApp.h https://gist.github.com/tado/6710045#le-oneparticleclass01-testapp-h Particle particle; 46. testApp.cpp https://gist.github.com/tado/6710045#le-oneparticleclass01-testapp-cpp testApp::setup( ) testApp::draw( ) Particledraw( ) particle.position.x = ofRandom(ofGetWidth()); particle.position.y = ofRandom(ofGetHeight()); particle.draw(); 47. !! 48. 49. 1() = = 100Particle static const int NUM = 100; Particle particle[NUM]; 50. (Array) particle[0] particle[1] particle[2] . . . Particle particle[NUM] NUM particle[NUM] 51. for testApp::setup() testApp::draw() for(int i = 0; i < NUM; i++){ float posX = ofRandom(ofGetWidth()); float posY = ofRandom(ofGetHeight()); particle[i].setup(ofVec2f(posX, posY)); } for(int i = 0; i < NUM; i++){ particle[i].draw(); } 52. 1100 Particle testApp.h https://gist.github.com/tado/6710857#le-particlearray-testapp-h testApp.cpp https://gist.github.com/tado/6710857#le-particlearray-testapp-cpp 53. !! 54. - 1 55. ! ! void setInit(); void resetForce(); void updateForce(); void updatePos(); void checkBounds(); 56. ! UML Particle + position:ofVec2f + velocity:ofVec2f + force:ofVec2f + friction:float + radius:float + setup(ofVec2f position, ofVec2f velocity):void + resetForce():void + addForce(ofVec2f force):void + updateForce():void + updatePos():void + checkBounds(float xmin, float ymin, float xmax, float ymax):void + draw():void 57. ! Particle Github https://gist.github.com/tado/6711018 58. ! Particle1 59. ! Github testApp.h https://gist.github.com/tado/6711076#le-particlesystem- example01-testapp-h testApp.cpp https://gist.github.com/tado/6711076#le-particlesystem- example01-testapp-cpp 60. ! !! 61. - 2 vector () 62. vector () Particle : c Particle? 1000? 10000? 1000000? Array 63. vector () Array particle[0] particle[1] particle[2] . . . Particle particle[NUM] NUM particle[NUM] 64. vector () Array () C++ vector vector : Particleparticle vector particle; 65. vector () vector () particle[0] particle[1] particle[2] . . . vector particle 66. vector () Vector push_back() Particlepparticle pop_back() clear() particle.push_back(p); particle.clear(); particle.pop_back(); 67. vector () Gist (ParticleOK!) testApp.h https://gist.github.com/tado/6712412#le-particlevector- testapp-h testApp.cpp https://gist.github.com/tado/6712412#le-particlevector- testapp-cpp 68. vector () !! 69. - 3 70. 71. Particle testApp.h https://gist.github.com/tado/6714705#le-particlesystem- image-test-h testApp.cpp https://gist.github.com/tado/6714705#le-particlesystem- image-test-cpp 72. !! 73. ofBeginShape() ofCurveVertex() ... ofEndShape() 74. testApp.cpp draw() testApp.cpp https://gist.github.com/tado/6714750#le-particlesystem- line-test-cpp 75. ! 76. !! 2 3 : ofVec2f (x, y) ofVec3d (x, y, z)