Skip to content

Instantly share code, notes, and snippets.

@incinirate
incinirate / scrollbar.lua
Created July 12, 2016 16:44
The core for scrollbar system in CC
--[[
Given the height of the associated work area, and the height of the viewport you can create a scrollbar where the entirety
of it's scope represents the entire document, where the size of the handle represents the viewport. The problem comes in when
the document is so long, that the linked scroll handle would be too small. The way to solve that problem is to simply have a
minimum length for the handle, The logic will still stay the same since the defines of the area is enclosed by the top of the
scroll handle. And when the handle reaches the very bottom, then you can adjust so that the bottom of the document is viewed.
]]

Riko 4

Graphics Interface Specs

Good practices

    Generally, the fastest way to handle graphics in Riko 4 is to rasterize everything into an image (see below) to reduce calls. However this is not always applicable as creating images is not super fast. Meaning, its not a good idea to create new images every frame. You can modify images which is a good way to make minor changes to them, however the ideal condition is to have a spritesheet with all possible forms of your graphics present.

    As the Riko 4 screen is double buffered, the ideal way to draw graphics is to clear the screen, draw your graphics, then swap.


@incinirate
incinirate / LuaXML.lua
Last active June 1, 2017 22:22
Simple parser / pretty printer for XML written in Lua, no guarentees about anything
local xmlutils = {}
--[[
TODO:
- Parse standard XML header
]]
@incinirate
incinirate / 0_pproc.lua
Last active November 7, 2018 06:57
"Find and Replace" macro preprocessor for Lua
--[[
USAGE: pproc <inputFile> [outputFile]
If outputFile is not specified, pproc will write output to this path: inputFile .. ".lua"
]]
local args = { ... }
@incinirate
incinirate / complex.lua
Created October 13, 2017 04:10
Complex number library for Lua, supports all basic operations
local complex = {}
do
function complex.init(a, b)
local c = {real = a, imag = b}
setmetatable(c, {__index = complex,
__add = complex.add,
__sub = complex.sub,
__mul = complex.mul,
__div = complex.div,
__pow = complex.pow,
@incinirate
incinirate / xenon-build.lua
Last active May 13, 2018 23:38
Don't read me, I'm a squashed and bundled nightmare
-- vim: syntax=lua
-- luacheck: globals loadRemote getRemote fs loadstring peripheral
-- Load required libs / files
local surface = (function()
local surface = { } do
--[[
Surface 2
@incinirate
incinirate / test.c
Last active December 23, 2018 21:46
Demonstration of slowdown when using BlitRect
#include "SDL.h"
#include "SDL_gpu.h"
#include <stdio.h>
#define WIDTH 280
#define HEIGHT 160
#define SCALE 3
bool running = true;
bool doScale = true;
@incinirate
incinirate / float.lua
Last active November 5, 2018 05:21
Floating Point visualization for Riko4 (rlua)
local exp = 5
local frac = 3
local args = {...}
if args[1] then exp = tonumber(args[1]) end
if args[2] then frac = tonumber(args[2]) end
local bits = {0}
for i = 1, exp do
@incinirate
incinirate / 0_x86emu.lua
Last active October 30, 2018 18:09
Simple x86 (GAS/AT&T flavor asm) emulator for Riko4
local cursor = require("ui.cursor").new()
local running = true
local env = {
rax = 0,
rbx = 0,
rcx = 0,
rdx = 0,
rsi = 0,
rdi = 0,
@incinirate
incinirate / target.lua
Last active November 16, 2018 18:29
Missile targeting algorithm via numeric approximation
local sqrt = math.sqrt
local cos, sin = math.cos, math.sin
local targetStep = 0.1 -- Determines targeting accuracy, lower is better (but slower)
local function targetAngle(missile, target)
local px = missile.pos.x
local py = missile.pos.y
local vx = missile.vel.x
local vy = missile.vel.y
local am = missile.accel