Skip to content

Instantly share code, notes, and snippets.

@luizbills
Created March 10, 2025 17:16
Show Gist options
  • Save luizbills/d8eb6306c180e372514b1b4d44501ef8 to your computer and use it in GitHub Desktop.
Save luizbills/d8eb6306c180e372514b1b4d44501ef8 to your computer and use it in GitHub Desktop.
DOOM fire in Litecanvas
// based on https://fabiensanglard.net/doom_fire_psx/
const FIRE_WIDTH = 128;
const FIRE_HEIGHT = 128;
litecanvas({
width: FIRE_WIDTH,
})
const firePalette = [0,0,0,0,0,0,10,10,10,10,10,10,10,10,4,4,4,4,4,4,4,4,5,5,5,5,5,5,3,3,3,3],
firePixels = []
console.log(firePalette.toString())
function init() {
setfps(30)
for(let i = 0; i < FIRE_WIDTH*FIRE_HEIGHT; i++) {
firePixels[i] = 0;
}
for(let i = 0; i < FIRE_WIDTH; i++) {
firePixels[(FIRE_HEIGHT-1)*FIRE_WIDTH + i] = firePalette.length-1;
}
}
function update(dt) {
for(x = 0 ; x < FIRE_WIDTH; x++) {
for (y = 1; y < FIRE_HEIGHT ; y++) {
let from = (y * FIRE_WIDTH + x);
let rand = randi(0,3) & 3;
let to = from - FIRE_WIDTH - rand + 1 ;
firePixels[to] = firePixels[from] - (rand & 1);
}
}
}
function draw() {
cls(0)
for(let h = 0; h < FIRE_HEIGHT; h++) {
for(let w = 0; w < FIRE_WIDTH; w++) {
let p = firePixels[h * FIRE_WIDTH + w];
if (p >= 0) {
rectfill(w, h, 1, 1, firePalette[p]);
}
}
}
}
@luizbills
Copy link
Author

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