Skip to content

Commit

Permalink
feat: async for init anim
Browse files Browse the repository at this point in the history
  • Loading branch information
psemsari committed May 2, 2023
1 parent 1e7dda2 commit cd7fe97
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/Anim.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { fabric } from 'fabric'

async function Init(obj, canvas) {
// // update position
if (obj.get('top') > window.innerHeight)
{
obj.vy = Math.random() * 10 + 2
obj.set({left: Math.floor(Math.random() * canvas.width) - 50, top: -100})
}
else
obj.set({top: obj.get('top') + obj.vy})
}

function Anim() {

let canvas = new fabric.StaticCanvas('c', {
Expand All @@ -16,15 +27,8 @@ function Anim() {

// update velocity
canvas.getObjects().forEach((obj) => {

// // update position
if (obj.get('top') > window.innerHeight)
{
obj.vy = Math.random() * 10 + 2
obj.set({left: Math.floor(Math.random() * canvas.width) - 50, top: -100})
}
else
obj.set({top: obj.get('top') + obj.vy})
Init(obj, canvas)
})
fabric.util.requestAnimFrame(update)
canvas.renderAll()
Expand Down

0 comments on commit cd7fe97

Please sign in to comment.