openFrameworks 動きを生みだす様々なアルゴリズム - 多摩美メディアアートII
Upcoming SlideShare
Loading in...5
×
 

openFrameworks 動きを生みだす様々なアルゴリズム - 多摩美メディアアートII

on

  • 9,085 views

 

Statistics

Views

Total Views
9,085
Views on SlideShare
3,336
Embed Views
5,749

Actions

Likes
16
Downloads
140
Comments
0

8 Embeds 5,749

http://yoppa.org 2855
http://yoppa.org 2855
http://paper.li 14
https://twitter.com 11
http://a0.twimg.com 6
http://a0.twimg.com 6
http://us-w1.rockmelt.com 1
http://us-w1.rockmelt.com 1
More...

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

openFrameworks 動きを生みだす様々なアルゴリズム - 多摩美メディアアートII openFrameworks 動きを生みだす様々なアルゴリズム - 多摩美メディアアートII Presentation Transcript

  • ‣ ‣‣ ‣ ‣ ‣ ‣ ‣ ‣
  • ‣‣‣
  • ‣‣‣ http://goo.gl/zyfQR (Google Docs ) View slide
  • ‣‣ View slide
  • ‣‣‣void testApp::mouseMoved(int x, int y ){! prevMouseX = x;! prevMouseY = y;}void testApp::mouseDragged(int x, int y, int button){! //1! float dx = x - prevMouseX;! float dy = y - prevMouseY;!! //! particle myParticle;! myParticle.setInitialCondition(x,y, dx*0.5,dy*0.5);! //! particles.push_back(myParticle);!! //! prevMouseX = x;! prevMouseY = y;!}
  • ‣‣‣
  • ‣‣‣ F -F
  • ‣‣void particle::bounceOffWalls(){! //! float minx = 0;! float miny = 0;! float maxx = ofGetWidth();! float maxy = ofGetHeight();! //! if (pos.x > maxx){! ! pos.x = maxx;! ! vel.x *= -1;! } else if (pos.x < minx){! ! pos.x = minx;! ! vel.x *= -1;! }! //! if (pos.y > maxy){! ! pos.y = maxy;! ! vel.y *= -1;! } else if (pos.y < miny){! ! pos.y = miny;! ! vel.y *= -1;! }}
  • ‣‣‣ F = -kx‣ k F = -kx ma = -kx x = -sin k t m x = Csin(ωt + θ x
  • ‣‣ springForce = -stiffness * stretch‣ = - *‣‣ springForce = -stiffness * (position - restPosition)‣
  • ‣‣ springForce = stiffness * (restPositon - position)‣‣ velocity = dumping * (velocity + springFroce)
  • ‣‣‣‣
  • ‣‣‣void spring::update(){! if ((particleA == NULL) || (particleB == NULL)){! ! return;! }!! ofVec2f pta = particleA->pos;! ofVec2f ptb = particleB->pos;!! float theirDistance = (pta - ptb).length();! float springForce = (springiness * (distance - theirDistance));! ofVec2f frcToAdd = (pta-ptb).normalized() * springForce;!! particleA->addForce(frcToAdd.x, frcToAdd.y);! particleB->addForce(-frcToAdd.x, -frcToAdd.y);}
  • ‣‣void testApp::setup(){!!! ofBackground(0,0,0);!! ofSetVerticalSync(true);! ofSetFrameRate(60);! //Particle A! particle_a.setInitialCondition(400, 400, 0, 0);!! //Particle B! particle_b.setInitialCondition(500, 500, 0, 0);! // (spring)! mySpring.distance = 100; //! mySpring.springiness = 0.1f; //! mySpring.particleA = &particle_a;! mySpring.particleB = &particle_b;}
  • ‣‣void testApp::update(){!! //! particle_a.resetForce();! particle_b.resetForce();!! //! mySpring.update();!! // ( )! particle_a.bounceOffWalls();! particle_a.update();!! particle_b.bounceOffWalls();! particle_b.update();}
  • ‣‣void testApp::draw(){! ofSetColor(255, 255, 255);!! //! mySpring.draw();!! //particle! particle_a.draw();! particle_b.draw();}
  • ‣‣
  • ‣‣‣
  • ‣‣void testApp::setup(){!! ofBackground(0,0,0);! ofSetVerticalSync(true);! ofSetFrameRate(60);! ofSetBackgroundAuto(false);! pimg.loadImage("particle32.png");! //particle! for (int i = 0; i < 20; i++){! ! particle myParticle;! ! myParticle.setInitialCondition(ofRandom(500,550),ofRandom(500,550),0,0);! ! particles.push_back(myParticle);! }!! // spring! for (int i = 0; i < (particles.size()-1); i++){! ! spring mySpring;! ! mySpring.distance = 25;! ! mySpring.springiness = 0.2f;! ! mySpring.particleA = & (particles[i]);! ! mySpring.particleB = & (particles[(i+1)%particles.size()]);! ! springs.push_back(mySpring);! }}
  • ‣‣void testApp::update(){! // particle! for (int i = 0; i < particles.size(); i++){! ! particles[i].resetForce();! }! //! for (int i = 0; i < springs.size(); i++){! ! springs[i].update();! }!! // particle! for (int i = 0; i < particles.size(); i++){! ! particles[i].addDampingForce();! ! particles[i].bounceOffWalls();! ! particles[i].update();! }}
  • ‣‣void testApp::draw(){! //! ofSetColor(255, 255, 255, 127);! for (int i = 0; i < springs.size(); i++){! ! springs[i].draw();! }!! // particle! ofSetColor(255, 255, 255);! for (int i = 0; i < particles.size(); i++){! ! particles[i].draw();! }!}
  • ‣‣‣ ‣ ‣‣
  • ‣‣
  • ‣‣‣‣ ‣ ‣ ‣‣‣
  • ‣int fieldWidthint fieldHeightint fieldSizeint externalWidthint externalHeightvector field
  • ‣vectorField();virtual ~vectorField();void setupField(int innerW, int innerH,int outerW, int outerH);void clear();void fadeField(float fadeAmount);void randomizeField(float scale);void draw();ofVec2f getForceFromPos(float xpos, floatypos);
  • ‣void addOutwardCircle(float x, float y,float radius, float strength);void addInwardCircle(float x, float y,float radius, float strength);void addClockwiseCircle(float x, float y,float radius, float strength);void addCounterClockwiseCircle(float x,float y, float radius, float strength);void addVectorCircle(float x, float y,float vx, float vy, float radius, floatstrength);
  • ‣‣ ‣ ‣ ‣ ‣‣
  • ‣‣oid testApp::setup(){!!! ofSetVerticalSync(true);! ofSetFrameRate(60);! ofBackground(0, 0, 0);!! // ( 102 76 )! VF.setupField(102, 76, ofGetWidth(), ofGetHeight());! //! addMode = 1;}
  • ‣‣void testApp::draw(){! //! ofEnableBlendMode(OF_BLENDMODE_ADD);! ofSetColor(0,130,130, 200);! VF.draw();! ofDisableBlendMode();!}
  • ‣‣‣
  • ‣‣void testApp::setup(){!!! ofSetVerticalSync(true);! ofSetFrameRate(60);! ofBackground(0, 0, 0);!! // 10000! for (int i = 0; i < 10000; i++){! ! particle myParticle;! ! myParticle.setInitialCondition! ! (ofRandom(0,ofGetWidth()),ofRandom(0,ofGetHeight()),0,0);! ! particles.push_back(myParticle);! }!! // ( 102 76 )! VF.setupField(102, 76, ofGetWidth(), ofGetHeight());!! //! addMode = 2;}
  • ‣‣void testApp::update(){!! for (int i = 0; i < particles.size(); i++){! !! ! //particle! ! particles[i].resetForce();! !! ! // particle! ! ofVec2f frc;! ! frc = VF.getForceFromPos(particles[i].pos.x, particles[i].pos.y);! !! ! //Particle! ! particles[i].addForce(frc.x, frc.y);! ! particles[i].addDampingForce();! ! particles[i].bounceOffWalls();! ! particles[i].update();! }!! //! VF.fadeField(0.998f);}
  • ‣‣void testApp::draw(){!! ofEnableBlendMode(OF_BLENDMODE_ADD);!! //! ofSetColor(0,130,130, 127);! VF.draw();!! // particle! ofSetColor(0, 127, 255)! ;! for (int i = 0; i < particles.size(); i++){! ! particles[i].draw();! }!!! ofDisableBlendMode();!}
  • ‣‣
  • ‣‣void testApp::mouseDragged(int x, int y, int button){!! float diffx = x - prevMouseX;! float diffy = y - prevMouseY;!! VF.addVectorCircle((float)x, (float)y, diffx*0.3, diffy*0.3, 60, 0.3f);!! prevMouseX = x;! prevMouseY = y;}
  • ‣‣‣ http://www.msavisuals.com/msafluid
  • ‣‣‣‣‣‣ http://www.red3d.com/cwr/boids/
  • ‣ ‣ ‣ ‣ ‣ ‣ ‣
  • ‣‣‣
  • ‣void particle::addFlockingForce(){! // seperation! if(seperation.count > 0){! ! seperation.sum /= (float)seperation.count;! ! float sepFrc ! = seperation.strength;! ! frc -= (seperation.sum.normalized() * sepFrc);! }!! // alignment! if(alignment.count > 0){! ! alignment.sum /= (float)alignment.count;! ! float alignFrc ! = alignment.strength;! ! frc += (alignment.sum! ! * alignFrc);! }!! // cohesion! if(cohesion.count > 0){! ! cohesion.sum /= (float)cohesion.count;! ! cohesion.sum -= pos;! ! float cohFrc ! = cohesion.strength;! ! frc += (cohesion.sum.normalized() * cohFrc);! }!}
  • ‣void particle::addForFlocking(particle &p){!! ofVec3f diff, diffNormalized;! float distance;!! diff! ! ! = p.pos - pos;! distance! ! = diff.length();! diffNormalized! = diff;! diffNormalized.normalize();! if( distance > 0 && distance < seperation.distance ){! ! seperation.sum += diffNormalized;! ! seperation.count++;! }!! if( distance > 0 && distance < alignment.distance ){! ! alignment.sum += p.vel.getNormalized();! ! alignment.count++;! }!! if( distance > 0 && distance < cohesion.distance ){! ! cohesion.sum += p.pos;! ! cohesion.count++;! }}