Skip to content

Instantly share code, notes, and snippets.

@HoraceBury
HoraceBury / collisionslib.lua
Last active October 30, 2016 08:23
Collisions library modified version of the Corona SDK CollisionFilter sample.
-- collision library
local collisionslib = {}
local categoryNames = {}
local categoryCounter = 1
local function newCategory( name )
categoryNames[ name ] = categoryCounter
categoryCounter = categoryCounter * 2
@HoraceBury
HoraceBury / cleanhtml.lua
Created February 14, 2014 13:37
Cleans rich text so that HTML is cleanly removed, p and br tags are reduced to new lines and some special characters are replaced with the text equivelents.
local t = [[ your html ]]
-- list of strings to replace (the order is important to avoid conflicts)
local cleaner = {
{ "&", "&" }, -- decode ampersands
{ "—", "-" }, -- em dash
{ "’", "'" }, -- right single quote
{ "“", "\"" }, -- left double quote
{ "”", "\"" }, -- right double quote
{ "–", "-" }, -- en dash
@HoraceBury
HoraceBury / tablelib.lua
Last active May 30, 2023 05:49
Lua table extensions used to improve and expand the table.* library in a simple manner.
-- table library extensions
if (dump == nil) then
dump = function(t)
print("=============")
for k,v in pairs(t) do
print("\t",k,v)
end
print("=============")
end
@HoraceBury
HoraceBury / utils.lua
Last active April 26, 2022 13:02
Miscellaneous utility functions which help get screen dimensions, extend display operations and some string functions.
-- utils
local composer = require("composer")
local utils = {}
function dump( ... )
if (#arg > 1) then
print("========================DUMP ("..#arg..")========================")
for i=1, #arg do
@HoraceBury
HoraceBury / _mathlib.lua
Last active February 27, 2022 12:17
Mathematics functions, including trigonometry. The main file demonstrates the use of the various maths extension functions available in the library. To use this remove the '_' from the filename.
-- mathlib.lua
local function dump(tbl)
print("====================")
for k,v in pairs(tbl) do
print(k,v)
end
print("====================")
end
@HoraceBury
HoraceBury / drawPolygonMain.lua
Last active November 1, 2015 09:01
Draw a polygon by tapping. Move the points. Tap points to remove them. Points go green when concave. Polygon concave/convex status displayed above.
-- polygon concave
require("mathlib")
stage = display.getCurrentStage()
local text = display.newText{ text="- - -", x=display.contentCenterX, y=100, fontSize=24 }
lines = display.newGroup()
lines:insert(display.newGroup())
@HoraceBury
HoraceBury / arrowlib.lua
Last active July 23, 2020 12:09
Arrow projectile with air drag applied to feathered tail.
-- arrow test
-- http://www.iforce2d.net/b2dtut/sticky-projectiles
-- video: http://screencast.com/t/vcPLSJR6xkIq
require("mathlib")
local sWidth, sHeight = display.actualContentWidth, display.actualContentHeight
local centerX, centerY = sWidth/2, sHeight/2
@HoraceBury
HoraceBury / rgb.lua
Last active December 19, 2016 04:48
Colours
-- rgb
-- Colors referenced from http://www.tayloredmktg.com/rgb/
local RGB = {
neoncyan = {16, 174, 239}, -- Neon Cyan
neonyellow = {231, 228, 37}, -- Neon Yellow
neonpink = {231, 83, 177}, -- Neon Pink
neongreen = {4, 228, 37}, -- Neon Green
@HoraceBury
HoraceBury / iolib.lua
Last active September 15, 2018 11:07
File IO supporting functions to make reading and writing files easier.
-- io operations
local json = require("json")
local lfs = require( "lfs" )
local iolib = {}
--[[ FACILITIES ]]--
local function toDate( timestamp )
@HoraceBury
HoraceBury / backswipelib.lua
Last active April 18, 2019 12:20
BackSwipe Navigation for Composer
-- swipe library
--[[ Libraries ]]--
local composer = require("composer")
--[[ Fields ]]--
local mainstage = display.getCurrentStage()
local stage = composer.stage