Skip to content

Instantly share code, notes, and snippets.

View markknol's full-sized avatar
🧪
Doodling around

Mark Knol markknol

🧪
Doodling around
View GitHub Profile
@markknol
markknol / Life.hx
Created May 25, 2018 09:15
Life = life
package com.mediamonks.game.state;
import flambe.Component;
import flambe.util.Value;
/**
* Life.
*
* To follow the clues and walk out the exit.
* To know and master the world.
@markknol
markknol / Publish to Haxelib using Travis.md
Last active July 17, 2018 20:06
Publish to Haxelib (using Travis) using Github Releases

Publish to Haxelib using Travis using Github Releases

This tutorial will help you publish your library automatically to lib.haxe.org when you create a release on GitHub.

Motivation

  • Collaborators on GitHub can help publish on haxelib without the need of sharing/knowing your password.
  • It automatically tests your project, this ensures you don't publish broken builds.
  • It makes sure you have tagged your projects because that's what GitHub does for you when doing a release.
  • It is more transparent for collaborators/users what goes into the haxelib package zip file.
@markknol
markknol / Main.hx
Created September 21, 2018 13:30
Rainbow colors
function getRainbow(size:Int) {
inline function sinToHex(i, phase) {
var sin = Math.sin(Math.PI / size * 2 * i + phase);
var int = Math.floor(sin * 127) + 128;
return StringTools.hex(int, 2);
}
return [for (i in 0...size) {
var red = sinToHex(i, 0 * Math.PI * 2/3);
var blue = sinToHex(i, 1 * Math.PI * 2/3);
var green = sinToHex(i, 2 * Math.PI * 2/3);
@markknol
markknol / LutShader.hx
Created March 19, 2019 09:21
LUT shader (uses 512x512 textures)
class LutShader extends h3d.shader.ScreenShader {
static var SRC = {
@param var texture : Sampler2D;
@param var lookup1 : Sampler2D;
@param var lookup2 : Sampler2D;
@param var mixAmount : Float = 0.0;
@param var totalMixAmount : Float = 1.0;
function calcLookup(color:Vec4, lookupTexture:Sampler2D):Vec4 {
var blueColor = color.b * 63.0;
# FD UI THEME (5.3+)
# Use themes in dialogs?
SmartForm.UseTheme=True
# Should we use custom border?
ThemeManager.UseCustomBorder=True
# Apply even if set to None?
ThemeManager.ForceBorderStyle=False
@markknol
markknol / ArrayUtils.hx
Created May 17, 2019 15:30
Support `for(index => value in array)` syntax in Haxe
class ArrayUtils {
/**
Support `for(index => value in array)` syntax.
**/
public static inline function keyValueIterator<A>(arr:Array<A>) {
return new ArrayKeyValueIterator(arr);
}
}
private class ArrayKeyValueIterator<T>{
@markknol
markknol / shadertoy.md
Last active November 9, 2025 01:44
Shader cheatsheet (from shadertoy)

This help only covers the parts of GLSL ES that are relevant for Shadertoy. For the complete specification please have a look at GLSL ES specification

Language:

Version: WebGL 2.0
Arithmetic: ( ) + - ! * / %
Logical/Relatonal: ~ < > <= >= == != && ||
Bit Operators: & ^ | << >>
Comments: // /* */
Types: void bool int uint float vec2 vec3 vec4 bvec2 bvec3 bvec4 ivec2 ivec3 ivec4 uvec2 uvec3 uvec4 mat2 mat3 mat4 mat?x? sampler2D, sampler3D samplerCube
Format: float a = 1.0; int b = 1; uint i = 1U; int i = 0x1;

@markknol
markknol / DateUtil.hx
Last active June 12, 2019 13:54
DateUtil Outputs "xx days/weeks/days/minutes/seconds ago" https://try.haxe.org/#21f31
class DateUtil {
public static function format(target:Date) {
var secondsInMs = 1000;
var minuteInMs = secondsInMs * 60;
var hourInMs = minuteInMs * 60;
var dayInMs = hourInMs * 24;
var targetTime = target.getTime();
var now = Date.now().getTime();
@markknol
markknol / Main.hx
Created December 28, 2019 10:51 — forked from jdonaldson/Main.hx
Paths example
class Main {
static function main(){
var router = Paths.buildRouter(Page);
var o = router(["Home"]);
trace(o + " is the value for o");
var p = router(["Foo","Baz", "1"]);
trace(p + " is the value for p");
@markknol
markknol / EnumSet.hx
Last active January 7, 2021 16:14
A Map for enums, that require you to have all of its enum values as keys, by providing them in constructor. Stricter EnumValueMap
class Test {
static function main() {
var mySet = new EnumSet((key:MyEnum) -> switch key {
case A: [1,2];
case B: [1,2,3];
case C: [1,2,3,4];
case D: [1,2,3,15];
});
mySet[A].push(911);