multi-curves3.js 634 B

1234567891011121314151617181920212223242526272829
  1. var stage = new mtm.Stage('c'),
  2. points = [],
  3. numPoints = 9,
  4. ctx = stage.ctx;
  5. for (var i=0; i < numPoints; i++) {
  6. points[i] = {
  7. x: Math.random() * stage.height,
  8. y: Math.random() * stage.height
  9. };
  10. }
  11. ctx.beginPath();
  12. var xc1 = (points[0].x + points[numPoints-1].x) / 2,
  13. yc1 = (points[0].y + points[numPoints-1].y) / 2;
  14. ctx.moveTo(xc1, yc1);
  15. for (var i=0; i<numPoints-1; i++) {
  16. var xc = (points[i].x + points[i+1].x) / 2,
  17. yc = (points[i].y + points[i+1].y) / 2;
  18. ctx.quadraticCurveTo(points[i].x, points[i].y, xc, yc);
  19. }
  20. ctx.quadraticCurveTo(points[i].x, points[i].y, xc1, yc1);
  21. ctx.stroke();