Skip to content

Instantly share code, notes, and snippets.

View anissen's full-sized avatar

Anders Nissen anissen

View GitHub Profile
@anissen
anissen / StackMachine.hx
Last active September 23, 2016 08:21
Minimal test of a stack machine
// Minimal test of a stack machine (https://en.wikipedia.org/wiki/Stack_machine)
enum Bytecode {
PUSH(v :Int);
ADD;
MULT;
PRINT;
}
class StackMachine {
@anissen
anissen / UniformPoissonSampler.hx
Created September 14, 2016 09:06
Fast uniform Poisson sampling
// Adapated from java source by Herman Tulleken
// http://www.luma.co.za/labs/2008/02/27/poisson-disk-sampling/
// The algorithm is from the "Fast Poisson Disk Sampling in Arbitrary Dimensions" paper by Robert Bridson
// http://www.cs.ubc.ca/~rbridson/docs/bridson-siggraph07-poissondisk.pdf
// Code adapted from http://theinstructionlimit.com/fast-uniform-poisson-disk-sampling-in-c
typedef Vector2 = { x :Float, y :Float }
@anissen
anissen / voronoi.lua
Created September 8, 2016 12:16
Voronoi in pico8
-- grabbed from http://www.lexaloffle.com/bbs/?pid=28105
function jitter(points)
for i = 1, #points do
p = points[i]
p.x += rnd(2) - 1
p.y += rnd(2) - 1
end
end
@anissen
anissen / Analytics.hx
Created August 19, 2016 22:24
Testing GameAnalytics REST API integration from Haxe
import haxe.crypto.Base64;
import haxe.crypto.Hmac;
import haxe.io.Bytes;
class Analytics {
var game_key :String;
var secret_key :String;
public function new(game_key :String, secret_key :String) {
this.game_key = game_key;
@anissen
anissen / Main.hx
Created August 19, 2016 13:10 — forked from po8rewq/Main.hx
Empty haxe / pico-8 project
package ;
import Pico.*;
class Main
{
static function main()
{
onInit = init;
@anissen
anissen / Main.hx
Last active July 6, 2016 08:46 — forked from elsassph/ResourceGenerator.hx
Haxe build macro converting a JSON file into strongly typed, inline/dce friendly, properties
class Main {
public static function main() {
trace(R.list);
trace(R.obj.foo);
}
}
@anissen
anissen / GeneratorParser.hx
Last active March 24, 2016 20:14
Parser for simple generative grammar
enum Token {
TSymbol(s :String);
TTerminal(s :String);
TArrow;
TPlus;
TBracketOpen;
TBracketClose;
TNumber(v :Float);
TEof;
@anissen
anissen / Test.hx
Created March 7, 2016 20:44
Diamond-square algorithm for generating realistic terrain
class Heightmap {
var size :Int;
var tiles :Array<Array<Null<Float>>>;
var d :Int;
public function new() {
}
@anissen
anissen / Perlin.hx
Last active April 12, 2016 13:33
Animated perlin noise example
class Perlin {
public var repeat :Int;
public function new(repeat :Int = -1) {
this.repeat = repeat;
}
public function OctavePerlin(x :Float, y :Float, z :Float, octaves :Int, persistence :Float) {
var total :Float = 0;
var frequency :Float = 1;
@anissen
anissen / GenNew.hx
Last active February 23, 2016 12:14 — forked from ibilon/GenNew.hx
Object construction with macro
import haxe.macro.Expr;
import haxe.macro.Context;
class GenNew {
macro public static function build () : Array<Field> {
var fields = Context.getBuildFields();
var args = [];
var assigns = [];
for (field in fields) {