SlideShare ist ein Scribd-Unternehmen logo
1 von 63
Downloaden Sie, um offline zu lesen
‣
‣


‣
‣


‣
‣

‣
‣
‣
‣
‣
    ‣
    ‣


‣
    ‣
    ‣
‣
‣
    ‣


    ‣
    ‣
    ‣


    ‣
‣
‣
‣
‣
‣
‣
‣
‣
‣
‣
‣
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
‣
‣
‣
‣
‣
‣
‣




    getName()   getName()
‣
    ‣
    ‣
‣
‣
‣
‣


‣
‣
‣
‣
‣



‣
‣
‣

‣
‣
‣
‣
‣
‣


‣


‣
    ‣
    ‣
    ‣

‣
    ‣

    ‣
‣


‣
    ‣
    ‣
    ‣
    ‣
    ‣
    ‣
    ‣
    ‣
‣


‣
    ‣
    ‣
    ‣


‣
    ‣
    ‣
    ‣
‣
#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:
};
‣
#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;
}
‣
//
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);
}
‣
‣


‣
    ‣


‣
    ‣
    ‣
    ‣


‣
    ‣
‣
#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;
};
‣
#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();
}
‣
‣



‣
    ‣
        ‣
    ‣
        ‣
    ‣
        ‣
    ‣
        ‣
‣
void testApp::mousePressed(int x, int y, int button){
! p.setInitialCondition(x,y,ofRandom(-10,10), ofRandom(-10,10));
}
‣
‣


‣
‣
‣
‣
‣
‣



    p[0]
    p[1]
    p[2]   NUM
‣



‣
‣
Particle p[100];




‣
‣

vector <Particle> p;
‣
‣



    Particle p[NUM]

          p[0]
          p[1]
          p[2]        NUM



         p[NUM]
‣
#pragma once

#include "ofMain.h"
#include "Particle.h"

#define NUM 100

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      (NUM )
     Particle p[100];
};
‣
#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();
    }
}
‣



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));
    }
}
‣
‣


    Vector <Particle> particles

             particles[0]
             particles[1]
             particles[2]
‣


‣
‣
    particles.push_back(p);


‣
    particles.pop_back();


‣
    particles.clear();
‣
#pragma once
#include "ofMain.h"
#include "Particle.h"

#define NUM 100

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;
};
‣
#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();
    }
}
‣


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);
    }
}
‣
‣
‣


‣
    ‣
    ‣
    ‣

‣
‣
#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;
};
‣
#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();
    }
}
‣
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);
}
‣
‣


‣
‣
‣
‣
‣
‣
‣


‣


‣
‣
‣


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();
}
‣
‣


‣
‣
‣


‣
    ‣
    ‣
‣
#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;
};
‣
#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();
    }
}
‣
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();
!   }
}
‣



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);
}
‣

Weitere ähnliche Inhalte

Was ist angesagt?

Media Art II openFrameworks 複数のシーンの管理・切替え
Media Art II openFrameworks 複数のシーンの管理・切替えMedia Art II openFrameworks 複数のシーンの管理・切替え
Media Art II openFrameworks 複数のシーンの管理・切替え
Atsushi Tadokoro
 
メディア・アート II 第1回: ガイダンス openFrameworks入門
メディア・アート II 第1回: ガイダンス openFrameworks入門メディア・アート II 第1回: ガイダンス openFrameworks入門
メディア・アート II 第1回: ガイダンス openFrameworks入門
Atsushi Tadokoro
 
Media Art II 2013 第6回:openFrameworks Addonを使う 2 - ofxOpenCV と ofxCv
Media Art II 2013  第6回:openFrameworks Addonを使う 2 - ofxOpenCV と ofxCvMedia Art II 2013  第6回:openFrameworks Addonを使う 2 - ofxOpenCV と ofxCv
Media Art II 2013 第6回:openFrameworks Addonを使う 2 - ofxOpenCV と ofxCv
Atsushi Tadokoro
 
ライブラリ作成のすゝめ - 事例から見る個人OSS開発の効能
ライブラリ作成のすゝめ - 事例から見る個人OSS開発の効能ライブラリ作成のすゝめ - 事例から見る個人OSS開発の効能
ライブラリ作成のすゝめ - 事例から見る個人OSS開発の効能
Yoshifumi Kawai
 
