alara's experiments

twitter itch.io github gitlab

back to home page.

this is a dumping ground for some quick experiements.


readable name colors

chat applications often let users set any name color. that usually causes problems with contrast against different background colors. i made this cause i couldn't find something that did this.

alice: can you read my name?
bob: depends what the minimum contrast is set to

here's the code running on this page (using some functions from this gist for oklab conversion)

function clamp(x, min, max) {
	return Math.min(Math.max(x, min), max);
}
function getReadableNameColor(minContrast, fgHex, bgHex) {
	const fg = rgbToOklab(hexToRGB(fgHex));
	const bg = rgbToOklab(hexToRGB(bgHex));
	// if we are already within minContrast, we dont need to do anything
	if (Math.abs(bg.L - fg.L) > minContrast) return fgHex;
	const defaultOffset = bg.L < 0.5 ? minContrast : -minContrast;
	const offset =
		fg.L > bg.L
			? bg.L + minContrast > 1
				? defaultOffset
				: minContrast
			: bg.L - minContrast < 0
			? defaultOffset
			: -minContrast;
	const L = clamp(bg.L + offset, 0.0, 1.0);
	return rgbToHex(
		oklabToSRGB({
			L,
			a: fg.a,
			b: fg.b,
		})
	);
}
function getReadableTextColor(bgHex) {
	const bg = rgbToOklab(hexToRGB(bgHex));
	return bg.L < 0.5 ? "#ffffff" : "#000000";
}

you can use this under the terms of the mit license.


DFPWM

dfpwm is a one bit per sample audio codec. this plugin converts a signal to dfpwm and back.

this codec was originally designed for use in minecraft mods, but it works pretty good as an effect i think.

dfpwm was invented by Ben "GreaseMonkey" Russell, and i ported it to an audio plugin.

you can read more about how dfpwm works here.

Demo

Dry

Wet

Downloads

Windows x86_64 VST3 Clap
source code is available here.