wave2.js 458 B

123456789101112131415161718192021222324
  1. var stage = new mtm.Stage('c'),
  2. angle = 0,
  3. range = 50,
  4. centerY = 150,
  5. speedX = 1, speedY = .05,
  6. posX = 0, posY = 0;
  7. render(stage.ctx, 0, centerY);
  8. stage.play(function(ctx) {
  9. render(ctx, posX, posY);
  10. }, {auto: false});
  11. function render(ctx, startX, startY) {
  12. angle += speedY;
  13. posX += speedX;
  14. posY = centerY + Math.sin(angle) * range;
  15. ctx.beginPath();
  16. ctx.moveTo(startX, startY);
  17. ctx.lineTo(posX, posY);
  18. ctx.stroke();
  19. }