Observable Everywhere - Rxの原則とUniRxにみるデータソースの見つけ方
Observable Everywhere  - Rxの原則とUniRxにみるデータソースの見つけ方Observable Everywhere  - Rxの原則とUniRxにみるデータソースの見つけ方
Observable Everywhere - Rxの原則とUniRxにみるデータソースの見つけ方
Yoshifumi Kawai
 

Was ist angesagt? (20)

Media Art II openFrameworks 複数のシーンの管理・切替え
Media Art II openFrameworks 複数のシーンの管理・切替えMedia Art II openFrameworks 複数のシーンの管理・切替え
Media Art II openFrameworks 複数のシーンの管理・切替え
 
メディア・アート II 第1回: ガイダンス openFrameworks入門
メディア・アート II 第1回: ガイダンス openFrameworks入門メディア・アート II 第1回: ガイダンス openFrameworks入門
メディア・アート II 第1回: ガイダンス openFrameworks入門
 
ももち浜TECHカフェ:OpenCVとKinectで作ろう壁面タッチパネル
ももち浜TECHカフェ:OpenCVとKinectで作ろう壁面タッチパネルももち浜TECHカフェ:OpenCVとKinectで作ろう壁面タッチパネル
ももち浜TECHカフェ:OpenCVとKinectで作ろう壁面タッチパネル
 
Media Art II 2013 第6回:openFrameworks Addonを使う 2 - ofxOpenCV と ofxCv
Media Art II 2013  第6回:openFrameworks Addonを使う 2 - ofxOpenCV と ofxCvMedia Art II 2013  第6回:openFrameworks Addonを使う 2 - ofxOpenCV と ofxCv
Media Art II 2013 第6回:openFrameworks Addonを使う 2 - ofxOpenCV と ofxCv
 
ライブラリ作成のすゝめ - 事例から見る個人OSS開発の効能
ライブラリ作成のすゝめ - 事例から見る個人OSS開発の効能ライブラリ作成のすゝめ - 事例から見る個人OSS開発の効能
ライブラリ作成のすゝめ - 事例から見る個人OSS開発の効能
 
A-Frameで始めるWebXRとハンドトラッキング (HoloLens2/Oculus Quest対応)
A-Frameで始めるWebXRとハンドトラッキング (HoloLens2/Oculus Quest対応)A-Frameで始めるWebXRとハンドトラッキング (HoloLens2/Oculus Quest対応)
A-Frameで始めるWebXRとハンドトラッキング (HoloLens2/Oculus Quest対応)
 
ゲーム開発者のための C++11/C++14
ゲーム開発者のための C++11/C++14ゲーム開発者のための C++11/C++14
ゲーム開発者のための C++11/C++14
 
Effective Modern C++ 勉強会 Item 22
Effective Modern C++ 勉強会 Item 22Effective Modern C++ 勉強会 Item 22
Effective Modern C++ 勉強会 Item 22
 
ビジュアルスクリプティングで始めるUnity入門2日目 ゴールとスコアの仕組み - Unityステーション
ビジュアルスクリプティングで始めるUnity入門2日目 ゴールとスコアの仕組み - Unityステーションビジュアルスクリプティングで始めるUnity入門2日目 ゴールとスコアの仕組み - Unityステーション
ビジュアルスクリプティングで始めるUnity入門2日目 ゴールとスコアの仕組み - Unityステーション
 
シェーダだけで世界を創る!three.jsによるレイマーチング
シェーダだけで世界を創る!three.jsによるレイマーチングシェーダだけで世界を創る!three.jsによるレイマーチング
シェーダだけで世界を創る!three.jsによるレイマーチング
 
Riderはいいぞ!
Riderはいいぞ!Riderはいいぞ!
Riderはいいぞ!
 
ピンホールカメラモデル
ピンホールカメラモデルピンホールカメラモデル
ピンホールカメラモデル
 
アーキテクチャパターンの紹介
アーキテクチャパターンの紹介アーキテクチャパターンの紹介
アーキテクチャパターンの紹介
 
20180527 ORB SLAM Code Reading
20180527 ORB SLAM Code Reading20180527 ORB SLAM Code Reading
20180527 ORB SLAM Code Reading
 
Unity2018/2019における最適化事情
Unity2018/2019における最適化事情Unity2018/2019における最適化事情
Unity2018/2019における最適化事情
 
