This page is under development. Comments are welcome, but please load any comments in the comments section at the bottom of the page. Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Aside from your courtesy, your wiki MONIKER and date as a signature and minimal good faith of any internet post are the rules of this TCL-WIKI. Its very hard to reply reasonably without some background of the correspondent on his WIKI bio page. Thanks, gold 12Dec2018
The Iching is the ancient fortune telling book of China. The Iching literature mentions various methods for casting fortune patterns of Iching. The various methods include hot ironing of turtle shells (-t.), manipulations of yarrow sticks, flipping coins, throwing shaman bones, and dice. One analogy from North America is a shaman throwing or shuffling stick dice.
I made three stick dice for Iching by cutting a dowel of square cross section into three sticks. For the three stick dice, the flat sides are marked or burned with 2 or 3 holes alternately. Two sticks are marked with {3 2 3 2} dots on the sides. One stick is marked with {3 3 3 2} dots on the sides. In casting such three dice, the possible sums are 6,7,8, or 9. Further, the stick dice are cast six times to obtain whole lines or broken lines in a pattern or set of six lines. A set of six Iching lines is called a gua in the orient or a hexagram in some translations of the Chinese.
In the Iching interpretations, casts of 6 and 8 are broken or yin (female) lines, while casts of 7 and 9 are whole or yang (male) lines. The casts are recorded by pencil with the first line at bottom and marking up the column. It is possible to record the numbers from the casts with tally sticks or Chinese counting rods, which are somewhat reminiscent of the Iching patterns themselves. After marking the original pattern or hexagram, sometimes a second follow-up hexagram is developed by swapping throws of 6 for a 7 and throws of 9 for a 6. These swaps effectively trade a broken line(6) for a whole line(7) and a whole line(9) for a broken line(6). The throws for the changing lines (6&9) may not always be come out in the first hexagram or its component lines, so the followup hexagram may not exist {under consistent rules}. If the first hexagram is interpreted on a line by line basis, any changing lines(6&9) or second hexagram offers some modification or discount on the interpretation of the first hexagram.
In developing a computer program or application, it is helpful to develop analogs for the individual tasks of the application. An Iching application would have to compose, beg, or borrow TCL procedures for random casts, tallies of scores, accounting files, display hexagram lines on a screen, swapping changing lines, hexagram pattern recognition and ranking interpretations. In fact, some TCL one liner procedures and text swapping routines might be useful as utilities in a starter application program, since unruly text strings are expected in the Iching. Casting the sticks or bones for each Iching line is analog for random lpick subroutine below. Adding the top sides of three sticks and throwing six times is analog for the "for 6 times" statement in the bonereadxx procedure below. In the West, Leibniz etc recognized that the whole and broken lines in the hexagram patterns could be counted as ones and zeros, respectively in a binary number system. For example, a cast or TCL list of { 6,7,8,9,6,7 } could be expressed as a binary number, 010101. The binary numbers are the analogs for the binaryexchange subroutine below. For computer procedures, the patterns are effectively a horizontal bar code of 6 lines.
In the process of designing the basic subroutine tasks, we could throw in some switches, logic chains, or daisy chains that break the outset rules given above. For example, TCL is so good at swapping lines (6&9) for the second hexagram, that it would be easy to put a switch that generates or swaps all hexagram lines (6,7,8,&9) for their opposites. Also from some scripts of the Chinese Chou dynasty, different Iching fortune methods of yarrow sticks or coins would generate different probabilities of obtaining each hexagram line. Might be interesting to have a back door in the program to check (or adapt} the different probabilities of stick or coin throws.
Several authors have pointed out that a few of the hexagrams look similar to Chinese characters or even Mayan calendar notation. Without wading too deep into alternate realities, the Iching hexagrams could be used as numerals, script alphabet, dial markers, game tokens, symbol recognition code, or maybe a programming language (like Greek letters for APL operators). Such rule breaking helps keep the finished program more flexible.
+----------------------------------------------------------------------------------+
| THREE STICK DICE: CONSTRUCTION AND MARKINGS |
| Square-cross-section dowel cut into 3 sticks |
| Flat sides burned or marked with dot patterns |
| |
| Stick 1 (special): sides marked { 3 3 3 2 } (three 3-sides, one 2-side) |
| Stick 2 (regular): sides marked { 3 3 2 2 } (two 3-sides, two 2-sides) |
| Stick 3 (regular): sides marked { 3 3 2 2 } (two 3-sides, two 2-sides) |
| |
| In TCL (bonereadxx, coinsread==1): |
| bone1 = lpick { 3 3 3 2 } |
| bone2 = lpick { 3 3 2 2 } |
| bone3 = lpick { 3 3 2 2 } |
| bonereading = bone1 + bone2 + bone3 |
| |
| Possible sums and their meanings: |
| +------+-------+----------+------------------------------------+ |
| | sum | value | type | I Ching meaning | |
| +------+-------+----------+------------------------------------+ |
| | 6 | 2+2+2 | old yin | broken, changing --> yang | |
| | 7 | 3+2+2 | yng yang | whole, static | |
| | 8 | 3+3+2 | yng yin | broken, static | |
| | 9 | 3+3+3 | old yang | whole, changing --> yin | |
| +------+-------+----------+------------------------------------+ |
| |
| Sticks cast SIX times --> one complete hexagram (6 lines) |
| Results recorded from bottom to top (line 1 = first cast) |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+
| COIN TOSS vs STICK DICE: PROBABILITY COMPARISON |
| |
| Coin toss (3 coins, coinsread==2): |
| bone1 = bone2 = bone3 = lpick { 3 3 2 2 } (all symmetric) |
| |
| +-------+------+--------------------+--------------------+---------------------+|
| | value | type | stick dice P | coin toss P | notes ||
| +-------+------+--------------------+--------------------+---------------------+|
| | 6 | o.yin| 1*2*2/64 = 4/64 | 2*2*2/64 = 8/64 | chg yin --> yang ||
| | | | = 0.0625 | = 0.1250 | ||
| | 7 | y.yng| (3*2*2+3*2*2 | (3*2*2+3*2*2 | static yang ||
| | | | +3*3*2*2)/64 | +3*3*2*2)/64 | (stick: 7/16 most ||
| | | | = 28/64 = 0.4375 | = 24/64 = 0.3750 | common) ||
| | 8 | y.yin| 20/64 = 0.3125 | 24/64 = 0.3750 | static yin ||
| | 9 | o.yng| 12/64 = 0.1875 | 8/64 = 0.1250 | chg yang --> yin ||
| +-------+------+--------------------+--------------------+---------------------+|
| |
| Key difference: |
| Stick dice: asymmetric (7 most common at 7/16, 6 rarest at 1/16) |
| Coin toss: symmetric (8 and 7 equally likely at 6/16 each) |
| Both: P(changing line) = (4+12)/64 or (8+8)/64 = 16/64 = 0.25 |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+
| HEXAGRAM CASTING FLOW (bonereadxx proc) |
| |
| Input: coinsread (1 = stick dice, 2 = coin toss) |
| | |
| v |
| FOR j = 0 to 5 (6 lines): |
| bone1 = lpick { 3 3 3 2 } or { 3 3 2 2 } (by coinsread mode) |
| bone2 = lpick { 3 3 2 2 } |
| bone3 = lpick { 3 3 2 2 } |
| wow = bone1 + bone2 + bone3 (value 6, 7, 8, or 9) |
| lappend gualisting wow |
| | |
| v |
| gualisting = lreverse(gualisting) <-- read top-down (standard display) |
| | |
| v |
| guabinary = binaryexchange(gualisting) (6,8 --> 0; 7,9 --> 1) |
| decimalout = convertbase2to10(guabinary) (binary string to integer) |
| bookgua = kvsearch(bookvalue2, decimalout) (hexagram number lookup) |
| second_hexa = second_hexagram_compute(gualisting) (changing lines swapped) |
| | |
| v |
| Display in .wxxccc text widget: |
| "last bone N, gua listing, binary, decimal, Iching gua #, 2nd hex." |
| | |
| v |
| castfortune --> draw hexagram rectangles on .can canvas |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+
| BINARY EXCHANGE AND BASE CONVERSION (binaryexchange + convertbase2to10) |
| |
| binaryexchange {gualisting}: |
| Map line values to binary digits: |
| 6 --> 0 (yin, broken line) |
| 7 --> 1 (yang, whole line) |
| 8 --> 0 (yin, broken line) |
| 9 --> 1 (yang, whole line) |
| Remove spaces --> return binary string |
| |
| Example: gualisting { 6 7 8 9 6 7 } (top to bottom after lreverse) |
| guabinary = "010101" |
| |
| convertbase2to10 {jip}: |
| Split binary string to list of digits |
| For each digit n at position e (0-indexed from right): |
| t += n * int(2^e) |
| Return decimal integer |
| |
| Example: "010101" (left=high bit, right=low bit) |
| pos: 5 4 3 2 1 0 |
| val: 0 1 0 1 0 1 |
| sum: 0 +16+ 0 + 4 + 0 + 1 = 21 |
| |
| kvsearch(bookvalue2, 21) --> Iching hexagram number from lookup table |
| |
| Note: lreverse applied BEFORE binaryexchange gives different binary value |
| than no-reverse. Consistent application is critical for correct hexagram #. |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+
| SECOND HEXAGRAM COMPUTATION (second_hexagram_compute proc) |
| Changing lines (6 and 9) swapped to opposite yang/yin |
| |
| Swap rules: |
| 6 (old yin, changing) --> 7 (young yang, static) |
| 9 (old yang, changing) --> 6 (old yin... renders as yin next step) |
| 7 (young yang, static) --> unchanged |
| 8 (young yin, static) --> unchanged |
| |
| In TCL (plainsub string replacement): |
| second_hexagram = join(gualisting) |
| second_hexagram = plainsub(second_hexagram, "6", "7") <- 6 to 7 |
| second_hexagram = plainsub(second_hexagram, "9", "6") <- 9 to 6 |
| |
| IMPORTANT WARNING: |
| plainsub uses simple string substitution. |
| "9" --> "6" must come AFTER "6" --> "7", or 6s just swapped will |
| be re-swapped to 7 in the next pass. |
| Order matters for correct output. |
| |
| Example: |
| gualisting: { 9 8 7 6 7 8 } |
| after 6-->7: { 9 8 7 7 7 8 } |
| after 9-->6: { 6 8 7 7 7 8 } |
| second_hexagram: { 6 8 7 7 7 8 } |
| --> then binaryexchange + convertbase2to10 --> second hexagram number |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+ | CANVAS DISPLAY: HEXAGRAM RECTANGLES (castfortune proc) | | Two hexagrams drawn side by side on .can canvas | | | | Layout: dx=50, dy=30, 3 columns x 6 rows | | Only the MIDDLE column (j==1) uses hexagram line color | | Left (j==0) and right (j==2) always = solid fill color (border columns) | | | | Hexagram 1 (primary cast, LEFT panel): | | +-------+-------------------+----------------------------------+ | | | value | middle col color | meaning | | | +-------+-------------------+----------------------------------+ | | | 6 | white (open) | old yin = broken changing line | | | | 7 | brown (solid) | young yang = whole static line | | | | 8 | white (open) | young yin = broken static line | | | | 9 | brown (solid) | old yang = whole changing line | | | +-------+-------------------+----------------------------------+ | | | | Hexagram 2 (second/future, RIGHT panel, offset x+=180): | | Same rules but blue=solid instead of brown=solid | | white=open (yin) same as primary | | | | Canvas .can: scrollable (yscrollcommand .scr), width=240, bg=colorground | | Text .wxxccc: 80 wide x 3 high, shows full cast details on screen | +----------------------------------------------------------------------------------+
+----------------------------------------------------------------------------------+
| UTILITY PROC LIBRARY (string and list manipulation) |
| |
| +----------+------------------------------------------+------------------------+|
| | proc | syntax / example | effect ||
| +----------+------------------------------------------+------------------------+|
| | lpick | lpick {a b c} | random pick from list ||
| | plainsub | plainsub text item replacewith | string find+replace ||
| | %+ | %+ tree --> TREE | to uppercase ||
| | %- | %- TREE --> tree | to lowercase ||
| | %++ | %++ tree root --> treeroot | string concat ||
| | %-- | %-- "5 7" 7 --> "5 " | remove first match ||
| | %% | %% "tree root" root --> "tree " | remove all matches ||
| | %2x | %2x tree --> treetree | double string ||
| | %3x | %3x tree --> treetreetree | triple string ||
| | %5x | %5x tree --> tree tree tree| spaced triple ||
| | srevert | srevert "hello" --> "olleh" | reverse string (RS) ||
| | lreverse | lreverse {a b c} --> {c b a} | reverse list (RS) ||
| | sumoflist| sumoflist {1 2 3 4} --> 10 | sum list elements (RS) ||
| | average | average {1 2 3 4} --> 2.5 | mean of list (RS) ||
| | whitelist| whitelist "a b c" --> {a b c} | strip blank elements ||
| | repeat | repeat 3 {puts hi} | runs body N times ||
| | random | random 6 --> 0..6 | int random 0..n ||
| | kvsearch | kvsearch kvlist item | key-value pair lookup (RS) ||
| +----------+------------------------------------------+------------------------+|
| |
| convertbase2to10: binary string "010101" --> decimal integer 21 |
| binaryexchange: gualisting {6 7 8 9} --> binary string "0101" |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+
| HEXAGRAM NAME DATABASE (chartbamboo list, API-style key:value pairs) |
| Format: hexagram_N : pinyin NAME wade WADE english {ENGLISH TITLE} |
| Punctuation stripped by plainsub before use |
| |
| +----+----------+---------------+------------------------------------------+ |
| | # | pinyin | Wade-Giles | English (Wilhelm/Baynes) | |
| +----+----------+---------------+------------------------------------------+ |
| | 1 | Qian | Ch'ien | The Creative | |
| | 2 | Kun | K'un | The Receptive | |
| | 3 | Zhun | Chun | Difficulty at the Beginning | |
| | 4 | Meng | Meng | Youthful Folly | |
| | 5 | Xu | Hsu | Waiting | |
| | 6 | Song | Sung | Conflict | |
| | 7 | Shi | Shih | The Army | |
| | 8 | Bi | Pi | Holding Together | |
| | 9 | Xiaoxu | Hsiao Ch'u | The Taming Power of the Small | |
| | 10 | Lu | Lu | Treading | |
| | 11 | Tai | T'ai | Peace | |
| | 12 | Pi | P'i | Standstill | |
| | 63 | Jiji | Chi Chi | After Completion | |
| | 64 | Weiji | Wei Chi | Before Completion | |
| +----+----------+---------------+------------------------------------------+ |
| (full 64-hexagram table in Appendix Tables section of wiki page) |
| |
| Access pattern: kvsearch $bookvalue2 $decimalout --> hexagram number |
| bookvalue2 starts with sentinel 9999 at index 0 (1-indexed lookup) |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+ | EIGHT TRIGRAMS TABLE (from Appendix, Wilhelm/Baynes associations) | | | | +---+--------+----------+-------+-------+------------------------------------+ | | | # | pinyin | Wade-G. | symbol| lines | associations | | | +---+--------+----------+-------+-------+------------------------------------+ | | | 1 | Qian | Ch'ien | Heaven| 111 | creative, Father, NW, head, lungs | | | | 2 | Kun | K'un | Earth | 000 | receptive, Mother, SW, abdomen | | | | 3 | Zhen | Chen | Thunder| 001 | arousing, Eldest Son, E, throat | | | | 4 | Kan | K'an | Water | 010 | abysmal, Middle Son, N, kidneys | | | | 5 | Gen | Ken | Mountain|011 | keeping still, Youngest Son, NE | | | | 6 | Xun | Sun | Wind | 100 | gentle, Eldest Daughter, SE, hips | | | | 7 | Li | Li | Flame | 101 | clinging, Middle Daughter, S, eyes | | | | 8 | Dui | Tui | Lake | 110 | joyous, Youngest Daughter, W, mouth| | | +---+--------+----------+-------+-------+------------------------------------+ | | | | Hexagram = lower trigram (lines 1-3) + upper trigram (lines 4-6) | | Hexagram number = upper_trigram_index * 8 + lower_trigram_index | | | | Trigram lines: 1 = yang (whole), 0 = yin (broken) | | Read bottom to top (e.g. 001 = yin yin yang at lines 1 2 3) | +----------------------------------------------------------------------------------+
+----------------------------------------------------------------------------------+
| HEXAGRAM AS BAR CODE: BINARY NUMBER ANALOGY (Leibniz observation) |
| |
| Leibniz (17th century): recognized whole/broken lines = 1s and 0s |
| Hexagram = horizontal bar code of 6 lines = 6-bit binary number |
| |
| Example cast: { 6 7 8 9 6 7 } (top to bottom after lreverse) |
| |
| Line 6 (top): 7 yang --> 1 ||||||||||||||||||||||||||||||||||||| |
| Line 5: 6 yin --> 0 |||||||| |||||||| |
| Line 4: 9 yang --> 1 ||||||||||||||||||||||||||||||||||||| |
| Line 3: 8 yin --> 0 |||||||| |||||||| |
| Line 2: 7 yang --> 1 ||||||||||||||||||||||||||||||||||||| |
| Line 1 (bot): 6 yin --> 0 |||||||| |||||||| |
| |
| Binary: 010101 (read top to bottom = high to low bit) |
| Decimal: 21 |
| kvsearch(bookvalue2, 21) --> Hexagram # |
| |
| Extended uses for hexagram patterns noted in Conclusions: |
| numerals, script alphabet, dial markers, game tokens, |
| symbol recognition codes, APL-like operator glyphs, |
| Mayan calendar notation analogs |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+
| FILE BROWSER / STARTER PROC (top section of program) |
| Opens files in Notepad on left mouse double-click |
| (Windows-specific, written for Windows XP / Windows 10) |
| |
| xlistlistbox: |
| .labellabel delete 0 end |
| foreach filefile [glob .* *]: |
| if directory: append "/" to name |
| .labellabel insert end filefile |
| |
| xskipskipdirectory {dir}: |
| cd $dir |
| .realcommand configure -text [pwd] |
| xlistlistbox |
| |
| clickclicklistbox: |
| get curselection index |
| if directory: call xskipskipdirectory |
| else: exec notepad $filename (Windows editor) |
| |
| Main window layout: |
| +---------------------------+ .labelframe (directory path label) |
| | .labellabel (listbox) | .listlistbox (scrollable file list) |
| | with x and y scrollbars | .buttonbuttonx (Cast_Bones | Coin_Toss | Exit)|
| +---------------------------+ .ww (holding tank label) |
| | .wxxccc (text output 80x3)| .can (scrollable canvas, width=240) |
| +---------------------------+ .scr (vertical scrollbar for canvas) |
| |
| Initialized: xskipskipdirectory $env(HOME) (starts at home directory) |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+
| ICHING APPLICATION: REQUIRED SUBROUTINE ANALOGS |
| Each physical I Ching task mapped to a TCL procedure |
| |
| +----------------------------+-----------------------------------------------+ |
| | physical I Ching task | TCL analog | |
| +----------------------------+-----------------------------------------------+ |
| | cast sticks/bones/coins | lpick {3 3 3 2} etc. + sum (bonereadxx) | |
| | throw 6 times | for j 0 to 5 loop (bonereadxx) | |
| | tally scores | lappend gualisting wow | |
| | record cast bottom to top | lreverse gualisting | |
| | display hexagram lines | castfortune (canvas rectangles) | |
| | swap changing lines (6,9) | plainsub "6"-->"7", "9"-->"6" (second_hex) | |
| | hexagram pattern lookup | binaryexchange + convertbase2to10 + kvsearch | |
| | rank interpretations | kvsearch bookvalue2 / chartbamboo database | |
| | tally sticks (counting rod)| Chinese counting rod analogy to list display | |
| | accounting files | text widget .wxxccc + console output | |
| +----------------------------+-----------------------------------------------+ |
| |
| Two casting modes via button: |
| Cast_Bones --> bonereadxx 1 (stick dice: asymmetric probabilities) |
| Coin_Toss --> bonereadxx 2 (coin toss: symmetric probabilities) |
| Both call castfortune after cast to update canvas display |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+ | OVERALL PROGRAM FLOW (Iching_Fortunes, 6Feb2007, gold) | | | | Startup: | | package require Tk | | set colorground bisque | | build GUI (frames, listbox, canvas, buttons, text, scrollbars) | | xskipskipdirectory $env(HOME) --> populate file browser | | | | | v | | User action: double-click file in listbox | | --> clickclicklistbox --> exec notepad (or cd into directory) | | | | User action: push Cast_Bones button | | --> bonereadxx 1 (stick dice mode) | | --> castfortune (update canvas) | | | | User action: push Coin_Toss button | | --> bonereadxx 2 (coin toss mode) | | --> castfortune (update canvas) | | | | Inside bonereadxx: | | 6x lpick --> gualisting | | lreverse --> binaryexchange --> convertbase2to10 --> kvsearch bookvalue2 | | second_hexagram_compute --> kvsearch bookvalue | | display in .wxxccc: bone, gualisting, binary, decimal, hex #, 2nd hex # | | | | Inside castfortune: | | draw 3x6 rectangle grid for primary hexagram (brown/white, left) | | draw 3x6 rectangle grid for second hexagram (blue/white, right) | +----------------------------------------------------------------------------------+
+----------------------------------------------------------------------------------+
| BOOKVALUE2 LOOKUP TABLE STRUCTURE (key-value pair list) |
| Maps decimal binary-exchange output --> King Wen hexagram number |
| |
| bookvalue2 format: { 9999 1 63 43 62 14 61 ... } |
| Index 0: sentinel 9999 (makes list 1-indexed for kvsearch) |
| Index 1: 1 (decimal 0 binary --> hexagram 1?) |
| Index 2: 63 ... |
| ... |
| |
| kvsearch {kvlist item} (RS proc): |
| pos = lsearch kvlist item |
| if pos == -1: return nothing |
| return lindex kvlist (pos+1 - 2*(pos%2)) |
| --> returns the PARTNER of the found item (odd/even pair logic) |
| |
| bookvalue (without sentinel): |
| same content starting directly with first value |
| used in second_hexagram_compute |
| |
| Example lookup: |
| gualisting { 6 7 8 9 6 7 } --> guabinary "010101" |
| convertbase2to10("010101") --> 21 |
| kvsearch bookvalue2 21 --> hexagram number (King Wen sequence) |
+----------------------------------------------------------------------------------++----------------------------------------------------------------------------------+ | ALTERNATE USES: HEXAGRAM PATTERNS BEYOND DIVINATION | | From Conclusions section -- rule-breaking for flexible programs | | | | +---------------------------+------------------------------------------------+ | | | use | notes | | | +---------------------------+------------------------------------------------+ | | | numerals | 6-bit binary 0..63, 64 unique symbols | | | | script alphabet | some hexagrams look like Chinese characters | | | | | or Mayan calendar notation | | | | dial markers | 64-position dial (6x finer than 8-bit) | | | | game tokens | 64 distinct tokens for board games | | | | symbol recognition codes | pattern matching / barcode-like identification | | | | programming language | APL used Greek letters as operators; | | | | | hexagrams as operator glyphs possible | | | | probability back-door | swap probabilities to test yarrow/coin/dice | | | | | different casting methods | | | | full swap switch | swap all lines (6,7,8,9) to opposites, | | | | | not just changing lines (6,9) | | | | weather prediction | see Chinese Iching Random Weather Predictions | | | | kingdom strategy game | see Game Kingdom of Strategy (Iching_Fortunes | | | | | code was starter for that game) | | | +---------------------------+------------------------------------------------+ | | | | Random divination (non-Iching) keywords: | | Limyran, Lycia, Sortes Astrampsych, Thomas Oracle, Bibliomancy | +----------------------------------------------------------------------------------+
#!/usr/bin/env wish
# pretty print version from autoindent and ased editor
#Iching_Fortunes
# or Itching For Tunes [%>}
# 6Feb2007, [gold]
# working on XP starter code
# top browser is written for windows
# and should open file in notepad,
# on left mouse click.
package require Tk
global bookvalue bookvalue2
set colorground bisque
set wow "bone number"
proc xlistlistbox {} {
.labellabel delete 0 end
foreach filefile [glob .* *] {
if [file isdirectory $filefile] {
set filefile "$filefile/"
}
.labellabel insert end $filefile;
}
}
proc xskipskipdirectory {dir} {
cd $dir
.realcommand configure -text [pwd]
xlistlistbox
}
proc clickclicklistbox {} {
catch { set index [lindex [.labellabel curselection] 0] }
if { $index == "" } { return }
set filename [.labellabel get $index]
if [file isdirectory $filename] {
xskipskipdirectory $filename
} else {
#exec xedit $file &
# windows editor
exec notepad $filename}}
wm title . "File Starter"
frame .labelframe
pack .labelframe -expand no -fill x
label .labellabel1 -text "Directory:"
label .realcommand -text "" \
-relief groove
pack .labellabel1 -in .labelframe \
-side left -expand no -fill x
pack .realcommand -in .labelframe \
-side left -expand yes -fill x -anchor w
frame .listlistbox
pack .listlistbox -expand yes -fill both
listbox .labellabel \
-width 25 -height 3 \
-xscrollcommand ".xxxxaxis set" \
-yscrollcommand ".yyyyaxis set" \
-bg $colorground
scrollbar .yyyyaxis \
-command ".labellabel yview" \
-orient v
scrollbar .xxxxaxis \
-command ".labellabel xview" \
-orient h
pack .xxxxaxis -in .listlistbox -side bottom -fill x -expand no
pack .yyyyaxis -in .listlistbox -side right -fill y -expand no
pack .labellabel -in .listlistbox -side top -fill both -expand yes
frame .buttonbuttonx
pack .buttonbuttonx -fill x
button .caster -text Cast_Bones -command {bonereadxx 1 ;castfortune;}
button .coinster -text Coin_Toss -command {bonereadxx 2;castfortune;}
button .done -text Exit -command exit
pack .caster .coinster .done -in .buttonbuttonx \
-side top -fill x
bind .labellabel <Double-1> clickclicklistbox
pack [ label .ww -text "Iching holding tank " -bg $colorground]
pack [ text .wxxccc -width 80 -height 3 -bg beige ]
focus .wxxccc ;# allow keyboard input
.wxxccc insert end "xxx starter xxx ";
scrollbar .scr -orient vertical -command ".can yview"
canvas .can -yscrollcommand ".scr set" -width 240 -bg $colorground
pack .can -fill both -expand 1 -side left
pack .scr -fill y -expand 0 -side left
set width 50
set height 50
set w ".can"
set x 100
set y 100
set dx 50
set dy 30
set colors {white black }
set color 0
#suchenwirth_subroutine;}
proc lpick L {lindex $L [expr {int(rand()*[llength $L])} ];}
# utilities
proc plainsub {text item replacewith} {
set text [string map [list $item $replacewith] $text]
}
proc %+ {a } {return [string toupper $a]; #%+ tree >TREE }
proc %- {a } {return [string tolower $a]; #%+ Tree >tree }
proc %++ {a b} {return $a$b;#%+* tree root >treeroot }
proc %-- {a b} {regsub $b $a "" a; return $a;#%-- 5 7>5 }
proc %% {a b} {regsub -all $b $a "";#%% tree root >tree }
proc %1 {a b} {regsub $b $a "" a; return $a;#%1 tree root>tree }
proc %2 {a b} {regsub $b $a "" a;regsub $b $a "" a; return $a;#%2 tree root>tree }
proc %3 {a b} {regsub $b $a "" a;regsub $b $a "" a;regsub $b $a "" a; return $a;#%3 tree root>tree}
proc %2x {a} {return $a$a;#%2x tree>treetree}
proc %3x {a} {return $a$a$a;#%3x tree>treetreetree}
proc %4x {a} {return "$a,$a,$a";#%5x tree>tree,tree,tree }
proc %5x {a} {return "$a $a $a";#%5x tree>tree tree tree }
proc repeat {n body} {while {$n} {incr n -1; uplevel $body}}
proc random n {expr {round($n*rand())}}
proc whitelist {a} {return [lreplace $a 0 -1];#take string,return list without blanks}
set k [split {abcdefghijklmnopqrstuvwxyz} {}]
proc average L {expr ([join $L +])/[llength $L].}
proc srevert s {
set l [string length $s]
set res ""
while {$l} {append res [string index $s [incr l -1]]}
set res
};# RS,
proc lreverse L {
set res {}
set i [llength $L]
#while {[incr i -1]>=0} {lappend res [lindex $L $i]}
while {$i} {lappend res [lindex $L [incr i -1]]} ;# rmax
set res
} ;# RS, tuned 10% faster by [rmax]
proc sumoflist L {expr [join [split $L ""] +]+0} ;# RS
proc convertbase2to10 {jip} {
set l [split $jip ""]
set t 0; set e 0;
foreach n $l {
set exp [ expr int(pow(2,$e))];
incr t [ expr $n * $exp ] ;
incr e;
}
return $t}
proc kvsearch {kvlist item} {
set pos [lsearch $kvlist $item]
if {$pos != -1} {
lindex $kvlist [expr {$pos+1-2*($pos%2)}]
}
} ;# RS
# end utilities
#start iching data
set bookvalue [ list 1 63 43 62 14 61 34 60 9 59 5 58 26 57 11 56 10 55 58 54 38 53 54 52 61 51 60 50 41 49 19 48 13 47 49 46 30 45 55 44 37 43 63 42 22 41 36 40 25 39 17 38 21 37 51 36 42 35 3 34 27 33 24 32 44 31 28 30 50 29 32 28 57 27 48 26 18 25 46 24 6 23 47 22 64 21 40 20 59 19 29 18 4 17 7 16 33 15 31 14 56 13 62 12 53 11 39 10 52 9 15 31 14 56 13 62 12 53 11 39 10 52 9 15 8 12 7 45 6 35 5 16 4 20 3 23 1 2 0 8 2 ]
set bookvalue2 [ list 9999 1 63 43 62 14 61 34 60 9 59 5 58 26 57 11 56 10 55 58 54 38 53 54 52 61 51 60 50 41 49 19 48 13 47 49 46 30 45 55 44 37 43 63 42 22 41 36 40 25 39 17 38 21 37 51 36 42 35 3 34 27 33 24 32 44 31 28 30 50 29 32 28 57 27 48 26 18 25 46 24 6 23 47 22 64 21 40 20 59 19 29 18 4 17 7 16 33 15 31 14 56 13 62 12 53 11 39 10 52 9 15 31 14 56 13 62 12 53 11 39 10 52 9 15 8 12 7 45 6 35 5 16 4 20 3 23 1 2 0 8 2 ]
if 0 { iching hexagrams and trigrams }
if 0 { Little API style database }
set chartbamboo { " list
+ hexagram_1 : pinyin Qian wade Ch'ien english {The Creative }
+ hexagram_2 : pinyin Kun wade K'un english {The Receptive}
+ hexagram_3 : pinyin Zhun wade Chun english { Difficulty at the Beginning }
+ hexagram_4 : pinyin Meng wade Mêng english {Youthful Folly }
+ hexagram_5 : pinyin Xu wade Hsü english {Waiting }
+ hexagram_6 : pinyin Song wade Sung english {Conflict }
+ hexagram_7 : pinyin Shi wade Shih english {The Army }
+ hexagram_8 : pinyin Bi wade Pi english {Holding Together}
+ hexagram_9 : pinyin Xiaoxu wade Hsiao Ch'u english {The Taming Power of the Small}
+ hexagram_10 : pinyin Lü wade Lü english {Treading}
+ hexagram_11 : pinyin Tai wade T'ai english {Peace }
+ hexagram_12 : pinyin Pi wade P'i english {Standstill }
+ hexagram_13 : pinyin Tongren wade {T'ung Jên} english {Fellowship with Men }
+ hexagram_14 : pinyin Dayou wade { Ta Yu } english {Possession in Great Measure }
+ hexagram_15 : pinyin Qian wade Ch'ien english {Modesty }
+ hexagram_16 : pinyin Yu wade Yü english {Enthusiasm }
+ hexagram_17 : pinyin Sui wade Sui english {Following }
+ hexagram_18 : pinyin Gu wade Ku english {Work on What Has Been Spoiled }
+ hexagram_19 : pinyin Lin wade Lin english {Approach }
+ hexagram_20 : pinyin Guan wade Kuan english {Contemplation }
+ hexagram_21 : pinyin Shike wade {Shih Ho } english {Biting Through }
+ hexagram_22 : pinyin Bi wade Pi english {Grace }
+ hexagram_23 : pinyin Bo wade Po english {Splitting Apart }
+ hexagram_24 : pinyin Fu wade Fu english {Return }
+ hexagram_25 : pinyin Wuwang wade { Wu Wang }english {Innocence }
+ hexagram_26 : pinyin Daxu wade { Ta Ch'u } english {The Taming Power of the Great }
+ hexagram_27 : pinyin Yi wade I english {The Corners of the Mouth }
+ hexagram_28 : pinyin Daguo wade { Ta Kuo } english {Preponderance of the Great }
+ hexagram_29 : pinyin Kan wade K'an english {The Abysmal }
+ hexagram_30 : pinyin Li wade Li english {The Clinging }
+ hexagram_31 : pinyin Xian wade Hsien english {Influence }
+ hexagram_32 : pinyin Heng wade Hêng english {Duration}
+ hexagram_33 : pinyin Dun wade Tun english {Retreat }
+ hexagram_34 : pinyin Dazhuang wade { Ta Chuang } english {The Power of the Great }
+ hexagram_35 : pinyin Jin wade Chin english {Progress}
+ hexagram_36 : pinyin Mingyi wade { Ming I } english {Darkening of the Light }
+ hexagram_37 : pinyin Jiaren wade Chia Jên english { The Family}
+ hexagram_38 : pinyin Kui wade K'uei english {Opposition }
+ hexagram_39 : pinyin Jian wade Chien english {Obstruction}
+ hexagram_40 : pinyin Xie wade Hsieh english {Deliverance}
+ hexagram_41 : pinyin Sun wade Sun english {Decrease }
+ hexagram_42 : pinyin Yi wade I english {Increase }
+ hexagram_43 : pinyin Guai wade Kuai english {Break-through}
+ hexagram_44 : pinyin Gou wade Kou english {Coming to Meet}
+ hexagram_45 : pinyin Cui wade Ts'ui english {Gathering Together }
+ hexagram_46 : pinyin Sheng wade Shêng english {Pushing Upward }
+ hexagram_47 : pinyin Kun wade K'un english {Oppression }
+ hexagram_48 : pinyin Jing wade Ching english {The Well }
+ hexagram_49 : pinyin Ge wade Ko english {Revolution}
+ hexagram_50 : pinyin Ding wade Ting english {The Caldron }
+ hexagram_51 : pinyin Zhen wade Chên english {The Arousing }
+ hexagram_52 : pinyin Gen wade Kên english {Keeping Still }
+ hexagram_53 : pinyin Jian wade Chien english {Development }
+ hexagram_54 : pinyin Guimei wade {Kuei Mei} english {The Marrying Maiden }
+ hexagram_55 : pinyin Feng wade Fêng english {Abundance }
+ hexagram_56 : pinyin Lü wade Lü english {The Wanderer }
+ hexagram_57 : pinyin Xun wade Sun english {The Gentle }
+ hexagram_58 : pinyin Dui wade Tui english {The Joyous }
+ hexagram_59 : pinyin Huan wade Huan english { Dispersion }
+ hexagram_60 : pinyin Jie wade Chieh english {Limitation }
+ hexagram_61 : pinyin Zhongfu wade {Chung Fu} english {InnerTruth }
+ hexagram_62 : pinyin Xiaoguo wade { Hsiao Kuo} english {Preponderance of the Small }
+ hexagram_63 : pinyin Jiji wade { Chi Chi } english {After Completion}
+ hexagram_64 : pinyin Weiji wade { Wei Chi } english {Before Completion }
" }
proc plainsub {text item replacewith} {
set text [string map [list $item $replacewith] $text] }
foreach piece { + : \{ \} } {
set chartbamboo [ plainsub $chartbamboo $piece "*" ]
}
set reading [ list [ split $chartbamboo " " ]]
#end iching data
proc binaryexchange {gualisting} {
# converts gualisting as a list
# to binary & decimal numbers.
global dx dy colors color
global guabinary guadecimal guatransform
set guabinary [ whitelist $gualisting ];
set guabinary [ join [ split $guabinary " "]];
set guabinary [ plainsub $guabinary 6 0 ];
set guabinary [ plainsub $guabinary 7 1 ];
set guabinary [ plainsub $guabinary 8 0 ];
set guabinary [ plainsub $guabinary 9 1 ];
set guabinary [ plainsub $guabinary " " "" ];
return $guabinary;
}
proc second_hexagram_compute {gualisting } {
# subroutine under test
global bookvalue second_hexagram
#set gualisting [ lreverse $gualisting];
set second_hexagram [ list ];
set second_hexagram [ join $gualisting ] ;
set second_hexagram [ plainsub $second_hexagram 6 7 ];
set second_hexagram [ plainsub $second_hexagram 9 6 ];
set guabinary [ binaryexchange $second_hexagram ];
set decimalout [ convertbase2to10 $guabinary ];
set bookgua [ kvsearch $bookvalue $decimalout ];
return $bookgua;
}
proc bonereadxx {coinsread} {
global dx dy colors color gualisting reading
global bookvalue bookvalue2 second_hexagram
set dj 1;
set gualisting [list ];
if { $coinsread == 1 } {
for {set j 0} {$j<6} {incr j $dj} {
set bone1 [lpick {3 3 3 2}]
set bone2 [lpick {3 3 2 2}]
set bone3 [lpick {3 3 2 2}]
set bonereading [expr $bone1 + $bone2 + $bone3 ]
set wow [expr $bone1 + $bone2 + $bone3 ]
lappend gualisting $wow;
}
}
if { $coinsread == 2 } {
for {set j 0} {$j<6} {incr j $dj} {
set bone1 [lpick {3 3 2 2}]
set bone2 [lpick {3 3 2 2}]
set bone3 [lpick {3 3 2 2}]
set bonereading [expr $bone1 + $bone2 + $bone3 ]
set wow [expr $bone1 + $bone2 + $bone3 ]
lappend gualisting $wow;
}
}
#set guabinary [ list 1 0 1 1 1 si tiene problema ]
set gualisting [ lreverse $gualisting];
# reading hexagram lines top down,
# opposed to reverse(down top)
# give different binary values
#
set guabinary [ binaryexchange $gualisting ];
set decimalout [ convertbase2to10 $guabinary ];
set bookgua [ kvsearch $bookvalue2 $decimalout ];
set second_hexa [ second_hexagram_compute $gualisting ];
.wxxccc delete 1.0 end;
set outoutfoulspirit " last bone is $wow .gua listing is $gualisting && binary $guabinary && decimal $decimalout &&Iching_gua_# $bookgua && test 2nd hex. $second_hexagram && 2nd h. test $second_hexa && $second_hexagram
$reading "
.wxxccc insert end $outoutfoulspirit }
proc castfortune {} {
global dx dy colors color gualisting second_hexagram
set colorx black;
for {set i 0; set y 0} {$i<6} {incr i; incr y $dy} {
set colorx brown;
for {set j 0; set x 0} {$j<3} {incr j; incr x $dx} {
set colorx brown;
if { $j == 1} {
if { [lindex $gualisting $i ] == 6} {set colorx white}
if { [lindex $gualisting $i ] == 7} {set colorx brown}
if { [lindex $gualisting $i ] == 8} {set colorx white}
if { [lindex $gualisting $i ] == 9} {set colorx brown}
}
.can create rectangle $x $y [expr {$x+$dx}] [expr {$y+$dy}] \
-fill $colorx
}}
set dx 50
set dy 30
set colorx blue;
for {set i 0; set y 0} {$i<6} {incr i; incr y $dy} {
set colorx blue;
for {set j 0; set x 0} {$j<3} {incr j; incr x $dx} {
set colorx blue;
if { $j == 1} {
if { [lindex $second_hexagram $i ] == 6} {set colorx white}
if { [lindex $second_hexagram $i ] == 7} {set colorx blue}
if { [lindex $second_hexagram $i ] == 8} {set colorx white}
if { [lindex $second_hexagram $i ] == 9} {set colorx blue}
}
.can create rectangle [expr $x + 180] $y [expr {[expr $x +180 ]+$dx}] [expr {$y+$dy}] \
-fill $colorx
}}
}
xskipskipdirectory $env(HOME)
if 0 { iching hexagrams and trigrams }
|1. |Qian |Ch'ien, The Creative|
|2. |Kun |K'un, The Receptive|
|3. |Zhun |Chun, Difficulty at the Beginning|
|4. |Meng |Mêng, Youthful Folly|
|5. |Xu |Hsü, Waiting|
|6. |Song |Sung, Conflict|
|7. |Shi |Shih, The Army|
|8. |Bi |Pi, Holding Together|
|9. |Xiaoxu |Hsiao Ch'u, The Taming Power of the Small|
|10. |Lü |Lü, Treading|
|11. |Tai |T'ai, Peace|
|12. |Pi |P'i, Standstill|
|13. |Tongren |T'ung Jên, Fellowship with Men|
|14. |Dayou |Ta Yu, Possession in Great Measure|
|15. |Qian |Ch'ien, Modesty|
|16. |Yu |Yü, Enthusiasm|
|17. |Sui |Sui, Following|
|18. |Gu |Ku, Work on What Has Been Spoiled|
|19. |Lin |Lin, Approach|
|20. |Guan |Kuan, Contemplation|
|21. |Shike |Shih Ho, Biting Through|
|22. |Bi |Pi, Grace|
|23. |Bo |Po, Splitting Apart|
|24. |Fu |Fu, Return|
|25. |Wuwang |Wu Wang, Innocence|
|26. |Daxu |Ta Ch'u, The Taming Power of the Great|
|27. |Yi |I, The Corners of the Mouth|
|28. |Daguo |Ta Kuo, Preponderance of the Great|
|29. |Kan |K'an, The Abysmal|
|30. |Li |Li, The Clinging|
|31. |Xian |Hsien, Influence|
|32. |Heng |Hêng, Duration|
|33. |Dun |Tun, Retreat|
|34. |Dazhuang |Ta Chuang, The Power of the Great|
|35. |Jin |Chin, Progress|
|36. |Mingyi |Ming I, Darkening of the Light|
|37. |Jiaren |Chia Jên, The Family|
|38. |Kui |K'uei, Opposition|
|39. |Jian |Chien, Obstruction|
|40. |Xie |Hsieh, Deliverance|
|41. |Sun |Sun, Decrease|
|42. |Yi |I, Increase|
|43. |Guai |Kuai, Break-through|
|44. |Gou |Kou, Coming to Meet|
|45. |Cui |Ts'ui, Gathering Together|
|46. |Sheng |Shêng, Pushing Upward|
|47. |Kun |K'un, Oppression|
|48. |Jing |Ching, The Well|
|49. |Ge |Ko, Revolution|
|50. |Ding |Ting, The Caldron|
|51. |Zhen |Chên, The Arousing|
|52. |Gen |Kên, Keeping Still|
|53. |Jian |Chien, Development|
|54. |Guimei |Kuei Mei, The Marrying Maiden|
|55. |Feng |Fêng, Abundance|
|56. |Lü |Lü, The Wanderer|
|57. |Xun |Sun, The Gentle|
|58. |Dui |Tui, The Joyous|
|59. |Huan |Huan, Dispersion|
|60. |Jie |Chieh, Limitation|
|61. |Zhongfu |Chung Fu, Inner Truth|
|62. |Xiaoguo |Hsiao Kuo, Preponderance of the Small|
|63. |Jiji |Chi Chi, After Completion|
|64. |Weiji |Wei Chi, Before Completion||I |Ching |Trigram Name | Translations| | |Pinyin |Wade-Giles | (Wilhelm/Baynes) associations| |1. |Qian |Ch'ien |the creative, heaven, Father,northwest,head,lungs| |2. |Kun |K'un |the receptive,earth,Mother,southwest,abdomen,reproductive_organs| |3. |Zhen |Chên |the arousing, thunder,Eldest_Son,east,throat| |4. |Kan |K'an |the abysmal,water,Middle_Son,north,liver,kidneys,inner_ear| |5. |Gen |Kên |keeping still, mountain,Youngest_Son,northeast,hands,spine,bones| |6. |Xun |Sun |the gentle, wind, Eldest Daughter,southeast,hips,buttocks| |7. |Li |Li |the clinging, flame,Middle_Daughter,south,eyes,heart| |8. |Dui |Tui |the joyous, lake,Youngest_Daughter,west,mouth }|
gold This page is copyrighted under the TCL/TK license terms, this license .
Please place any comments here, Thanks. gold Change:Redundant procedure ? deleted.
LV slightly reformatted code to some level of consistency, added a few braces around expr arguments, and removed a redundant proc definition.
gold12Dec2018. Change 13Mar2007:omitted **(exp) in expr for base2, TCL8.5&>.
CJL thinks that following the guidelines [L2 ] would make this page much more readable, and give browsers a chance to flow the formatting gold12Dec2018. Removed blank lines in code. removed carriage returns in prose. Remark that I use a windows PC and uncertain how page looks on a unix platform.
Please place any comments here with your wiki MONIKER and date, Thanks.gold12Dec2018
gold 9/27/2021. Switched some comment signs ;# to #. This a big file. Check earlier editions, if not compatible. Maybe obvious, but this page was written on Windows10 Tcl ports including ActiveTCL. I assume that the reader can cut and paste on screen, what the reader needs, and tootle on to his own project and own contribution pages to the TCL Wiki.