Gallery › Geometry and fractals
Fern, After Barnsley
The chaos game: 48,000 points over four affine maps, with no outline drawn.
How it is made
Michael Barnsley's fern is built by picking one of four simple transformations at random, over and over, and plotting where the point lands. After 48,000 plots a frond appears, though no line of it was drawn. Change the seed and the same fern grows from different dots.
Details
- Category
- Geometry and fractals
- Libraries
- none: this piece is plain PostScript
- Added
- 2026-07-12
- Page size
- 620 × 800 points
Source
View source the whole program in a scrolling window, or read gallery/fern.ps on GitHub. To draw it yourself, from a checkout of the repository:
pscat --page 620x800 gallery/fern.ps
Open it in the playground and watch it draw in your browser: this piece reads no other file, so it runs there unchanged.
The first 40 of 81 lines of the source
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 620 800
%%Title: Fern, After Barnsley
%%Creator: Claude, resident artist
%%EndComments
% The chaos game: one point, four affine maps chosen at random with the
% classic Barnsley weights, forty-eight thousand hops. No outline is ever
% drawn — the fern condenses out of probability. Color deepens with
% height so the frond tips catch the light.
/seed 8675309 def
/rand01 {
/seed seed 1103515245 mul 12345 add 2147483648 mod def
seed 2147483648 div
} def
/sethsb {
3 dict begin
/v exch def /s exch def /h exch def
/h h h 360 div floor 360 mul sub def
/i h 60 div floor def
/f h 60 div i sub def
/p v 1 s sub mul def
/q v 1 s f mul sub mul def
/t v 1 s 1 f sub mul sub mul def
i 0 eq { v t p } {
i 1 eq { q v p } {
i 2 eq { p v t } {
i 3 eq { p q v } {
i 4 eq { t p v } {
v p q } ifelse } ifelse } ifelse } ifelse } ifelse
setrgbcolor
end
} def
/box {
4 dict begin
/hh exch def /ww exch def /yy exch def /xx exch def
newpath xx yy moveto ww 0 rlineto 0 hh rlineto ww neg 0 rlineto