distance.js 484 B

123456789101112131415161718192021222324
  1. var stage = new mtm.Stage('c'),
  2. shape, shape1, shape2;
  3. for (var i = 0; i<2; i++) {
  4. shape = new Rect();
  5. shape.x = Math.random() * stage.width;
  6. shape.y = Math.random() * stage.height;
  7. stage.shapes.push(shape);
  8. }
  9. stage.play(function() {
  10. shape1 = stage.shapes[0];
  11. shape2 = stage.shapes[1];
  12. var dx = shape1.x - shape2.x,
  13. dy = shape1.y - shape2.y,
  14. dist = Math.sqrt(dx*dx + dy*dy);
  15. stage.render();
  16. stage.stop();
  17. console.log(dist);
  18. }, {auto: false});