Procedural generation of I Ching hexagrams using PIL and NumPy.
First, install requirements
(PIL and NumPy).
A Hexagram is composed from two of the eight trigrams. Its bars are encoded as binary numbers, from bottom to top, using the digits from left to right.
1
encodes a solid bar, 0
encodes a broken bar.
Pass a 6-digit iterable of 1
/0
or True
/False
to generate the hexagram.
Call dump()
to dump it to hexagram_output/hexagram.png
. Pass an optional string to dump()
to control the output filename.
Call dump_json()
to dump it to hexagram.json
. Pass an optional string to dump_json()
to control the output filename.
Trigrams can be constructed and dumped in the same way; pass a 3-digit iterable.
from hexagram import Hexagram, Trigram
from hexagrams import hexagrams, trigrams
for k, v in hexagrams.items():
h = Hexagram(v)
h.dump(k)
for k, v in trigrams.items():
t = Trigram(v)
t.dump(k)
Can be found here.
The Lottery in Babylon is a very good story. You should read it.