Skip to content

Instantly share code, notes, and snippets.

@luizbills
Created October 4, 2025 13:26
Show Gist options
  • Select an option

  • Save luizbills/53572fb7663b35c8a6965981cb13928a to your computer and use it in GitHub Desktop.

Select an option

Save luizbills/53572fb7663b35c8a6965981cb13928a to your computer and use it in GitHub Desktop.
Animated background using Litecanvas
let pos = {},
speed = 100,
ts = 32,
bg
litecanvas({
width: 320,
autoscale: 0
})
function init() {
pos.x = 0
pos.y = 0
bg = paint(W+ts*2,H+ts*2,(ctx) => {
const w = ctx.canvas.width
const h = ctx.canvas.height
for (let y = 0; y < floor(h/ts); y++) {
for (let x = 0; x < floor(w/ts); x++) {
rectfill(x*ts,y*ts,ts,ts,(x+y)%2===0?1:2)
}
}
})
}
function update(dt) {
pos.x += speed * dt
pos.y += speed * dt
pos.x = wrap(pos.x, 0, ts*2)
pos.y = wrap(pos.y, 0, ts*2)
}
function draw() {
cls(0)
image(-pos.x, -pos.y, bg)
}
@luizbills
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment