Skip to content

Instantly share code, notes, and snippets.

@mrange
mrange / tic80.lua
Last active September 21, 2026 19:34
TIC80 music
pos=0
local abs = math.abs
local exp2 = function(x) return 2.0 ^ x end
local sin = math.sin
local mod = function(a, b) return a - math.floor(a / b) * b end -- GLSL mod (always positive)
local function music(t1)
local a3 = 0.0
for i1 = 1, 4 do
@mrange
mrange / neworder.js
Last active September 12, 2026 17:04
Strudel effect
/*
@title EffectTime testing
@by mrange
*/
class EffectTime {
constructor() {
this.time=0;
this.n=0;
this.lastOnset=-1;
@mrange
mrange / truchet..js
Last active September 12, 2026 10:46
Custom hydra effect
// https://hydra.ojack.xyz/
setFunction({
name: 'truchet',
type: 'src',
inputs: [
{
type: 'float',
name: 'T',
default: 0.,
@mrange
mrange / hydra.js
Last active September 10, 2026 17:29
Green Apollo
// https://hydra.ojack.xyz/
setFunction({
name: 'greenapollo',
type: 'src',
inputs: [
{
type: 'float',
name: 't',
default: 0,
@mrange
mrange / hydra.js
Last active September 7, 2026 19:47
My first hydra-hack
// https://hydra.ojack.xyz/
setFunction({
name: 'hack',
type: 'src',
inputs: [],
glsl:
`
vec2 P=2.*_st-1.;
P.x*=resolution.x/resolution.y;
@mrange
mrange / README.md
Last active September 6, 2026 09:08
Snippets for shader devs

Snippets for shader devs

⚠️ All text content on this blog is licensed under CC BY-SA 4.0. All code is licensed under CC0. ⚠️

All code assumes shadertoy environment:

// O - output color
// C - pixel coordinate
// iResolution - vec3 uniform containing the resolution, .z is 1 when generating 2D fragments.
void mainImage(out vec4 O, vec2 C) {
@mrange
mrange / main.c
Last active February 24, 2026 12:50
Obfuscated C experiment: Nothing special
#define _GNU_SOURCE
#include<math.h>
#include<sys/ioctl.h>
#define V for(n=0;n<3;++n)
#define F c+=sprintf(b+c,
//////////////////////////////////////
// "Nothing Special"-Posix version ///
// by mrange 2026-02-22 ////
// // //
// Compile and run with: // //
@mrange
mrange / Program.cs
Created February 21, 2026 11:51
Spectre Playground Effect
// "Nothing Special" shader by Mårten Rånge
var terminal = new BrowserTerminal(
AnsiConsole.Console,
AnsiConsole.Profile.Width,
AnsiConsole.Profile.Height);
var renderer = new Renderer(terminal);
var writer = AnsiConsole.Profile.Out.Writer;
writer.Write("\x1b[?25l"); // Hide cursor
@mrange
mrange / main.cpp
Created January 27, 2026 11:16
pimpl
#include "pimpl.h"
int main() {
auto x = new pimpl();
x->the_method();
delete x;
return 0;
}
@mrange
mrange / units.fs
Last active October 7, 2025 19:56
F# measures
open LanguagePrimitives
// Units of measure are *compile-time* type tags on numeric types
// They prevent mixing incompatible dimensions (meters vs seconds) and have *no runtime cost*.
type [<Measure>] m // meter (length)
type [<Measure>] kg // kilogram (mass)
type [<Measure>] s // second (time)
type [<Measure>] A // ampere (electric current)
type [<Measure>] K // kelvin (thermodynamic temperature)
type [<Measure>] mol // mole (amount of substance)
type [<Measure>] cd // candela (luminous intensity)