What it is
A 16:9 animation in two halves. On the left, eleven lines of code are typed. On the right, the field of the Battle of Nagashino appears as each line is typed: a dusk sky and a crescent moon, Nagashino Castle, a torii gate and pines, the terrace of Shitaragahara and the Rengo River, the wooden palisades, the army of Oda Nobunaga and then the army of Takeda Katsuyori.
When the last line, battle.engage(...), is finished, the picture stops being a drawing and becomes a simulation. 148 soldiers act on their own rules until one side has nobody left to send, the field goes quiet, and it starts again.
What happens in the battle
| Who | What they do |
|---|---|
| Oda gunners (24) | Stand in three ranks. One rank fires while the next aims and the third reloads, so a volley goes out about every second. |
| Oda archers (10) | Shoot arrows in a high arc over their own lines. |
| Oda spearmen (28) | Hold the line behind the palisades and stab at anything that comes within reach. |
| Oda reserves (6) | Samurai who run to wherever a palisade has been broken. |
| Takeda cavalry (30) | Charge across the river in four waves, ram the palisades, and pour through any gap. |
| Takeda foot soldiers (40) | Follow the horses, shoot arrows on the way in and fight hand to hand at the fence. |
| The palisades | Six sections, each with its own strength. They crack, splinter and fall as they are hit. |
| The river | Turns red where soldiers fall in it, and the colour drifts downstream. |
The counters at the top show each side’s losses, and the label beside them names the stage: wave 1 charge, three-rank volley, cavalry surge, palisade breach, aftermath. The fallen stay where they fell until the scene starts over.
About the history
The battle was fought in 1575 at Shitaragahara, near Nagashino Castle in what is now Aichi Prefecture, between the allied armies of Oda Nobunaga and Tokugawa Ieyasu and the army of Takeda Katsuyori. The date in the first line, 1575.05.21, is the date in the Japanese calendar of the time; in the Western calendar it was 28 June. Oda’s side waited behind wooden palisades with a large number of matchlock guns, and the Takeda charges broke against them.
The famous three-rank rotating volley is how the battle has been told for centuries, but historians today doubt that it happened in that tidy form. This animation shows the traditional telling. The numbers are also scaled down: tens of thousands fought, and 148 fit on the screen.
How to take it
Press Download the HTML file above to get typing-nagashino-1575.html, or press Copy the code and save it as a file ending in .html. It is one file with no libraries and works offline. To record a video, open the picture-only view and record your screen; the picture is 1920 × 1080.
View the code
Loading…Embed it on your page
<iframe src="https://aspect.tools/nagashino-code" style="border:0;width:100%;max-width:1180px;aspect-ratio:16/13" title="Typing Nagashino 1575" loading="lazy"></iframe>
License and credit
Typing Nagashino 1575, 2026 series, by aspect.tools (https://aspect.tools/typing-nagashino), MIT License
A visible credit is appreciated but not required.
How to change it
| What to change | Where | Example |
|---|---|---|
| The text that is typed | CODE: one entry per line | ['// my battle', null] |
| Typing speed | TYPE_SPEED, characters per second | var TYPE_SPEED = 50; |
| How long the quiet field stays | AFTERMATH_HOLD, in seconds | var AFTERMATH_HOLD = 20; |
| Play once and stop | LOOP | var LOOP = false; |
| Colours of the two armies | the col('odaBlue'...) and col('takedaRed'...) lines | col('odaBlue', '#6294ff'); |
| How strong each kind of soldier is | hp in resetBattle | hp: 82 for a spearman |
| How many waves attack | the loop for (var w = 1; w <= 4; w++) in resetBattle | Change 4 to 6 for a longer battle |
Questions
Is the battle the same every time?
Nearly. The starting positions are fixed, and the fighting follows rules with a little chance in them, so the result is always similar but small details differ.
Who wins?
Oda Nobunaga's side, as in 1575. The Takeda break some palisades, but their four waves run out first.
Is the three-rank volley historically certain?
No. It is the traditional story of the battle, and many historians now doubt it happened in that neat form. The animation shows the traditional telling.
Does the typed code really run the battle?
No. The typed text is a script for the show. The real code is in the same file, below it, and you can read it.
Can I use it in my own project or video?
Yes. It is under the MIT License for personal and commercial use. Keep the license notice inside the file.