Skip to content

Instantly share code, notes, and snippets.

@leegrey
leegrey / PixelController.cs
Created June 22, 2017 11:35
A Unity3D class for snapping pixel art to multiples of a whole (design scale) pixel
using UnityEngine;
/*
A Unity3D class for snapping pixel art to multiples of a whole (design scale) pixel
Use in conjunction with an appropriately scaled Otho Camera
License: MIT
Written by Lee Grey (@mothteeth)
*/
/*
Basic Sprite Shader for aligning pixel art to the same grid, based on the Unity Sprite Shader.
Create one Material where you assign the same Pixels Per Unit value you use on your imported Sprites,
then reuse this Material on all appropriate Sprite Renderers.
(As far as I know there's no possiblity to get this value automatically.)
This is not for scaled or rotated artwork. If you need those features, look at low res render textures.
Use this however you want.
@leegrey
leegrey / ProcessTimer.cs
Created February 13, 2017 22:54
A small debug util for timing chunks of code in Unity / C#
using System.Collections.Generic;
using System.Diagnostics;
using Debug = UnityEngine.Debug;
/*
USAGE:
ProcessTimer.Start("unique_process_id");
// do stuff
ProcessTimer.End("unique_process_id", "An optional additional message to display with results");
/**
* @author Lee Grey / Jonathan Hopcroft
*
* seeded random number generator
* based on Rndm by Grant Skinner
* https://github.com/gskinner/AS3Libs/blob/master/Rndm/com/gskinner/utils/Rndm.as
*
* Incorporates implementation of the Park Miller ( 1988 ) "minimal standard" linear
* congruential pseudo-random number generator by Michael Baczynski, www.polygonal.de.
* ( seed * 16807 ) % 2147483647
@leegrey
leegrey / TileMapPathField.ts
Last active May 4, 2020 12:52
Pathfinding on a Grid with Flow Fields
// Copyright Lee Grey, 2014
// License: MIT
module lg.tileSystem {
import Vector2D = lg.math.geometry.Vector2D;
export class FieldInfo {
distanceFromTarget: number = -1;
@leegrey
leegrey / InheritMax.js
Created July 17, 2013 04:25
InheritMax.js is a more advanced version of Inherit.js. It produces classes that contain a self calling init() function. I now prefer the simpler, stripped back functionality of Inherit.js, but have posted this for reference.
/*
Author: Lee Grey, 2012
License: MIT
USAGE:
var A = InheritMax.base( {
name: 'A',
say: function () {
console.log( 'A speaks' );
@leegrey
leegrey / test.markdown
Last active December 14, 2015 21:29
Test
SECOND FILE
# H1
followed by some text
## H2
followed by some text
### H3
followed by some text
@leegrey
leegrey / inherit.js
Last active October 12, 2015 21:47
inherit.js - a minimal prototype inheritance utility
/*
Inherit copyright 2012 by Lee Grey
license: MIT
http://creativecommons.org/licenses/MIT/
http://opensource.org/licenses/mit-license.php
The goal of the Interit class is to allow for a prototype based inheritance that
does not create a deep prototype chain. Inherited fields are known to be slow,
so methods and fields are simply copied onto the prototype of the target,
keeping only a single depth.
@leegrey
leegrey / SignalHub.as
Created September 15, 2012 07:48
SignalHub.as is a Signal manager for AS3
/*
SignalHub:
Created on Sat 15th Sep, 2012
by Lee Grey
SignalHub solves the problem of object-creation order by using lazy initialisation - whoever
makes the first request for a Signal with a given key will bring about it's creation.
@leegrey
leegrey / PerlinNoiseGenerator.js
Last active November 13, 2023 17:09
Seeded Perlin Noise in JavaScript - based on original by Ken Perlin
// Seeded Perlin Noise
//
// Based on the original by Ken Perlin:
//
// http://mrl.nyu.edu/~perlin/noise/
// http://mrl.nyu.edu/~perlin/paper445.pdf
//
// Seeding function based on code from:
// http://techcraft.codeplex.com/discussions/264014
//