flâneur — a map of the web's best reading

Procedural Textures with Hash Functions

douglasorr.github.io · 949 words · saved by 1 readers

I'm the sort of person who gets very excited when simple rules create complex behaviour. The other day, I needed a simple hash function that maps ( 𝑥 , 𝑦 ) coordinates to a colour, and found a straightforward equation that ended up being astoundingly rich. Hence this post; to talk about and play with this function. TL;DR: The boolean predicate ( 𝑐 𝑥 𝑥 + 𝑐 𝑦 𝑦 + 𝑐 𝑥 𝑦 𝑥 𝑦 + 𝑐 𝑥 2 𝑥 2 + 𝑐 𝑦 2 𝑦 2 ) mod 𝑚 < 𝜏 𝑚 , is richly varied and beautiful. For example, varying 𝑐 𝑥 𝑦 with the other parameters fixed: For the rest of this post, we'll try to unpick the function. If you'd prefer to play with it yourself, check out the hash playground. I was trying to make a game that obeyed a 2-bit colour palette. With a strict interpretation of the rules, this means no interpolation or antialiasing — the pixels onscreen should only be one of 4 colours. So I needed textures that could align perfectly to the screen. The not-at-all novel solution: Hash the (x, y) screen-space

Procedural textures with hash functions Procedural textures with hash functions and Hash Playground I'm the sort of person who gets very excited when simple rules create complex behaviour. The other day, I needed a simple hash function that maps $(x, y)$ coordinates to a colour, and found a straightforward equation that ended up being astoundingly rich. Hence this post; to talk about and play with this function. TL;DR: The boolean predicate $(c_x \, x + c_y \, y + c_{xy} \, x \, y + c_{x^2} \, x^2 + c_{y^2} \, y^2)$ $\mathrm{mod} \, m < \tau \, m$, is richly varied and beautiful. For example,

Explore this link on the map →

saved by

related reading