Proga 0622

1,277 views

Published on

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,277
On SlideShare
0
From Embeds
0
Number of Embeds
205
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Proga 0622

  1. 1. • F = -kx k F = -kx ma = -kx x = -sin k t m x = Csin(!t + " x
  2. 2. springForce = -stiffness * stretch springForce = -stiffness * (position - restPosition)
  3. 3. • springForce = stiffness * (restPositon - position) velocity = friction * (velocity + springFroce)
  4. 4. 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 }
  5. 5. • F = ma a=F/m acceleration = springForce / mass
  6. 6. //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; //
  7. 7. 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); }
  8. 8. 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;
  9. 9. // noStroke(); fill(255); ellipse(x, y, 40, 40); // stroke(127); noFill(); line(mouseX, mouseY, x, y); // targetX = mouseX; targetY = mouseY; }
  10. 10. //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); }
  11. 11. // 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;
  12. 12. 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); } }
  13. 13. // 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); } }
  14. 14. 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(); }
  15. 15. 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()); } } }
  16. 16. 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]
  17. 17. 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); } } }
  18. 18. 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); } }
  19. 19. 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); } } }
  20. 20. 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()); } } }
  21. 21. 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); } } }
  22. 22. 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()); } } }
  23. 23. 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); } } }
  24. 24. 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()); } } }

×