wrote an essay on terrain generation, the math behind it,

Arpit Bhayani

Arpit Bhayani

Nov 30, 2025 • 1 min read


wrote an essay on terrain generation, the math behind it, with some code to generate it. The algorithm is useful in games like Counter-Strike, Age of Empires, etc, to programmatically generate terrains.

Interestingly, all it takes is a bunch of cosine functions layered on top of each other. Give it a read - it’s pretty interesting.

By the way, I originally wrote this in 2020, but I thought I’d share it again since it’s been more than five years :)

Arpit Bhayani

Principal Engineer II at Razorpay - building Agent Studio, Ex-staff engg at GCP Memorystore & Dataproc, Creator of DiceDB, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses