Skip to content

Commit

Permalink
Get image layers in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans5958 committed Jun 20, 2023
1 parent a3a64f7 commit 21da09f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions web/_js/main/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,20 @@ async function updateBackground(newPeriod = currentPeriod, newVariation = curren
}
const canvas = document.createElement('canvas')
const context = canvas.getContext('2d')
for await (const url of layerUrls) {

layers.length = layerUrls.length
await Promise.all(layerUrls.map(async (url, i) => {
const imageLayer = new Image()
await new Promise(resolve => {
imageLayer.onload = () => {
context.canvas.width = Math.max(imageLayer.width, context.canvas.width)
context.canvas.height = Math.max(imageLayer.height, context.canvas.height)
layers.push(imageLayer)
layers[i] = imageLayer
resolve()
}
imageLayer.src = url
})
}
}))

for (const imageLayer of layers) {
context.drawImage(imageLayer, 0, 0)
Expand Down

0 comments on commit 21da09f

Please sign in to comment.