# Generowanie z gramatyk i L-systemów

EN: **Grammars and L-systems for content generation** · id `grammarpcg` · aliases: grammar-based procedural generation, procedural grammars, generowanie proceduralne oparte na gramatykach, gramatyki proceduralne

Path: [AI Atlas](https://aiatlasgraph.com/llms.txt) › [AI w grach](https://aiatlasgraph.com/t/gameai.md) › [Proceduralne generowanie treści gier](https://aiatlasgraph.com/t/pcg.md) › Generowanie z gramatyk i L-systemów

## Description

- PL: Generowanie treści przez wielokrotne stosowanie reguł produkcji: równoległe przepisywanie napisów (L-systemy) dla roślin oraz gramatyki grafowe dla misji i układów poziomów.
- EN: Content generation by repeatedly applying production rules: parallel string rewriting (L-systems) for plants and graph grammars for missions and level layouts.

## In one sentence

- PL: Kilka prostych reguł przepisywania, stosowanych raz za razem, wyhodowuje drzewa, rośliny, budynki albo układy lochów.
- EN: A few simple rewriting rules, applied again and again, grow trees, plants, buildings or dungeon layouts.

## Problem it solves

- PL: Projektant chce tysięcy różnych drzew czy poziomów, ale każdy ma trzymać się sensownej struktury, a nie być przypadkowym bałaganem.
- EN: A designer wants thousands of different trees or levels, each still following a sensible structure rather than random mess.

## What it does

- PL: Działa jak przepis „każda gałąź wypuszcza dwie mniejsze”: po kilku powtórzeniach z jednej kreski robi się całe drzewo.
- EN: It works like the rule 'every branch sprouts two smaller ones': after a few rounds, one line becomes a whole tree.

## Everyday example

- PL: W grze przygodowej każdy loch ma inny układ, a jednak klucz zawsze leży przed drzwiami, które otwiera.
- EN: In an adventure game every dungeon has a different layout, yet the key always lies before the door it opens.

## This concerns you if you…

- PL: generujesz roślinność lub miasta do gry albo wizualizacji
- PL: chcesz losowych poziomów, które zawsze da się przejść
- PL: lubisz matematykę kryjącą się za kształtami natury
- EN: generate vegetation or cities for a game or visualisation
- EN: want random levels that are always beatable
- EN: enjoy the maths behind nature's shapes

## Keywords

L-system · bracketed L-system · turtle graphics · graph grammar · shape grammar · mission graph · Ludoscope · SpeedTree

## How it works

- PL: L-system zaczyna od aksjomatu i w każdym kroku przepisuje wszystkie symbole naraz; wynik czyta żółw graficzny jako polecenia rysowania, a nawiasy zapisują i przywracają jego stan, co daje rozgałęzienia. Gramatyki grafowe przepisują podgrafy misji (wejście, zadanie, klucz, zamek, cel), a osobny krok zamienia misję na geometrię poziomu.
- EN: An L-system starts from an axiom and rewrites all symbols at once each step; turtle graphics reads the result as drawing commands, and brackets save and restore its state, producing branches. Graph grammars rewrite mission subgraphs (entrance, task, key, lock, goal), and a separate step turns the mission into level geometry.

## Limits

- PL: Duże gramatyki trudno zaprojektować i utrzymać, a ich wynik bywa trudny do kontrolowania, np. liczba zadań może wyjść zbyt mała lub bez ograniczenia. Zamiana misji na przestrzeń to najtrudniejszy krok i najlepiej działa w liniowych grach.
- EN: Large grammars are hard to design and maintain, and their output can be hard to control, e.g. the number of tasks may be too small or unbounded. Turning a mission into space is the hardest step and works best for linear games.

## Key terms

- PL: **reguła produkcji**: Przepis, który zastępuje jeden symbol lub fragment innymi.
- PL: **aksjomat**: Początkowy napis lub graf, od którego zaczyna się przepisywanie.
- PL: **grafika żółwia**: Rysowanie przez polecenia: idź naprzód, skręć w lewo, skręć w prawo.
- EN: **production rule**: A recipe that replaces one symbol or fragment with others.
- EN: **axiom**: The starting string or graph that rewriting begins from.
- EN: **turtle graphics**: Drawing by commands: move forward, turn left, turn right.

## Related topics

Untyped, symmetric "see also" links.

- [Generowanie z lokalnych wzorów (Wave Function Collapse) (Wave Function Collapse and constraint-based generation)](https://aiatlasgraph.com/t/wfc.md)

## Sources

- [Grammars and L-systems with applications to vegetation and levels (Procedural Content Generation in Games, ch. 5)](<https://www.pcgbook.com/chapter05.pdf>) `pcgbook-ch05-grammars` · by Julian Togelius, Noor Shaker, Joris Dormans

---

AI Atlas revision 124 (2026-10-31) · HTML: https://aiatlasgraph.com/t/grammarpcg · index: https://aiatlasgraph.com/llms.txt · everything: https://aiatlasgraph.com/llms-full.txt · updated 2026-10-30
