Skip to content

Instantly share code, notes, and snippets.

View grapefrukt's full-sized avatar
πŸ’­
🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭

martin jonasson grapefrukt

πŸ’­
🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭🌭
View GitHub Profile
@grapefrukt
grapefrukt / Main.hx
Created January 13, 2014 22:47
Causes a crash on Windows XP systems once it goes above 489 rectangles
package ;
import flash.display.Sprite;
import flash.events.Event;
import flash.Lib;
import flash.text.TextField;
class Main extends Sprite {
package flash.text;
import flash.display.BitmapData;
import flash.display.Sprite;
/**
* Wraps a regular TextField and renders it to a Bitmap without it ever being on the DisplayList.
* Used to work around this bug: https://github.com/openfl/lime/issues/20
* @author Martin Jonasson, [email protected]
*/
class RTextField extends Sprite {
@grapefrukt
grapefrukt / IFilter.hx
Created February 4, 2014 23:04
Here's a few bits and pieces I once used to pitch/filter a sound in OpenFL
/*
The MIT License
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@grapefrukt
grapefrukt / Main.hx
Last active August 29, 2015 13:57
Compiler bug? "Variable initialization must be a constant value" despite being just that.
class Main {
// this particular setup gives me the error:
// Main.hx:12: characters 22-85 : Variable initialization must be a constant value
// set either GRID_SIZE, CELL_SIZE or OUTLINE_RATIO to anything else and it's fine
public static inline var GRID_SIZE :Int = 20;
public static inline var CELL_SIZE :Int = GRID_SIZE - 2;
public static inline var OUTLINE_RATIO :Float = 1.2;
@grapefrukt
grapefrukt / RTextField.hx
Created May 30, 2014 11:13
Hack to fix offset/cropped text when scaling a TextField in OpenFL
package flash.text;
import openfl.text.TextField;
import openfl.text.TextFormat;
/**
* ...
* @author Martin Jonasson, [email protected]
*/
#if flash
typedef RTextField = TextField;
@grapefrukt
grapefrukt / setconfig.hx
Created October 13, 2014 13:35
Recursively applies the values from one object to another using reflection
static function setconfig(target:Dynamic, config:Dynamic) {
// iterate over the fields of the config object
for (key in Reflect.fields(config)) {
// make sure our target has this field
if (!Reflect.hasField(target, key)) continue;
// fetch the value of the first field
var configvalue:Dynamic = Reflect.field(config, key);
// check if its and object, and if so, make sure it actually has multiple values inside
// (strings are for some reason considered objects)
package com.grapefrukt.games.slicer.utils;
/**
* ...
* @author Martin Jonasson, [email protected]
*/
class ConvexHull {
public static function get<T:{x:Float, y:Float}>(vertices:Array<T>):Array<T> {
@grapefrukt
grapefrukt / arcade_joy.ino
Last active August 29, 2015 14:15
This is the code I use for my Teensy 2.0++ Joystick interface in my Arcade machine.
#define STATIC_ASSERT(COND,MSG) typedef char static_assertion_##MSG[(COND)?1:-1]
#define CHECK_SIZE(a) (sizeof(a)/sizeof(a[0]))
#define NUM_DIR 4
#define NUM_BUT 6
#define NUM_INPUT (NUM_DIR + NUM_BUT)
#define LEFT 0
#define RIGHT 1
#define UP 2
class Test {
static function main() {
var input = '()()(()()()(()()((()((()))((()((((()()((((()))()((((())(((((((()(((((((((()(((())(()()(()((()()(()(())(()((((()((()()()((((())((((((()(()(((()())(()((((()))())(())(()(()()))))))))((((((((((((()())()())())(())))(((()()()((((()(((()(()(()()(()(()()(()(((((((())(())(())())))((()())()((((()()((()))(((()()()())))(())))((((())(((()())(())(()))(()((((()())))())((()(())(((()((((()((()(())())))((()))()()(()(()))))((((((((()())((((()()((((()(()())(((((()(()())()))())(((()))()(()(()(()((((()(())(()))(((((()()(()()()(()(((())())(((()()(()()))(((()()(((())())(()(())())()()(())()()()((()(((()(())((()()((())()))((()()))((()()())((((()(()()(()(((()))()(()))))((()(((()()()))(()(((())()(()((()())(()(()()(()())(())()(((()(()())()((((()((()))))())()))((()()()()(())()())()()()((((()))))(()(((()()(((((((())()))()((((()((())()(()())(())()))(()(()())(((((((())))(((()))())))))()))())((())(()()((())()())()))))()((()()())(())((())((((()())())()()()(((()))())))()()))())(()()
@grapefrukt
grapefrukt / run.sh
Created May 27, 2016 14:18
Run script that fixes missing libraries for 32 bit builds only
#!/bin/bash
# making sure we're in the correct dir
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"; cd ${DIR}
# get the architecture
arch=$(uname -m)
# this hack is only needed on 32 bit for some reason
if [[ ''$arch'' == ''i686'' ]]; then
# make sure libraries are loaded from the local directory