| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf8" />
- <title>Polyline Closed</title>
- <style>
- html, body, #canvas {
- width: 100%;
- height: 100%;
- margin: 0px;
- padding: 0px;
- }
- </style>
- <script src="../../dist/crender.map.js"></script>
- </head>
- <body>
- <canvas id="canvas"></canvas>
- </body>
- <script>
- const { CRender, extendNewGraph } = window.CRender
- const render = new CRender(document.querySelector('#canvas'))
- const [w, h] = render.area
- const topPos = h / 3
- const bottom = h / 3 * 2
- const gap = w / 10
- const beginX = w / 2 - gap * 2
- const points = new Array(5).fill('').map((t, i) =>
- [beginX + gap * i, i % 2 === 0 ? topPos : bottom])
- points[2][1] += top * 1.3
- const pointsAfter = new Array(5).fill('').map((t, i) =>
- [beginX + gap * i, i % 2 === 0 ? bottom : topPos])
- pointsAfter[2][1] -= top * 1.3
- const polyline = render.add({
- name: 'polyline',
- animationCurve: 'easeOutCubic',
- animationFrame: 50,
- drag: true,
- hover: true,
- shape: {
- points,
- close: true
- },
- style: {
- fill: '#ffee97',
- stroke: 'goldenrod',
- lineWidth: 2
- }
- })
- function wait (time) {
- return new Promise(resolve => setTimeout(resolve, time))
- }
- async function start () {
- await wait(1000)
- await polyline.animation('shape', {
- points: pointsAfter
- })
- await wait(1000)
- polyline.animation('style', {
- fill: 'lemonchiffon'
- })
- }
- start()
- </script>
- </html>
|