2c9e78e18fc19b483e2bda395ec610664761c4701a7231af70a8c74312962ab7b458c2456a7b30989871d3ae61716781b52af35edf1a810e5653a3ad0a29cd 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf8" />
  5. <title>launchAnimation</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. function randomNum (minNum, maxNum) {
  24. switch (arguments.length) {
  25. case 1:
  26. return parseInt(Math.random() * minNum + 1, 10)
  27. case 2:
  28. return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10)
  29. default:
  30. return 0
  31. }
  32. }
  33. const circles = new Array(100).fill(0).map(foo => render.add({
  34. name: 'circle',
  35. animationCurve: 'easeOutCubic',
  36. shape: {
  37. rx: randomNum(0, w),
  38. ry: randomNum(0, h),
  39. r: 10
  40. },
  41. style: {
  42. fill: '#ffee97',
  43. stroke: 'goldenrod',
  44. lineWidth: 2
  45. }
  46. }))
  47. function wait (time) {
  48. return new Promise(resolve => setTimeout(resolve, time))
  49. }
  50. async function start () {
  51. await wait(1000)
  52. circles.forEach(circle => circle.animation('shape', {
  53. rx: randomNum(0, w),
  54. ry: randomNum(0, h)
  55. }, true))
  56. render.launchAnimation()
  57. }
  58. start()
  59. </script>
  60. </html>