Psychohistory Simulator [Free+Open Source]
By Justin Wetch
GITHUB REPO: github.com/justinwetch/psychohistory LIVE DEMO: psychohistorysim.vercel.app
Growing up in Alaska, my bus ride to school was about an hour each way, longer in winter. I didn’t have a cell phone, so I read a lot of sci fi books. The books I kept coming back to were Isaac Asimov's Foundation series, not just Foundation itself but the extended universe, which remains some of my favorite science fiction. I'd read on the bus to school and on the bus home, and somewhere in those hours the idea of psychohistory lodged itself permanently in my brain: that the future of human civilization could be probabilistically knowable, that history had a shape you could see if you stood far enough back.
I never fully bought the premise. (Asimov didn't either, really. He built in his own counterargument with the Mule, a single unpredictable individual who demolishes the entire plan.) But the image from the books stayed with me for twenty years: Hari Seldon's Prime Radiant, a device that projects the complete mathematical framework of psychohistory as a three-dimensional hologram you can navigate, zoom into, modify with your hands.
I wanted to build that. Not the math, but the feeling.
What it is
Psychohistory Simulator reads live geopolitical data, generates a baseline analysis of the present moment, and then branches into possible futures. Each future forks again. You navigate this branching space with your hands via webcam, using gestures to explore possibilities, commit to a timeline, or collapse branches you want to discard. When you commit, the camera swoops along the causal spline into your chosen future while the unchosen branches fade and prune away behind you.
There are two ways to start. You can let the simulator observe the present, grounding itself in current events and proposing directions based on what's actually happening in the world right now. Or you can type in a scenario seed, anything you want, and the simulator grounds that premise in reality and branches from there. I typed "United States invades Iran" during development, and watching plausible cascading consequences unfold from that premise was the first moment this project genuinely startled me. It felt a little too real.
A divergence dial lets you tune the experience. Low entropy keeps things close to the probable, grounded, the kind of analysis you might read in Foreign Affairs. High entropy goes lateral and surprising, the kind of futures that are unlikely but not impossible. By default it sits at 0.5, balanced between realism and speculation.
The feeling
The thing I kept chasing during development was a specific sensation, something arcane. The Foundation in Asimov's books is dressed in scientific robes, but they function like a hidden priesthood, keepers of forbidden knowledge about how history actually works. I wanted using this tool to feel like that, like you're touching something you maybe shouldn't be able to touch.
And somehow it does. When you hold your hand up and the futures respond, when you pinch to commit and watch the other possibilities dissolve, there's a strangeness to it that I didn't fully anticipate. It bridges two very different ends of human nature: our capacity for abstract reason and historical prediction on one hand, and this extraordinarily primal motif of proprioceptive movement on the other. The hand is perhaps humanity's most fundamental tool-using appendage, and here it's manipulating possible human history, which is maybe the most abstract thing you could manipulate. That collision produces something genuinely uncanny. It feels less like using software and more like scrying.
A lot of this comes from my background in game design, working on Upekkha and over twenty interactive experiences across different roles. Game design forces you to think about how things should feel before you think about how they should work, and that instinct drove most of the interaction decisions here. How should it feel to commit to a future? How should it feel to go back? You ask the question first and then try to build the answer.
The aesthetic
I consciously avoided sci-fi aesthetics. The terminal look, the holographic blue, the CRT-era visual language that has become inextricable from Star Wars and Star Trek. That whole tradition started defining its aesthetic vocabulary in an era of cathode ray tubes and scan lines, and a lot of what we think of as "futuristic" is actually just that specific history of display technology. It's cool, but it wasn't right for this project.
Three things shaped the direction instead. The Civilization games were the biggest influence, and there's something circularly appropriate about that, since Civilization itself feels pretty inspired by psychohistory. The way events are described on screen, the fonts, that sense of historical sweep rendered in gold and parchment tones. Marvel's Eternals contributed a specific quality: fluid, thin gold linework, forms materializing from particles, a different kind of futurism than the sterile white corridors we're used to. The Foundation TV series has a similar gold-and-particle aesthetic that dovetailed naturally, though I didn't want to be too close to the show. And the physical object I kept thinking about was the orrery, those brass astronomical models from the 1700s that track celestial bodies with interlocking gears, objects that model something vast through elegant mechanical precision.
The result is gold on obsidian. Warm amber lighting from below, Rembrandt-style. Wireframe icosahedrons as nodes connected by curved splines that arc through three-dimensional space. The whole thing breathes on a slow animation loop, gold panels pulsing gently in the dark.
Under the hood
The architecture uses what I'm calling a shell node pattern: the 3D geometry spawns instantly during the camera animation, and the content fills in asynchronously from the API, so there's never a loading screen. The simulation feels continuous even though it's making generation calls behind the scenes. I chose Gemini Flash for speed, because if someone has to wait too long for a branch to resolve, the spell breaks and you lose them. Getting output that feels genuinely real from a fast model, rather than defaulting to a slow reasoning model, was one of the more satisfying constraints to work against.
The generation is grounded in what I'd call realpolitik principles: states acting in rational self-interest, the relationship between domestic politics and foreign policy, least-costly moves, internal power struggles constraining external action. Without this kind of structural grounding, LLMs default to one of two failure modes. Either everything spirals into sci-fi apocalypse within two turns, or if you ask for balance, it swings to an equally unsatisfying utopia where everyone cooperates and things work out. Neither feels like reality. Reality is that serious choices are being made all the time, with consequences that compound in ways that are hard to predict but internally coherent once you see them.
What I wanted the branching to feel like is what it actually feels like to live through history, which is strange. I was born in 1997. In the span of one lifetime so far: the end of "end of history" neoliberalism, 9/11, the rise of the surveillance state, the 2008 crash, the drone program, a global pandemic, and a political realignment that nobody in 1997 would have predicted. Living through history feels surreal, and choosing how history progresses should feel surreal too.
The stack is vanilla: Vite, Three.js, GSAP for animation, MediaPipe for hand tracking, no framework. The gesture system maps open palm to seek, pinch and hold to commit, closed fist to collapse a branch. There's a rewind gesture too, thumb-to-pinky pinch, that traverses backward through your committed history, un-pruning timelines you previously abandoned. Futures project into the Z-axis as a lightcone into a 3D void, not laid out as a flat tree. Further branches scale down and desaturate, giving a natural depth-of-field fade, and a minimap in the corner shows the full causal topology from above.
The caveats
I don't think psychohistory works as a real theory. The premise that individual actions wash out in aggregate is pretty clearly false. One idiosyncratic person in the right position can rewrite the trajectory of nations, and that's not a bug in history, it's the defining feature. Asimov knew this. It's why the Mule exists in his own story.
But there's something at the edges that's hard to dismiss entirely. If you turn up the realism, the predictions are not nothing. I'd be shocked if somewhere in Langley right now, someone isn't building a much more rigorous version of this, and if they're competent, they should be. The current tool is a game, tuned to be entertaining more than purely realistic. But with larger reasoning models, real-time regrounding, and serious compute behind an agent architecture, the gap between this and actual scenario planning gets smaller than you'd expect. Not prophecy. Something more like weather forecasting for geopolitics: probabilistic, decaying in accuracy over time, but informative within its horizon.
The code is open source. Plug in a Gemini API key and try it yourself. And if you want to turn it into something more rigorous, fork it and let me know what you build.