LiDAR点群とSfM点群との位置合わせ
LiDAR点群とSfM点群との位置合わせLiDAR点群とSfM点群との位置合わせ
LiDAR点群とSfM点群との位置合わせ
 
Observable Everywhere - Rxの原則とUniRxにみるデータソースの見つけ方
Observable Everywhere  - Rxの原則とUniRxにみるデータソースの見つけ方Observable Everywhere  - Rxの原則とUniRxにみるデータソースの見つけ方
Observable Everywhere - Rxの原則とUniRxにみるデータソースの見つけ方
 
プログラムを高速化する話Ⅱ 〜GPGPU編〜
プログラムを高速化する話Ⅱ 〜GPGPU編〜プログラムを高速化する話Ⅱ 〜GPGPU編〜
プログラムを高速化する話Ⅱ 〜GPGPU編〜
 
今日からできる!簡単 .NET 高速化 Tips
今日からできる!簡単 .NET 高速化 Tips今日からできる!簡単 .NET 高速化 Tips
今日からできる!簡単 .NET 高速化 Tips
 
1076: CUDAデバッグ・プロファイリング入門
1076: CUDAデバッグ・プロファイリング入門1076: CUDAデバッグ・プロファイリング入門
1076: CUDAデバッグ・プロファイリング入門
 

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

openFrameworks – 関数・クラス、オブジェクト指向プログラミング導入 - 多摩美メディアアートII
openFrameworks – 関数・クラス、オブジェクト指向プログラミング導入 - 多摩美メディアアートIIopenFrameworks – 関数・クラス、オブジェクト指向プログラミング導入 - 多摩美メディアアートII
openFrameworks – 関数・クラス、オブジェクト指向プログラミング導入 - 多摩美メディアアートII
Atsushi Tadokoro
 
openFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollider
openFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollideropenFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollider
openFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollider
Atsushi Tadokoro
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
Tomek Kaczanowski
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
calderoncasto9163
 
mobl: Een DSL voor mobiele applicatieontwikkeling
mobl: Een DSL voor mobiele applicatieontwikkelingmobl: Een DSL voor mobiele applicatieontwikkeling
mobl: Een DSL voor mobiele applicatieontwikkeling
Devnology
 
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Robot Media
 

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

openFrameworks – 関数・クラス、オブジェクト指向プログラミング導入 - 多摩美メディアアートII
openFrameworks – 関数・クラス、オブジェクト指向プログラミング導入 - 多摩美メディアアートIIopenFrameworks – 関数・クラス、オブジェクト指向プログラミング導入 - 多摩美メディアアートII
openFrameworks – 関数・クラス、オブジェクト指向プログラミング導入 - 多摩美メディアアートII
 
Of class1
Of class1Of class1
Of class1
 
Sbaw091020
Sbaw091020Sbaw091020
Sbaw091020
 
BCSL 058 solved assignment
BCSL 058 solved assignmentBCSL 058 solved assignment
BCSL 058 solved assignment
 
openFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollider
openFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollideropenFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollider
openFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollider
 
Of class3
Of class3Of class3
Of class3
 
Of class2
Of class2Of class2
Of class2
 
Sbaw090623
Sbaw090623Sbaw090623
Sbaw090623
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
662305 11
662305 11662305 11
662305 11
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
C Language Lecture 17
C Language Lecture 17C Language Lecture 17
C Language Lecture 17
 
Calculator code with scientific functions in java
Calculator code with scientific functions in java Calculator code with scientific functions in java
Calculator code with scientific functions in java
 
HTML5って必要?
HTML5って必要?HTML5って必要?
HTML5って必要?
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
Java awt
Java awtJava awt
Java awt
 
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdfJAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
JAVA...With N.E.T_B.E.A.N.S___________________________________.pdf
 
mobl: Een DSL voor mobiele applicatieontwikkeling
mobl: Een DSL voor mobiele applicatieontwikkelingmobl: Een DSL voor mobiele applicatieontwikkeling
mobl: Een DSL voor mobiele applicatieontwikkeling
 
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
 
Cpds lab
Cpds labCpds lab
Cpds lab
 

Mehr von Atsushi Tadokoro

「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
Atsushi Tadokoro
 
