12

canvas cherry blossom petals falling animation

 2 years ago
source link: https://codepen.io/rudtjd2548/pen/qBpVzxP
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

canvas cherry blossom petals falling animation

0 unsaved changes
xxxxxxxxxx
<canvas></canvas>
xxxxxxxxxx
html, body {
  width: 100%;
  height: 100%;
  background-color: #1a1a1a;
}
xxxxxxxxxx
const canvas = document.querySelector('canvas')
canvas.width = window.innerWidth
canvas.height = window.innerHeight
const ctx = canvas.getContext('2d')
const TOTAL = 100
const petalArray = []
const petalImg = new Image()
petalImg.src = 'https://djjjk9bjm164h.cloudfront.net/petal.png'
petalImg.addEventListener('load', () => {
  for (let i = 0; i < TOTAL; i++) {
    petalArray.push(new Petal())
  }
  render()
})
function render() {
  ctx.clearRect(0, 0, canvas.width, canvas.height)
  petalArray.forEach(petal => petal.animate())
  window.requestAnimationFrame(render)

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK