Skip to content

Instantly share code, notes, and snippets.

@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 / simple drag and rotate demo.lua
Last active October 7, 2016 08:20
This code was an answer to a forum question asking for a touch to drag an object but a tap-touch to rotate the object. I kept it simple and without reference to my mathlib.lua for the sake of brevity.
local function angleOnTarget( e )
local a = math.atan2( e.y-e.target.y, e.x-e.target.x ) * 180 / (4*math.atan(1))
if (a<0) then a=a+360 end
return a
end
local function tap(e)
e.target.touchMode = "drag"
print("drag mode")
e.target.dragtimer = timer.performWithDelay( 400, function()
@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 / 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 / Cache.cs
Created August 21, 2017 12:14
Generic caching mechanism which makes sliding expiration easy.
using System;
using System.Collections.Generic;
using System.Runtime.Caching;
namespace CacheServices
{
public class Cache
{
protected MemoryCache _cache = new MemoryCache("general");
@HoraceBury
HoraceBury / circlelib.lua
Last active October 26, 2017 00:13
Create a portion of a fill or unfilled circle as a polygon and move it by it's circle-centre. Requires image: http://content.screencast.com/users/HoraceBury/folders/Default/media/18ea951e-71a1-44f4-a148-f2109a1c9059/brush2.png Download full solution: https://www.dropbox.com/s/8472upw9w2cwkwi/CircleLib.2015-12-02.001.zip?dl=0
-- circle lib
require("mathlib")
display.setDefault( "isAnchorClamped", false )
local min, max = -10000000000000, 10000000000000
local cache = {}
local circlelib = {}
@HoraceBury
HoraceBury / cyclingants.lua
Last active March 11, 2018 18:56
Cycling ants. Takes a pattern to be used for a mask outline and generates a collection of display groups which can be used to animate the cyclic pattern around a path shape. https://youtu.be/4cwjTrpvnFU
require("mathlib")
require("graphicslib")
require("tablelib")
local function asPoint( x, y )
return { x=x, y=y }
end
local function getPoint( path, index )
return { x=path[index], y=path[index+1] }
@HoraceBury
HoraceBury / displaylib.lua
Created March 21, 2018 09:44
Display library, adding to and modifying the existing Corona display library.
-- display lib
local newShapeList = {
"newCircle",
"newContainer",
"newEmbossedText",
"newEmitter",
"newGroup",
"newImage",
"newImageRect",
@HoraceBury
HoraceBury / graphicslib.lua
Last active March 21, 2018 09:45
Graphics extension library.
-- graphics extension library
require("mathlib") -- https://gist.github.com/HoraceBury/9431861
require("displaylib") -- https://gist.github.com/HoraceBury/1e2ce033e3441823038eb88b551ad981
-- https://math.stackexchange.com/questions/2269589/calculate-angle-of-the-next-point-on-a-circle
--[[
Generates a table of points containing the outline of a circle with each point 'step' pixels from the previous.
Parameters:
@HoraceBury
HoraceBury / Program.cs
Created April 4, 2018 12:54
Executing an equation in C# proven with nUnit.
using System;
using NUnit.Framework;
using System.Data;
namespace RandomTests
{
[TestFixture]
public class NumberTests
{
public static void Main(string[] args)