Proga 0622
Upcoming SlideShare
Loading in...5
×
 

Proga 0622

on

  • 1,693 views

 

Statistics

Views

Total Views
1,693
Views on SlideShare
1,495
Embed Views
198

Actions

Likes
1
Downloads
2
Comments
0

6 Embeds 198

http://yoppa.org 167
http://yoppa.jpn.org 24
http://www.slideshare.net 4
https://www.mturk.com 1
http://www.yoppa.org 1
http://translate.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

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

Proga 0622 Proga 0622 Presentation Transcript

  • • 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 = friction * (velocity + springFroce) View slide
  • float stiffness = 0.1; // float damping = 0.9; // float velocity = 0.0; // float targetY; // float y; // void setup() { size(400, 400); noStroke(); } void draw() { fill(0, 12); rect(0, 0, width, height); fill(255); float force = stiffness * (targetY - y); // f = -kx velocity = damping * (velocity + force); // y += velocity; // rect(10, y, width - 20, 10); // targetY = mouseY; // Y } View slide
  • • F = ma a=F/m acceleration = springForce / mass
  • //2 float y1, y2; // float velocity1, velocity2; // float mass1 = 1.0; // 1 float mass2 = 6.0; // 2 float stiffness = 0.1; // float damping = 0.9; // void setup() { size(400, 400); noStroke(); } void draw() { fill(0, 12); rect(0, 0, width, height); fill(255); float targetY = mouseY; // // 1 float forceA = stiffness * (targetY - y1); // float accelerationY1 = forceA / mass1; // velocity1 = damping * (velocity1 + accelerationY1); // y1 += velocity1; //
  • rect(0, y1, width/2, 15); // 2 float forceB = stiffness * (targetY - y2); // float accelerationY2 = forceB / mass2; // velocity2 = damping * (velocity2 + accelerationY2); // y2 += velocity2; // rect(width/2, y2, width/2, 15); }
  • float stiffness = 0.05; float damping = 0.9; float mass = 3.0; float gravity = 0.0; float velocityX = 0.0, velocityY = 0.0; float targetX, targetY; float x, y; void setup() { size(600, 600); smooth(); } void draw() { background(0); //X float forceX = stiffness * (targetX - x); float accelerationX = forceX / mass; velocityX = damping * (velocityX + accelerationX); x += velocityX; //Y float forceY = stiffness * (targetY - y); forceY += gravity; float accelerationY = forceY / mass; velocityY = damping * (velocityY + accelerationY); y += velocityY;
  • // noStroke(); fill(255); ellipse(x, y, 40, 40); // stroke(127); noFill(); line(mouseX, mouseY, x, y); // targetX = mouseX; targetY = mouseY; }
  • //Spring2D Spring2D s1, s2; float gravity = 5.0; float mass = 2.0; void setup() { size(400, 400); smooth(); fill(0); // x , y , , s1 = new Spring2D(0.0, width / 2, mass, gravity); s2 = new Spring2D(0.0, width / 2, mass, gravity); } void draw() { background(204); s1.update(mouseX, mouseY); s1.display(mouseX, mouseY); s2.update(s1.x, s1.y); s2.display(s1.x, s1.y); }
  • // class Spring2D // class Spring2D { float vx, vy; float x, y; float gravity; float mass; float radius = 10; float stiffness = 0.2; float damping = 0.7; // Spring2D(float xpos, float ypos, float m, float g) { x = xpos; y = ypos; mass = m; gravity = g; } // void update(float targetX, float targetY) { float forceX = (targetX - x) * stiffness; float ax = forceX / mass; vx = damping * (vx + ax); x += vx; float forceY = (targetY - y) * stiffness;
  • forceY += gravity; float ay = forceY / mass; vy = damping * (vy + ay); y += vy; } // void display(float nx, float ny) { noStroke(); ellipse(x, y, radius*2, radius*2); stroke(255); line(x, y, nx, ny); } }
  • // int numSprings = 10; // Spring2D[] s = new Spring2D[numSprings]; float gravity = 5.0; float mass = 5.0; float stiffness = 0.2; float damping = 0.8; void setup() { size(600, 600); smooth(); fill(0); for (int i = 0; i < numSprings; i++) { s[i] = new Spring2D(width / 2, i*(height / numSprings), mass, gravity, stiffness, damping); } } void draw() { background(204); s[0].update(mouseX, mouseY); s[0].display(mouseX, mouseY); for (int i = 1; i < numSprings; i++) { s[i].update(s[i-1].x, s[i-1].y); s[i].display(s[i-1].x, s[i-1].y); } }
  • import traer.physics.*; ParticleSystem physics; Particle mouse; Particle[] p; Spring[] s; void setup(){ size( 400, 400 ); smooth(); //Physics physics = new ParticleSystem( 1.0, 0.05 ); p = new Particle[10]; s = new Spring[10]; // for(int i = 0; i < p.length; i++){ p[i] = physics.makeParticle( 1.0, width/2, 20 * i, 0); if(i > 0){ s[i] = physics.makeSpring( p[i], p[i-1], 1.0, 0.1, 20); } } // p[0].makeFixed(); }
  • void draw(){ background(0); physics.tick(); // p[0].moveTo(mouseX, mouseY, 0); // for(int i = 0; i < p.length; i++){ noStroke(); fill(128); ellipse( p[i].position().x(), p[i].position().y(), 10, 10 ); if(i > 0){ stroke(255); line(p[i].position().x(), p[i].position().y(), p[i-1].position().x(), p[i-1].position().y()); } } }
  • p[0] p[1] p[2] p[3] ... p[n] p[1] p[2] p[3] p[4] for(int i = 0; i < n; i++){ ... • • for(j = i + 1; j < n; j++){ p[n] • p[2] p[3] • } p[4] • } p[5] ... ... p[n] p[n]
  • import processing.opengl.*; import traer.physics.*; ParticleSystem physics; Particle[] particles; int num = 80; void setup(){ size(800, 800, OPENGL ); fill(255); smooth(); rectMode(CENTER); physics = new ParticleSystem(0, 0.0); particles = new Particle[num]; for (int i = 0; i < num; i++){ particles[i] = physics.makeParticle(0.2, random(width), random(height), 0); for (int j = i + 1; j < num; j++){ particles[j] = physics.makeParticle(0.2, random(width), random(height), 0); particles[j].setMass(0.5); physics.makeSpring(particles[i], particles[j], 0.1, 0.0, width/2); } } }
  • void draw(){ physics.tick(0.01); background(0); for (int i = 0; i < num; i++){ rect(particles[i].position().x(), particles[i].position().y(), 8, 8); } }
  • import processing.opengl.*; import traer.physics.*; ParticleSystem physics; Particle[] particles; int num = 80; void setup(){ size(800, 800, OPENGL ); fill(255); smooth(); rectMode(CENTER); physics = new ParticleSystem(0, 0.0); particles = new Particle[num]; for (int i = 0; i < num; i++){ particles[i] = physics.makeParticle(0.2, random(width), random(height), 0); for (int j = i + 1; j < num; j++){ particles[j] = physics.makeParticle(0.2, random(width), random(height), 0); particles[j].setMass(0.5); physics.makeSpring(particles[i], particles[j], 0.1, 0.0, width/2); } } }
  • void draw(){ physics.tick(0.01); background(0); for (int i = 0; i < num; i++){ fill(255); noStroke(); rect(particles[i].position().x(), particles[i].position().y(), 8, 8); stroke(127,50); //Spring line for (int j = i + 1; j < num; j++){ line(particles[j].position().x(), particles[j].position().y(), particles[i].position().x(), particles[i].position().y()); } } }
  • import processing.opengl.*; import traer.physics.*; ParticleSystem physics; Particle[] particles; int num = 80; void setup(){ size(800, 800, OPENGL ); fill(255); smooth(); rectMode(CENTER); physics = new ParticleSystem(0, 0.0); particles = new Particle[num]; for (int i = 0; i < num; i++){ particles[i] = physics.makeParticle(0.2, random(width), random(height), 0); for (int j = i + 1; j < num; j++){ particles[j] = physics.makeParticle(0.2, random(width), random(height), 0); particles[j].setMass(0.5); physics.makeSpring(particles[i], particles[j], 0.1, 0.0, width/2); } } }
  • void draw(){ physics.tick(0.01); background(0); for (int i = 0; i < num; i++){ rect(particles[i].position().x(), particles[i].position().y(), 4, 4); for (int j = i + 1; j < num; j++){ float l = dist(particles[j].position().x(), particles[j].position().y(), particles[i].position().x(), particles[i].position().y()); stroke(255, 100 - l); line(particles[j].position().x(), particles[j].position().y(), particles[i].position().x(), particles[i].position().y()); } } }
  • import processing.opengl.*; import traer.physics.*; ParticleSystem physics; Particle[] particles; int num = 80; void setup(){ size(800, 800, OPENGL ); smooth(); fill(255); rectMode(CENTER); physics = new ParticleSystem(0, 0.0); particles = new Particle[num]; for (int i = 0; i < num; i++){ particles[i] = physics.makeParticle(0.2, random(width), random(height), 0); for (int j = i + 1; j < num; j++){ particles[j] = physics.makeParticle(0.2, random(width), random(height), 0); particles[j].setMass(0.5); physics.makeAttraction(particles[i], particles[j], 1000, width); } } }
  • void draw(){ physics.tick(1); background(0); for (int i = 0; i < num; i++) { rect(particles[i].position().x(), particles[i].position().y(), 3, 3); for (int j = i + 1; j < num; j++) { float l = dist(particles[j].position().x(), particles[j].position().y(), particles[i].position().x(), particles[i].position().y()); stroke(255, 100 - l); line(particles[j].position().x(), particles[j].position().y(), particles[i].position().x(), particles[i].position().y()); } } }