Upgrade to Pro — share decks privately, control downloads, hide ads and more …

tamabi_ma130930.pdf

Atsushi Tadokoro
September 26, 2013
47

 tamabi_ma130930.pdf

Atsushi Tadokoro

September 26, 2013
Tweet

Transcript

  1. ‣ ΦϒδΣΫτࢦ޲ϓϩάϥϛϯά ‣ 0CKFDU0SJFOUFE1SPHSBNNJOH 001 ‣ ΦϒδΣΫτࢦ޲Ͱ1SPDFTTJOHͷϓϩάϥϜΛ࡞Δ ‣ ͦ΋ͦ΋ΦϒδΣΫτࢦ޲ͱ͸ ‣

    ؆୯ͳϓϩάϥϜΛɺΦϒδΣΫτࢦ޲Ͱॻ͍ͯΈΔ ‣ Ϋϥεͷఆٛ ‣ Ϋϥεͷݺͼͩ͠ ΦϒδΣΫτࢦ޲ϓϩάϥϛϯάͱ͸
  2. ‣ 001ͷಛ௃ ‣ ૬ޓʹϝοηʔδΛૹΓ߹͏ʮΦϒδΣΫτʯͷू·Γͱͯ͠ ϓϩάϥϜΛߏ੒ ‣ ΦϒδΣΫτ͸ɺϓϩύςΟͱϝιου͔Βߏ੒͞ΕΔ ‣ ΧϓηϧԽඞཁͷͳ͍৘ใ͸Ӆ͢ ‣

    ΠϯϔϦλϯε ܧঝ ͋ΔΦϒδΣΫτ͕ଞͷΦϒδΣΫ τͷಛੑΛҾ͖ܧ͙ ‣ ϙϦϞʔϑΟζϜ ଟଶੑɾଟ༷ੑ ϓϩάϥϛϯάݴޠͷ ֤ཁૉ͕ෳ਺ͷܕʹଐ͢Δ͜ͱΛڐ͢ ΦϒδΣΫτࢦ޲ϓϩάϥϛϯάͷ֓೦
  3. ‣ ΦϒδΣΫτ ‣ ϓϩύςΟͱϝιου ‣ ΧϓηϧԽ ‣ ܧঝ ΠϯϔϦλϯε ‣

    ଟଶੑɺଟ૬ੑ ϙϦϞʔϑΟζϜ 001ɺͭͷϙΠϯτ
  4. ‣ ΦϒδΣΫτࢦ޲ϓϩάϥϜͷϙΠϯτɿͦͷ ‣ ΦϒδΣΫτ͸ɺϓϩύςΟ ੑ࣭ɺঢ়ଶ ͱɺϝιου ಈ࡞ɺ ;Δ·͍ ͔Βߏ੒͞ΕΔ ঢ়ଶ

    ঢ়ଶ ঢ়ଶ ΦϒδΣΫτ ϝ ι ο υ  ϝ ι ο υ  ϝ ι ο υ  ϝ ι ο υ  001ɿϙΠϯτͦͷ
  5. ‣ ྫɿʮΓΜ͝ʯΛΦϒδΣΫτͱͯ͠ߟ͑Δ ੺  ؁͍ ;͡ ࣮ ͕ ͳ Δ

    ੒ ௕ ͢ Δ མ ͪ Δ ෗ Δ ੨  ͬ͢ͺ͍ ੨Ϧϯΰ ࣮ ͕ ͳ Δ ੒ ௕ ͢ Δ མ ͪ Δ ෗ Δ 001ɿϙΠϯτͦͷ
  6. ‣ ΦϒδΣΫτࢦ޲ϓϩάϥϜͷϙΠϯτɿͦͷ ‣ ඞཁͷͳ͍৘ใ͸Ӆ͢ ΧϓηϧԽ ‣ ϓϩάϥϜͷ࣮૷શͯΛ஌Δඞཁ͸ͳ͍ ‣ ඞཁͳΠϯλʔϑΣΠε ઀఺

    ͚ͩݟͤͯɺ͋ͱ͸Ӆ͢ To invent programs, you need to be able to capture abstractions and ex design. It’s 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 interface—much as a mechanical object separates its interfa illustrated in “Interface and Implementation” . Figure 2-1 Interface and Implementation 9 10 11 8 7 6 implementation interface ΠϯλʔϑΣΠε ࣮૷ 001ɿϙΠϯτͦͷ
  7. ‣ Ϋϥε ‣ Ϋϥεͱ͸ɿΦϒδΣΫτͷʮܕࢴʯ ‣ ΫϥεΛΠϯελϯεԽ ࣮ମԽ ͢Δ͜ͱͰΠϯελϯε ΦϒδΣΫτ ͱͳΔ

    ৭ ॏ͞ H ຯ Ϧϯΰ Ϋϥε ࣮ ͕ ͳ Δ ੒ ௕ ͢ Δ མ ͪ Δ ෗ Δ ੺  ؁͍ ;͡ ΠϯελϯεΦϒδΣΫτ ࣮ ͕ ͳ Δ ੒ ௕ ͢ Δ མ ͪ Δ ෗ Δ ੨  ͬ͢ͺ͍ ੨Ϧϯΰ ΠϯελϯεΦϒδΣΫτ ࣮ ͕ ͳ Δ ੒ ௕ ͢ Δ མ ͪ Δ ෗ Δ ΠϯελϯεԽ Ϋϥε
  8. #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); } 001࣮ફฤΫϥεΛ࡞Δ ‣ UFTU"QQDQQίʔυൈਮ
  9. 001࣮ફฤΫϥεΛ࡞Δ ‣ ͜ͷϓϩάϥϜΛΫϥεԽͯ͠ΈΔ ‣ Ϋϥε໊ɿ1BSUJDMF ‣ ϓϩύςΟ ঢ়ଶɺม਺ ɿ ‣

    PG7FDGQPTJUJPOॳظҐஔ ‣ ϝιου ;Δ·͍ɺؔ਺ ɿ ‣ ESBX  ύʔςΟΫϧΛඳ͘
  10. Ϋϥεͷهड़ ‣ ·ͣ͸ϔομʔϑΝΠϧ 1BSUJDMFI ͔Β ‣ ϨγϐͷࡐྉͱखॱͷҰཡ ‣ ࡐྉˠঢ়ଶɺੑ࣭ˠͭ·ΓɺϓϩύςΟ ม਺

    ‣ खॱˠ;Δ·͍ɺಈ࡞ˠͭ·Γɺϝιου ؔ਺ ‣ ͦͷΫϥεͷϓϩύςΟͱϝιουΛهड़ ‣ ֎෦͔Βࢀর͢Δ΋ͷ͸ɺQVCMJDҎԼʹॻ͘
  11. #pragma once #include "ofMain.h" class Particle { public: void draw();

    ofVec2f position; }; Ϋϥεͷهड़ ‣ 1BSUJDMFI ‣ IUUQTHJTUHJUIVCDPNUBEP
  12. #pragma once #include "ofMain.h" class Particle { public: void draw();

    ofVec2f position; }; Ϋϥεͷهड़ ‣ 1BSUJDMFI ‣ IUUQTHJTUHJUIVCDPNUBEP ΠϯΫϧʔυΨʔυ #VJMEͷࡍʹෳ਺ճಡΈ͜·Εͳ͍ͨΊͷ͘͠Έ
  13. #pragma once #include "ofMain.h" class Particle { public: void draw();

    ofVec2f position; }; Ϋϥεͷهड़ ‣ 1BSUJDMFI ‣ IUUQTHJTUHJUIVCDPNUBEP P'ͷػೳΛ࢖͏ͨΊͷϥΠϒϥϦΛ ඞͣಡΈࠐΉ
  14. #pragma once #include "ofMain.h" class Particle { public: void draw();

    ofVec2f position; }; Ϋϥεͷهड़ ‣ 1BSUJDMFI ‣ IUUQTHJTUHJUIVCDPNUBEP Ϋϥε໊
  15. #pragma once #include "ofMain.h" class Particle { public: void draw();

    ofVec2f position; }; Ϋϥεͷهड़ ‣ 1BSUJDMFI ‣ IUUQTHJTUHJUIVCDPNUBEP QVCMJDҎԼ͸֎෦ʹެ։͞ΕΔ
  16. #pragma once #include "ofMain.h" class Particle { public: void draw();

    ofVec2f position; }; Ϋϥεͷهड़ ‣ 1BSUJDMFI ‣ IUUQTHJTUHJUIVCDPNUBEP ϝιουɿESBX ԁΛඳ͘
  17. #pragma once #include "ofMain.h" class Particle { public: void draw();

    ofVec2f position; }; Ϋϥεͷهड़ ‣ 1BSUJDMFI ‣ IUUQTHJTUHJUIVCDPNUBEP ϓϩύςΟɿQPTJUJPOॳظҐஔ
  18. #pragma once #include "ofMain.h" class Particle { public: void draw();

    ofVec2f position; }; Ϋϥεͷهड़ ‣ 1BSUJDMFI ‣ IUUQTHJTUHJUIVCDPNUBEPpMFPOFQBSUJDMFDMBTTQBSUJDMFI ࠷ޙʹඞͣηϛίϩϯΛ͚ͭΔ
  19. #include "Particle.h" void Particle::draw(){ ofSetHexColor(0x3399cc); ofCircle(position, 10); } Ϋϥεͷهड़ ‣

    1BSUJDMFDQQ ‣ IUUQTHJTUHJUIVCDPNUBEPpMFPOFQBSUJDMFDMBTTQBSUJDMFDQQ
  20. #include "Particle.h" void Particle::draw(){ ofSetHexColor(0x3399cc); ofCircle(position, 10); } Ϋϥεͷهड़ ‣

    1BSUJDMFDQQ ‣ IUUQTHJTUHJUIVCDPNUBEPpMFPOFQBSUJDMFDMBTTQBSUJDMFDQQ ඞͣϔομʔϑΝΠϧΛಡΈࠐΉ
  21. #include "Particle.h" void Particle::draw(){ ofSetHexColor(0x3399cc); ofCircle(position, 10); } Ϋϥεͷهड़ ‣

    1BSUJDMFDQQ ‣ IUUQTHJTUHJUIVCDPNUBEPpMFPOFQBSUJDMFDMBTTQBSUJDMFDQQ ໭Γ஋Ϋϥε໊ؔ਺໊ Ҿ਺ Ϋϥε໊Λ໊લۭؒͱͯ͠࢖༻͍ͯ͠Δ ଞͷΫϥεͷESBX ؔ਺ͱͷࠞಉΛආ͚͍ͯΔ
  22. #include "Particle.h" void Particle::draw(){ ofSetHexColor(0x3399cc); ofCircle(position, 10); } Ϋϥεͷهड़ ‣

    1BSUJDMFDQQ ‣ IUUQTHJTUHJUIVCDPNUBEPpMFPOFQBSUJDMFDMBTTQBSUJDMFDQQ ԁΛඳը
  23. Ϋϥεͷهड़ ‣ ࠷ޙʹ࡞੒ͨ͠ΫϥεΛɺUFTU"QQ͔Βݺͼग़͠·͢ ‣ ϔομʔϑΝΠϧUFTU"QQIͰ.PWF$JSDMFΛએݴ ‣ ͜Ε͚ͩͰɺΫϥε͕࣮ମԽ ΠϯελϯεԽ ͞ΕΔ ‣

    Ϋϥε໊ɿ1BSUJDMF ‣ ΠϯελϯεɿQBSUJDMF ‣ UFTU"QQI ‣ IUUQTHJTUHJUIVCDPNUBEPpMFPOFQBSUJDMFDMBTTUFTUBQQI Particle particle;
  24. Ϋϥεͷهड़ ‣ ϝΠϯͷ࣮૷ϑΝΠϧɺUFTU"QQDQQͰ࡞੒ͨ͠Πϯελϯε Λ࢖༻ͯ͠ԁΛඳ͔ͤΔ ‣ IUUQTHJTUHJUIVCDPNUBEPpMFPOFQBSUJDMFDMBTTUFTUBQQDQQ ‣ UFTU"QQTFUVQ  ͰԁͷॳظҐஔΛࢦఆ

    ‣ UFTU"QQESBX  Ͱ1BSUJDMFͷESBX  ϝιουΛݺͼͩ͠ particle.position.x = ofRandom(ofGetWidth()); particle.position.y = ofRandom(ofGetHeight()); particle.draw();
  25. Ϋϥεͷ഑ྻ ‣ ͋ͱ͸GPSจΛ࢖༻ͯ͠൓෮ͯ͠ॲཧ͍ͯ͘͠ ‣ UFTU"QQTFUVQ ͰॳظԽ ‣ UFTU"QQESBX Ͱඳը ‣

    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(); }
  26. ύʔςΟΫϧγεςϜΛ࡞Δ ‣ 6.-ΫϥεਤͰදݱ 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
  27. WFDUPS ಈత഑ྻ ͷ׆༻ ‣ 1BSUJDMFΫϥεɺ͞ΒʹԠ༻ ‣ ࣍ͷΑ͏ͳΠϯλϥΫγϣϯΛ࣮ݱ͍ͨ͠ ‣ Ϛ΢εΛυϥοά͍ͯ͠ΔؒɺύʔςΟΫϧ͕Ϛ΢εͷ৔ॴ͔ Βੜ੒͞Εଓ͚Δ

    ‣ ੜ੒͞ΕͨύʔςΟΫϧ͸ɺͦͷ··ը໘ʹ࢒Δ ‣ ΩʔϘʔυͰʮDʯͷΩʔΛԡ͢ͱΫϦΞ ‣ 1BSUJDMFͷ഑ྻ͸ɺ͍ͭ֬͘อ͢Ε͹ྑ͍ͷ͔ ‣    ‣ ແݶେͷ"SSBZΛ࡞੒͢Δ͜ͱ͸Ͱ͖ͳ͍ʜ
  28. WFDUPS ಈత഑ྻ ͷ׆༻ ‣ "SSBZͷ਺͕֬ఆ͠ͳ͍ particle[0] particle[1] particle[2]  

     Particle particle[NUM] NUMݸ particle[NUM] → ෆ໌ → ෆ໌ → ෆ໌
  29. WFDUPS ಈత഑ྻ ͷ׆༻ ‣ ഑ྻͷ্ݶͷ਺͕Θ͔Βͳ͍৔߹ ‣ "SSBZ ੩త഑ྻ Ͱ͸ͳ͘ɺཁૉ਺Λࣗ༝ʹมߋͰ͖Δಈతͳ ഑ྻΛ࢖༻͢Δͱศར

    ‣ $ Ͱ͸ʮWFDUPSʯ͕ൺֱతѻ͍΍͍͢ ‣ ʮWFDUPSܕͷछྨ഑ྻ໊ʯͱͳΔ ‣ ྫ1BSUJDMFΫϥεͷಈత഑ྻɺQBSUJDMFΛએݴ vector<Particle> particle;
  30. WFDUPS ಈత഑ྻ ͷ׆༻ ‣ 7FDUPSͷ഑ྻཁૉͷૢ࡞ ‣ ഑ྻͷ຤ඌʹཁૉΛ௥ՃˠQVTI@CBDL ‣ ྫɿ1BSUJDMFͷΦϒδΣΫτQΛɺQBSUJDMFʹ௥Ճ ‣

    ഑ྻͷ຤ඌʹཁૉΛ࡟আˠQPQ@CBDL ‣ ഑ྻͷશͯͷཁૉΛΫϦΞˠDMFBS particle.push_back(p); particle.clear(); particle.pop_back();
  31. WFDUPS ಈత഑ྻ ͷ׆༻ ‣ ࣮૷ྫ ‣ ͪ͜Β΋(JTUΛࢀর 1BSUJDMFΫϥε͸ͦͷ··Ͱ0, ‣ UFTU"QQI

    ‣ IUUQTHJTUHJUIVCDPNUBEPpMFQBSUJDMFWFDUPS UFTUBQQI ‣ UFTU"QQDQQ ‣ IUUQTHJTUHJUIVCDPNUBEPpMFQBSUJDMFWFDUPS UFTUBQQDQQ