Skip to content

Instantly share code, notes, and snippets.

View luizbills's full-sized avatar

Luiz Bills luizbills

View GitHub Profile
@luizbills
luizbills / code.js
Created October 20, 2026 17:50
requests persistent browser storage
async function requestPersistentStorageIfNeeded() {
if (!navigator.storage || !navigator.storage.persist) {
return;
}
const isAlreadyPersisted = await navigator.storage.persisted();
if (isAlreadyPersisted) {
return;
}
@luizbills
luizbills / code.js
Created October 19, 2026 00:16
A small 32-bit hash example
// based on https://www.4rknova.com/blog/2026/03/01/mulberry32-rng
function hashStringToUint32(input) {
let h = 2166136261 >>> 0; // FNV-1a 32-bit offset basis
for (let i = 0; i < input.length; i += 1) {
h ^= input.charCodeAt(i); // xor in next character
h = Math.imul(h, 16777619); // multiply by FNV prime
}
return h >>> 0;
}
@luizbills
luizbills / README.md
Last active June 16, 2026 11:23
Simple timer for litecanvas

Simple Timer

Litecanvas plugin to handle simple timers.

Usage

litecanvas()

function init() {
@luizbills
luizbills / code.js
Last active June 30, 2026 18:07
extra sound functions for Litecanvas
/**
* @param {number} frequency
* @param {number} [duration] in seconds
* @param {number} [wavetype] 0 (sine), 1 (triangle), 2 (saw), 3 (tan), 4 (noise) or 5 (square)
* @param {number} [volume]
*/
function beep(frequency, duration = 0.1, wavetype = 1, volume = .5) {
sfx([, 0, frequency, 0.01, duration, 0.01, wavetype], 0, volume)
}
@luizbills
luizbills / 10print.js
Last active May 3, 2026 15:19
Commodore 64 BASIC one-liner "10 PRINT CHR$(205.5+RND(1)); : GOTO 10" in Litecanvas
litecanvas()
framerate(1)
draw()
function draw() {
cls(3)
block = randi(10,100)
for (let y = 0; y < H; y += block) {
for (let x = 0; x < W; x += block) {
@luizbills
luizbills / code.js
Created April 27, 2026 13:56
Simple loading screen #litecanvas
litecanvas({})
function draw() {
cls(0)
textfont("monospace")
textalign("center", "middle")
const dots = ".".repeat(wrap(T*1.5,0,5)+1)
text(W/2, H/2, "LOADING\n"+dots)
@luizbills
luizbills / code.js
Created April 24, 2026 12:50
Basic physics simulation
//! Based on https://slicker.me/javascript/physics/physics_engine.htm
// Vector utilities
class Vec {
constructor(x=0, y=0) {
this.x = x;
this.y = y;
}
add(v) {
return new Vec(this.x + v.x,this.y + v.y);
@luizbills
luizbills / code.js
Created February 11, 2026 14:48
Top-down movement like old pokemons games #litecanvas
litecanvas({
width: 8*8,
autoscale: 3
})
const p = {
x: 0,
y: 0,
dx: 0,
dy: 0,
@luizbills
luizbills / code.js
Last active October 25, 2026 14:22
Memory Game in Litecanvas
litecanvas({})
let cards = [], sprites, opens = [], timer = 0
const
SIZE = 64,
OFFSET = SIZE/4,
CLOSED_CARD = paint(SIZE, SIZE, () => {
cls(2)
})
@luizbills
luizbills / code.js
Created November 18, 2025 01:05
Draw random asteroid shape in Litecanvas
litecanvas({})
function init() {
framerate(1)
}
function draw() {
cls(0)
// linedash([10,5])
// circ(W/2, H/2, 150, 2)