Your browser lacks required capabilities. Please upgrade it or switch to another to continue.
Loading…
There are many different ways to approach procedural generation of content in Twine. This example covers using patterns, random generation, noise generation, and combining these with timing to generate and show content.
<blockquote>
This example uses the SugarCube 2.21.0 story format.
</blockquote>
[[Generate Basic Patterns]]
[[Generate Random Characters]]
[[Generate Repeating Character Patterns]]
[[Generate Erasure Patterns]]
[[Generate Noise Patterns]]
[[Generate Repeating Noise Patterns]]
<<nobr>>
<<for _i to 0; _i < 500; _i++>>
<<set _type to random(1,3)>>
<<if _type == 1>>
"""@@@"""
<<elseif _type == 2>>
"""====="""
<<else>>
"""********"""
<</if>>
<</for>>
<</nobr>><<nobr>>
<<for _i to 0; _i < 500; _i++>>
<<set _randomCharacter to random(32, 126)>>
<<print String.fromCharCode(_randomCharacter)>>
<</for>>
<</nobr>><div class="art"></div>
<<silently>>
<<repeat 3s>>
<<set $characterArray = []>>
<<for _i to 0; _i < 500; _i++>>
<<set _randomCharacter to random(32, 126)>>
<<set $characterArray[_i] = String.fromCharCode(_randomCharacter)>>
<</for>>
<<replace ".art">><<print $characterArray>><</replace>>
<</repeat>>
<</silently>><<silently>>
<<set _contentArray to Story.get("War of the Worlds").text>>
<<set _splitArray to _contentArray.split(" ")>>
<<for _i to 0; _i < 900; _i++>>
<<set _randomEntry to random(1, _splitArray.length)>>
<<set _splitArray[_randomEntry] to "--">>
<</for>>
<</silently>>
<<nobr>>
<<for _i to 0; _i < _splitArray.length; _i++>>
_splitArray[_i]
<</for>>
<</nobr>>As I set down these notes on paper, I'm obsessed by the thought that I may be the last living man on earth. I have been hiding in this empty house near Grovers Mill -- a small island of daylight cut off by the black smoke from the rest of the world. All that happened before the arrival of these monstrous creatures in the world now seems part of another life... a life that has no continuity with the present, furtive existence of the lonely derelict who pencils these words on the back of some astronomical notes bearing the signature of Richard Pierson. I look down at my blackened hands, my torn shoes, my tattered clothes, and I try to connect them with a professor who lives at Princeton, and who on the night of October 30, glimpsed through his telescope an orange splash of light on a distant planet. My wife, my colleagues, my students, my books, my observatory, my... my world... where are they? Did they ever exist? Am I Richard Pierson? What day is it? Do days exist without calendars? Does time pass when there are no human hands left to wind the clocks? ...In writing down my daily life I tell myself shall preserve human history between the dark covers of this little book that was meant to record the movements of the stars. . . But to write I must live, and to live, I must eat ... I find moldy bread in the kitchen, and an orange not too spoiled to swallow. I keep watch at the window. From time to time I catch sight of a Martian above the black smoke. The smoke still holds the house in its black coil... but at length there is a hissing sound and suddenly I see a Martian mounted on his machine, spraying the air with a jet of steam, as if to dissipate the smoke. I watch in a corner as his huge metal legs nearly brush against the house. Exhausted by terror, I fall asleep...it's morning...
Morning! Sun streams in the window. The black cloud of gas has lifted, and the scorched meadows to the north look as though a black snowstorm has passed over them. I venture from the house. I make my way to a road. No traffic. Here and there a wrecked car, baggage overturned, a blackened skeleton. I push on north. For some reason I feel safer trailing these monsters than running away from them. And I keep a careful watch. I have seen the Martians. . . feed. Should one of their machines appear over the top of trees, I am ready to fling myself flat on the earth. I come to a chestnut tree. October chestnuts are ripe. I fill my pockets. I must keep alive. Two days I wander in a vague northerly direction through a desolate world. Finally I notice a living creature... a small red squirrel in a beech tree. I stare at him, and wonder. He stares back at me. I believe at that moment the animal and I shared the same emotion...the joy of finding another living being. I push on north. I find dead cows in a brackish field. Beyond, the charred ruins of a dairy. The silo remains standing guard over the waste land like a lighthouse deserted by the sea. Astride the silo perches a weathercock. The arrow points north.
Next day I came to a city vaguely familiar in its contours, yet its buildings strangely dwarfed and leveled off, as if a giant hand sliced off its highest towers with a capricious sweep of his hand. I reached the outskirts. I found Newark, undemolished, but humbled by some whim of the advancing Martians. Presently, with an odd feeling of being watched, I caught sight of something crouching in a doorway. I made a step towards it, and it rose up and became a man! -- a man, armed with a large knife.<<nobr>>
<<for _i = 0; _i < 20; _i++>>
<<for _k = 0; _k < 20; _k++>>
<<if window.noise.simplex2(_i, _k) < 0>>
"""/"""
<<else>>
"""\"""
<</if>>
<</for>>
<br>
<</for>>
<</nobr>>
<div class="art"></div>
<<nobr>>
<<repeat 1s>>
<<run window.noise.seed(Math.random())>>
<<replace ".art">>
<<for _i = 0; _i < 20; _i++>>
<<for _k = 0; _k < 20; _k++>>
<<if window.noise.simplex2(_i,_k) < 0>>
"""/"""
<<else>>
"""\"""
<</if>>
<</for>>
<br>
<</for>>
<</replace>>
<</repeat>>
<</nobr>>