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 / spritesheet.html
Created September 20, 2023 12:33
Make spritesheet of bunch of images
<canvas width="4096" height="3072" id=canvas></canvas>
<script>
let ctx = canvas.getContext`2d`;
window.onload = async () => {
let grid = 12;
canvas.width = grid*260; // grid * tile width
canvas.height = grid*220; // grid * tile height
for(let i=0;i<grid*grid;i++) {
let image = await loadImage(`render_${(""+i).padStart(5,"0")}.png`);
let idx = i%grid, idy = i/grid|0;
@markknol
markknol / parseJson.js
Created November 23, 2022 15:35
parsing json in a worker
// promisified version of parsing json in a worker
// usage: `let data = await fetch(url).then(v => v.text()).then(v => parseJson(v)).then(data => console.log(data));`
function parseJson(txt:string) {
return new Promise((resolve, reject) => {
var blob = new Blob([
'this.onmessage = function(message) {\n' +
'postMessage(JSON.parse(message.data));\n' +
'};'
], { type: "text/javascript" });
var w = new Worker(URL.createObjectURL(blob));
@markknol
markknol / index.html
Last active February 28, 2024 21:23
fxhash previewer - save as html in your project, tweak the values
<nav><button onclick="reloadFrames()">GENERATE()</button></nav>
<main></main>
<script>
const urlParams = new URLSearchParams(window.location.search);
const total = 15+5; // total frames
const interval = urlParams.get("fast") == "true" ? 60 : 200; // ms
const src = "./index.html";
let alphabet = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
function getHash() {
@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);
@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 / 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 / shadertoy.md
Last active March 28, 2024 16:14
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 / 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>{
# 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 / 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;