プログラム初級講座 - メディア芸術をはじめよう
プログラム初級講座 - メディア芸術をはじめようプログラム初級講座 - メディア芸術をはじめよう
プログラム初級講座 - メディア芸術をはじめよう
Atsushi Tadokoro
 
Interactive Music II ProcessingとSuperColliderの連携 -2
Interactive Music II ProcessingとSuperColliderの連携 -2Interactive Music II ProcessingとSuperColliderの連携 -2
Interactive Music II ProcessingとSuperColliderの連携 -2
Atsushi Tadokoro
 
coma Creators session vol.2
coma Creators session vol.2coma Creators session vol.2
coma Creators session vol.2
Atsushi Tadokoro
 
Interactive Music II ProcessingとSuperColliderの連携1
Interactive Music II ProcessingとSuperColliderの連携1Interactive Music II ProcessingとSuperColliderの連携1
Interactive Music II ProcessingとSuperColliderの連携1
Atsushi Tadokoro
 
Interactive Music II Processingによるアニメーション
Interactive Music II ProcessingによるアニメーションInteractive Music II Processingによるアニメーション
Interactive Music II Processingによるアニメーション
Atsushi Tadokoro
 
Interactive Music II Processing基本
Interactive Music II Processing基本Interactive Music II Processing基本
Interactive Music II Processing基本
Atsushi Tadokoro
 
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
Atsushi Tadokoro
 
Media Art II openFrameworks アプリ間の通信とタンジブルなインターフェイス
Media Art II openFrameworks  アプリ間の通信とタンジブルなインターフェイス Media Art II openFrameworks  アプリ間の通信とタンジブルなインターフェイス
Media Art II openFrameworks アプリ間の通信とタンジブルなインターフェイス
Atsushi Tadokoro
 
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
Atsushi Tadokoro
 
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描くiTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
Atsushi Tadokoro
 
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリメディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
Atsushi Tadokoro
 
芸術情報演習デザイン(Web) 第8回: CSSフレームワークを使う
芸術情報演習デザイン(Web)  第8回: CSSフレームワークを使う芸術情報演習デザイン(Web)  第8回: CSSフレームワークを使う
芸術情報演習デザイン(Web) 第8回: CSSフレームワークを使う
Atsushi Tadokoro
 
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
Atsushi Tadokoro
 
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
Atsushi Tadokoro
 
Webデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
Webデザイン 第10回:HTML5実践 Three.jsで3DプログラミングWebデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
Webデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
Atsushi Tadokoro
 
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
Atsushi Tadokoro
 
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画するiTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
Atsushi Tadokoro
 
Interactive Music II SuperCollider実習 オリジナルの楽器を作ろう!
Interactive Music II SuperCollider実習  オリジナルの楽器を作ろう!Interactive Music II SuperCollider実習  オリジナルの楽器を作ろう!
Interactive Music II SuperCollider実習 オリジナルの楽器を作ろう!
Atsushi Tadokoro
 

Mehr von Atsushi Tadokoro (20)

「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
「クリエイティブ・ミュージック・コーディング」- オーディオ・ビジュアル作品のための、オープンソースなソフトウエア・フレームワークの現状と展望
 
プログラム初級講座 - メディア芸術をはじめよう
プログラム初級講座 - メディア芸術をはじめようプログラム初級講座 - メディア芸術をはじめよう
プログラム初級講座 - メディア芸術をはじめよう
 
Interactive Music II ProcessingとSuperColliderの連携 -2
Interactive Music II ProcessingとSuperColliderの連携 -2Interactive Music II ProcessingとSuperColliderの連携 -2
Interactive Music II ProcessingとSuperColliderの連携 -2
 
coma Creators session vol.2
coma Creators session vol.2coma Creators session vol.2
coma Creators session vol.2
 
Interactive Music II ProcessingとSuperColliderの連携1
Interactive Music II ProcessingとSuperColliderの連携1Interactive Music II ProcessingとSuperColliderの連携1
Interactive Music II ProcessingとSuperColliderの連携1
 
Interactive Music II Processingによるアニメーション
Interactive Music II ProcessingによるアニメーションInteractive Music II Processingによるアニメーション
Interactive Music II Processingによるアニメーション
 
