-- Various snippets for the PICO-8. Created by me or found online. Feel free to use. function delay(frames) for i=1,frames do yield() end end function rndrng(min, max) return min + rnd(max - min) end function stween(val, goal, amnt) return val + (goal - val) * amnt end -- Changes the values that PICO-8 uses for repeated button presses (i.e. you hold the button down and it triggers btnp() multiple times). I believe these values are in frames. function btndly(delay, freq) poke(0x5f5c, delay, freq) end -- Converts a scalar value (0.0-1.0) to a percentage string that can easily be printed to the screen. function scalartoperc(scalar) return sub(tostr(scalar * 100), 0, 5) .. "%" end -- Get the RAM usage as a percentage. function getramusage() return scalartoperc(stat(0)/2048) end -- Get the RAM usage & CPU usage in one formatted string function getdebuginfo() return "ram: " .. getramusage() .. "\ncpu: " .. scalartoperc(stat(1)) end function scalar(lower, upper, value) return (value - lower) / (upper - lower) end function remap(lower1, upper1, lower2, upper2, value) return (scalar(lower1, upper1, value) * (upper2 - lower2)) + lower2 end function sprrpt(ind, x, y, w, h) for xx=0,w-1 do for yy=0,h-1 do spr(ind, x + (xx * 8), y + (yy * 8)) end end end