Created
March 10, 2025 17:16
-
-
Save luizbills/d8eb6306c180e372514b1b4d44501ef8 to your computer and use it in GitHub Desktop.
DOOM fire in 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
// 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]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo