Created
October 4, 2025 13:26
-
-
Save luizbills/53572fb7663b35c8a6965981cb13928a to your computer and use it in GitHub Desktop.
Animated background using Litecanvas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Live Demo