c42bbce227b66f064de77b1edc36551654cca7715b507f1a3bf6b8de6aef620f1df5f6b90a2e00725236fba63327ece17154213fbc88d68f43218fe4953f50 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf8" />
  5. <title>Polyline Closed</title>
  6. <style>
  7. html, body, #canvas {
  8. width: 100%;
  9. height: 100%;
  10. margin: 0px;
  11. padding: 0px;
  12. }
  13. </style>
  14. <script src="../../dist/crender.map.js"></script>
  15. </head>
  16. <body>
  17. <canvas id="canvas"></canvas>
  18. </body>
  19. <script>
  20. const { CRender, extendNewGraph } = window.CRender
  21. const render = new CRender(document.querySelector('#canvas'))
  22. const [w, h] = render.area
  23. const topPos = h / 3
  24. const bottom = h / 3 * 2
  25. const gap = w / 10
  26. const beginX = w / 2 - gap * 2
  27. const points = new Array(5).fill('').map((t, i) =>
  28. [beginX + gap * i, i % 2 === 0 ? topPos : bottom])
  29. points[2][1] += top * 1.3
  30. const pointsAfter = new Array(5).fill('').map((t, i) =>
  31. [beginX + gap * i, i % 2 === 0 ? bottom : topPos])
  32. pointsAfter[2][1] -= top * 1.3
  33. const polyline = render.add({
  34. name: 'polyline',
  35. animationCurve: 'easeOutCubic',
  36. animationFrame: 50,
  37. drag: true,
  38. hover: true,
  39. shape: {
  40. points,
  41. close: true
  42. },
  43. style: {
  44. fill: '#ffee97',
  45. stroke: 'goldenrod',
  46. lineWidth: 2
  47. }
  48. })
  49. function wait (time) {
  50. return new Promise(resolve => setTimeout(resolve, time))
  51. }
  52. async function start () {
  53. await wait(1000)
  54. await polyline.animation('shape', {
  55. points: pointsAfter
  56. })
  57. await wait(1000)
  58. polyline.animation('style', {
  59. fill: 'lemonchiffon'
  60. })
  61. }
  62. start()
  63. </script>
  64. </html>