Interactive Music II Processing基本
Interactive Music II Processing基本Interactive Music II Processing基本
Interactive Music II Processing基本
 
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
Interactive Music II SuperCollider応用 2 - SuperColliderとPure Dataの連携
 
Media Art II openFrameworks アプリ間の通信とタンジブルなインターフェイス
Media Art II openFrameworks  アプリ間の通信とタンジブルなインターフェイス Media Art II openFrameworks  アプリ間の通信とタンジブルなインターフェイス
Media Art II openFrameworks アプリ間の通信とタンジブルなインターフェイス
 
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
Interactive Music II SuperCollider応用 - SuperColliderと OSC (Open Sound Control)
 
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描くiTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
iTamabi 13 ARTSAT API 実践 5 - 衛星の軌道を描く
 
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリメディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
メディア芸術基礎 II 第11回:HTML5実践 表現のための様々なJavaScriptライブラリ
 
芸術情報演習デザイン(Web) 第8回: CSSフレームワークを使う
芸術情報演習デザイン(Web)  第8回: CSSフレームワークを使う芸術情報演習デザイン(Web)  第8回: CSSフレームワークを使う
芸術情報演習デザイン(Web) 第8回: CSSフレームワークを使う
 
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 2
 
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
iTamabi 13 第9回:ARTSAT API 実践 3 ジオコーディングで衛星の位置を取得
 
Tamabi media131118
Tamabi media131118Tamabi media131118
Tamabi media131118
 
Webデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
Webデザイン 第10回:HTML5実践 Three.jsで3DプログラミングWebデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
Webデザイン 第10回:HTML5実践 Three.jsで3Dプログラミング
 
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
Interactive Music II SuperCollider応用 JITLib - ライブコーディング 1
 
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画するiTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
iTamabi 13 第8回:ARTSAT API 実践 2 衛星アプリを企画する
 
Interactive Music II SuperCollider実習 オリジナルの楽器を作ろう!
Interactive Music II SuperCollider実習  オリジナルの楽器を作ろう!Interactive Music II SuperCollider実習  オリジナルの楽器を作ろう!
Interactive Music II SuperCollider実習 オリジナルの楽器を作ろう!
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

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

  • 1.
  • 3.
  • 4. ‣ ‣ ‣ ‣ ‣ ‣ ‣
  • 5.
  • 6. ‣ ‣ ‣ ‣ ‣
  • 10.
  • 11. 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
  • 13. ‣ ‣ ‣ ‣ getName() getName()
  • 14. ‣ ‣
  • 18.
  • 21. ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣
  • 22. ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣
  • 23. ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣
  • 24. ‣ #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: };
  • 25. ‣ #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; }
  • 26. ‣ // 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); }
  • 27. ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣
  • 28. ‣ #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; };
  • 29. ‣ #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(); }
  • 30.
  • 31. ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣ ‣
  • 32. ‣ void testApp::mousePressed(int x, int y, int button){ ! p.setInitialCondition(x,y,ofRandom(-10,10), ofRandom(-10,10)); }
  • 33.
  • 35.
  • 36. ‣ ‣ ‣ ‣ p[0] p[1] p[2] NUM
  • 38. ‣ ‣ Particle p[NUM] p[0] p[1] p[2] NUM p[NUM]
  • 39. ‣ #pragma once #include "ofMain.h" #include "Particle.h" #define NUM 100 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 (NUM ) Particle p[100]; };
  • 40. ‣ #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(); } }
  • 41. ‣ 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)); } }
  • 42.
  • 43. Vector <Particle> particles particles[0] particles[1] particles[2]
  • 44. ‣ ‣ ‣ particles.push_back(p); ‣ particles.pop_back(); ‣ particles.clear();
  • 45. ‣ #pragma once #include "ofMain.h" #include "Particle.h" #define NUM 100 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; };
  • 46. ‣ #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(); } }
  • 47. ‣ 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); } }
  • 48.
  • 49. ‣ ‣ ‣ ‣ ‣ ‣ ‣
  • 50. ‣ #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; };
  • 51. ‣ #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(); } }
  • 52. ‣ 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); }
  • 53.
  • 56. ‣ 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(); }
  • 57.
  • 59. ‣ #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; };
  • 60. ‣ #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(); } }
  • 61. ‣ 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(); ! } }
  • 62. ‣ 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); }
  • 63.