Aspect ratio calculator / The Dragon and the Hill in ASCII

The Dragon and the Hill in ASCII

A dragon, a knight and his soldiers, printed in text. Click them, and they answer.

ASCII · 2026 series · All animations

Click the dragon for fire. Click the knight or the soldiers for a war cry. Drag to turn. Free under the MIT License.

What it is

A battle scene printed with letters and symbols. A red, winged dragon of the European kind hovers beside a hill. On the hilltop a knight sits on his horse under a banner, with foot soldiers and their spears spread down the slope. The whole scene is a small 3D model that turns slowly, and every part of it is drawn as text: # and @ for the dragon’s lit scales, / and X for its wing membranes, ^ for grass and spear points.

The dragon is alive in the model, not a fixed picture. Its wings beat, its tail and neck sway, and its head drops to aim when it breathes.

It reacts to you

What you doWhat happens
Click or tap the dragonIt lowers its head, opens its jaw and sweeps a stream of fire from one side of the hill to the other and back. The soldiers duck.
Click or tap the knight, the banner or a soldierThe army shouts “HOLD THE HILL!”, the soldiers jump and shake their spears, and a volley of arrows flies at the dragon.
Drag left or rightThe scene turns, with a little momentum.
Do nothingThe dragon breathes fire by itself every 12 to 22 seconds.
Press SoundTurns on a roar for the fire and two horn notes for the war cry (off by default).

The two buttons under the scene, Dragon fire and War cry, do the same as the clicks.

How the clicks know what you hit

While the page prints the characters, it also notes for every cell what is drawn there: nothing, the army or the dragon. A click looks up that note for the cell under the pointer and its neighbours. Because the note is made after depth sorting, you can only hit what you can actually see: if the dragon’s wing is in front of the banner, the click goes to the dragon.

How to take it

Press Download the HTML file above to get ascii-dragon-battle.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.

View the code
Loading…

Embed it on your page

<iframe src="https://aspect.tools/ascii-dragon" style="border:0;width:100%;max-width:860px;aspect-ratio:860/830" title="The Dragon and the Hill in ASCII" loading="lazy"></iframe>

License and credit

MIT License. You can use it, change it, share it and sell things made with it, for personal or commercial work. The one condition: keep the copyright and license notice that is at the top of the file.
The Dragon and the Hill in ASCII, 2026 series, by aspect.tools (https://aspect.tools/ascii-dragon-battle), MIT License

A visible credit is appreciated but not required.

How to change it

What to changeWhereExample
The words on screenBANNER and CRYvar CRY = 'H O L D T H E H I L L !';
Dragon colours and charactersthe mat('dragon'...), mat('wing'...) and mat('belly'...) linesmat('dragon', 60, 160, 90) for a green dragon
Where the dragon hoversDR: x, height, zDR = { x: 22, y: 26, z: 0 }
The knightthe KNIGHT text picture: each letter is one block'.....rkkl....'
Number and place of soldiersthe SOLDIERS list of positions[-4, 7]
Shape of the hillhillY12 * Math.exp(...)
Length and width of the fire sweepBREATH (seconds) and SWEEP (how far to each side)BREATH = 3.2, SWEEP = 26
How often the dragon attacks by itselfthe line that sets nextBreath12 + Math.random() * 10

Questions

What can I click?

Click the dragon to make it breathe fire. Click the knight, the banner or any soldier to make the army shout and shoot arrows.

Is the dragon a fixed drawing?

No. It is a 3D model rebuilt on every frame, so the wings beat, the tail sways and the head moves, and it looks right from every side.

Can I change the dragon to another colour?

Yes. Change the red, green and blue numbers on the dragon, wing and belly lines near the top of the script.

Can I use it in my own project?

Yes. It is under the MIT License for personal and commercial use. Keep the license notice inside the file.

Does it work on phones?

Yes. Tap instead of clicking, and drag with a finger to turn the scene.

Related tools and guides