Your SlideShare is downloading. ×
openFrameworks – パーティクルを動かす、静的配列と動的配列 - 多摩美メディアアートII
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

openFrameworks – パーティクルを動かす、静的配列と動的配列 - 多摩美メディアアートII

6,477
views

Published on

Published in: Technology, Business

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,477
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
135
Comments
0
Likes
3
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. ‣‣‣‣‣‣‣‣‣
  • 2. ‣‣ ‣ ‣‣ ‣ ‣
  • 3.
  • 4. ‣ ‣ ‣ ‣ ‣ ‣
  • 5. ‣‣‣‣‣
  • 6. ‣‣‣
  • 7. ‣‣
  • 8.
  • 9. 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 Inte rfa ce a nd Im ple m e nta tion interface implementation 11 10 9 8 7 6
  • 10. ‣‣‣
  • 11. ‣‣‣‣ getName() getName()
  • 12. ‣ ‣ ‣
  • 13. ‣‣‣
  • 14. ‣‣
  • 15. ‣‣
  • 16. ‣‣‣‣‣‣‣‣
  • 17. ‣‣
  • 18. ‣‣‣ ‣ ‣ ‣‣ ‣ ‣
  • 19. ‣‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣
  • 20. ‣‣ ‣ ‣ ‣‣ ‣ ‣ ‣
  • 21. ‣#pragma once#include "ofMain.h"class Particle {public:! ofVec2f pos; // ofVec2f vel; // ofVec2f frc; // ( ) float damping; // Particle(); virtual ~Particle(){}; void resetForce(); void addForce(float x, float y); void addDampingForce(); void setInitialCondition(float px, float py, float vx, float vy); void update(); void draw();protected:private:};
  • 22. ‣#include "Particle.h"// ( )Particle::Particle(){! setInitialCondition(0,0,0,0);! damping = 0.01f;}// ( )void Particle::resetForce(){ frc.set(0,0);}//void Particle::addForce(float x, float y){ frc.x = frc.x + x; frc.y = frc.y + y;}//void Particle::addDampingForce(){ frc.x = frc.x - vel.x * damping; frc.y = frc.y - vel.y * damping;}
  • 23. ‣//void Particle::setInitialCondition(float px, float py, float vx, float vy){ pos.set(px,py);! vel.set(vx,vy);}//void Particle::update(){!! vel = vel + frc;! pos = pos + vel;}//void Particle::draw(){ ofCircle(pos.x, pos.y, 3);}
  • 24. ‣‣‣ ‣‣ ‣ ‣ ‣‣ ‣
  • 25. ‣#pragma once#include "ofMain.h"#include "Particle.h"class testApp : public ofSimpleApp{!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(); // Particle Particle p;};
  • 26. ‣#include "testApp.h"void testApp::setup(){!! ofSetVerticalSync(true);! ofSetFrameRate(60);! ofBackground(0, 0, 0);! p.setInitialCondition(ofGetWidth()/2, ofGetHeight()/2, ofRandom(-10,10), ofRandom(-10,10));}void testApp::update(){! p.resetForce();! p.addDampingForce();! p.update();}void testApp::draw(){! ofSetColor(255, 255, 255);! p.draw();}
  • 27.
  • 28. ‣‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣
  • 29. ‣void testApp::mousePressed(int x, int y, int button){! p.setInitialCondition(x,y,ofRandom(-10,10), ofRandom(-10,10));}
  • 30.
  • 31. ‣‣‣
  • 32. ‣‣‣‣ p[0] p[1] p[2] NUM
  • 33. ‣‣‣Particle p[100];‣‣vector <Particle> p;
  • 34. ‣‣ Particle p[NUM] p[0] p[1] p[2] NUM p[NUM]
  • 35. ‣#pragma once#include "ofMain.h"#include "Particle.h"#define NUM 100class testApp : public ofSimpleApp{!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(); // Particle (NUM ) Particle p[100];};
  • 36. ‣#include "testApp.h"void testApp::setup(){!! ofSetVerticalSync(true);! ofSetFrameRate(60);! ofBackground(0, 0, 0);}void testApp::update(){ for (int i = 0; i < NUM; i++) { p[i].resetForce(); p[i].addForce(0, 0.1); p[i].addDampingForce(); p[i].update(); }}void testApp::draw(){! ofSetColor(255, 255, 255); for (int i = 0; i < NUM; i++) { p[i].draw(); }}
  • 37. ‣void testApp::mousePressed(int x, int y, int button){ for (int i = 0; i < NUM; i++) { p[i].setInitialCondition(x, y, ofRandom(-10,10), ofRandom(-10,10)); }}
  • 38.
  • 39. ‣ Vector <Particle> particles particles[0] particles[1] particles[2]
  • 40. ‣‣‣ particles.push_back(p);‣ particles.pop_back();‣ particles.clear();
  • 41. ‣#pragma once#include "ofMain.h"#include "Particle.h"#define NUM 100class testApp : public ofSimpleApp{!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(); // Particle particles vector <Particle> particles;};
  • 42. ‣#include "testApp.h"void testApp::setup(){!! ofSetVerticalSync(true);! ofSetFrameRate(60);! ofBackground(0, 0, 0);}void testApp::update(){ for (int i = 0; i < particles.size(); i++) { particles[i].resetForce(); particles[i].addForce(0, 0.1); particles[i].addDampingForce(); particles[i].update(); }}void testApp::draw(){! ofSetColor(255, 255, 255); for (int i = 0; i < particles.size(); i++) { particles[i].draw(); }}
  • 43. ‣void testApp::mousePressed(int x, int y, int button){ particles.clear(); for (int i = 0; i < NUM; i++) { //Particle → myParticle Particle myParticle; // float vx = ofRandom(-10, 10); float vy = ofRandom(-10, 10); myParticle.setInitialCondition(x, y, vx, vy); // particles.push_back(myParticle); }}
  • 44.
  • 45. ‣‣‣ ‣ ‣ ‣‣
  • 46. ‣#pragma once#include "ofMain.h"#include "Particle.h"class testApp : public ofSimpleApp{!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(); // Particle particles vector <Particle> particles;};
  • 47. ‣#include "testApp.h"void testApp::setup(){!! ofSetVerticalSync(true);! ofSetFrameRate(60);! ofBackground(0, 0, 0);}void testApp::update(){ for (int i = 0; i < particles.size(); i++) { particles[i].resetForce(); particles[i].addDampingForce(); particles[i].update(); }}void testApp::draw(){! ofSetColor(255, 255, 255);! //! string message = "current particle num = " + ofToString(particles.size(),0);! ofDrawBitmapString(message, 20, 20); for (int i = 0; i < particles.size(); i++) { particles[i].draw(); }}
  • 48. ‣void testApp::keyPressed (int key){! //c! if (key == c) {! ! particles.clear();! }! //f! if (key == f) {! ! ofToggleFullscreen();! }}void testApp::mouseDragged(int x, int y, int button){! //! Particle myParticle;! float vx = ofRandom(-3, 3);! float vy = ofRandom(-3, 3);! myParticle.setInitialCondition(x, y, vx, vy);! particles.push_back(myParticle);}
  • 49.
  • 50. ‣‣‣‣‣‣‣
  • 51. ‣‣‣‣
  • 52. ‣void testApp::draw(){! ofSetColor(255, 255, 255);! //! string message = "current particle num = "! + ofToString(particles.size(),0);! ofDrawBitmapString(message, 20, 20);!! ofNoFill();! ofBeginShape();! for (int i = 0; i < particles.size(); i++){! ! ofCurveVertex(particles[i].pos.x, particles[i].pos.y);! }! ofEndShape();}
  • 53.
  • 54. ‣‣‣‣‣ ‣ ‣
  • 55. ‣#pragma once#include "ofMain.h"#include "Particle.h"class testApp : public ofSimpleApp{!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(); // Particle particles vector <Particle> particles;! //! ofImage img;};
  • 56. ‣#include "testApp.h"void testApp::setup(){!! ofSetVerticalSync(true);! ofSetFrameRate(60);! ofBackground(0, 0, 0);! ofEnableBlendMode(OF_BLENDMODE_ADD);! //! img.loadImage("particle32.png");}void testApp::update(){ for (int i = 0; i < particles.size(); i++) { particles[i].resetForce(); particles[i].addDampingForce(); particles[i].update(); }}
  • 57. ‣void testApp::draw(){! //! ofSetColor(255, 255, 255);! string message = "current particle num = " + ofToString(particles.size(),0);! ofDrawBitmapString(message, 20, 20);! //! for (int i = 0; i < particles.size(); i++){! ! float posx = particles[i].pos.x - 16;! ! float posy = particles[i].pos.y - 16;! ! img.draw(posx, posy);! }}void testApp::keyPressed (int key){! //c! if (key == c) {! ! particles.clear();! }! //f! if (key == f) {! ! ofToggleFullscreen();! }}
  • 58. ‣void testApp::mouseDragged(int x, int y, int button){! //! Particle myParticle;! float vx = ofRandom(-1, 1);! float vy = ofRandom(-1, 1);! myParticle.setInitialCondition(x, y, vx, vy);! particles.push_back(myParticle);}
  • 59.