Error processing request

Parameters

CONTENT_LENGTH0
REQUEST_METHODGET
REQUEST_URI/revision/Chinese+Xiangqi+Chessboard?V=105
QUERY_STRINGV=105
CONTENT_TYPE
DOCUMENT_URI/revision/Chinese+Xiangqi+Chessboard
DOCUMENT_ROOT/var/www/nikit/nikit/nginx/../docroot
SCGI1
SERVER_PROTOCOLHTTP/1.1
HTTPSon
REMOTE_ADDR162.158.78.135
REMOTE_PORT50834
SERVER_PORT4443
SERVER_NAMEwiki.tcl-lang.org
HTTP_HOSTwiki.tcl-lang.org
HTTP_CONNECTIONKeep-Alive
HTTP_ACCEPT_ENCODINGgzip, br
HTTP_X_FORWARDED_FOR44.212.39.149
HTTP_CF_RAY86babaf43f173800-IAD
HTTP_X_FORWARDED_PROTOhttps
HTTP_CF_VISITOR{"scheme":"https"}
HTTP_ACCEPT*/*
HTTP_USER_AGENTclaudebot
HTTP_CF_CONNECTING_IP44.212.39.149
HTTP_CDN_LOOPcloudflare
HTTP_CF_IPCOUNTRYUS

Body


Error

Unknow state transition: LINE -> END

-code

1

-level

0

-errorstack

INNER {returnImm {Unknow state transition: LINE -> END} {}} CALL {my render_wikit {Chinese Xiangqi Chessboard} **Chinese\ Xianqi\ Chessboard**\n\n----\ \ \ \nThis\ page\ is\ under\ development.\ Comments\ are\ welcome,\ but\ please\ load\ any\ comments\ in\ the\ comments\ section\ at\ the\ middle\ of\ the\ page.\ Thanks,\ \[gold\]\n\n----\nHere\ is\ some\ starter\ code\ for\ Chinese\ Xiangqi\ Chessboard.\ There\ are\ several\ avenues\ for\ a\ Xianqi\ chessboard.\ Literature\ search\ showed\ many\ chess\ programs\ relying\ on\ a\ gif\ of\ the\ Chinese\ chessboard.\ Primarily\ looking\ at\ \[RS\]'s\ checkers.tcl\ on\ the\ wiki\ to\ get\ some\ primary\ movable\ pieces\ with\ the\ board.\ \ An\ \ version\ of\ the\ code\ was\ installed\ \ in\ the\ Simple\ Canvas\ Demo\ for\ some\ pictures.\ Also,\ \ TCLpaint\ \ made\ a\ lengthy\ list\ of\ 60\ line\ creations\ in\ TCLpaint,but\ the\ final\ code\ should\ rely\ on\ foreach\ or\ loop\ statements\ for\ compact\ code.\ \n\ \n----\ \nThe\ characters\ are\ generally\ stamped\ red\ and\ blue\ on\ round\ wooden\ pieces,\ which\ might\ be\ unicode\ characters\ in\ chinese.\ Given\ the\ purpose\ to\ display\ an\ Xiangqi\ board,\ a\ wish\ list\ is\ dreamed\ up.\ Probably\ need\ an\ if\ switch\ option\ for\ TCL\ lists\ of\ different\ character\ sets.\ \ Both\ the\ oval\ and\ the\ text\ character\ are\ taqgged\ with\ a\ random\ object\ name\ like\ obj_\$tiilename.\ On\ selection\ of\ a\ chess\ piece,\ the\ code\ finds\ the\ common\ name\ tag\ of\ the\ oval\ and\ text\ piece,\ and\ moves\ both\ at\ the\ same\ time.\ Probably\ should\ add\ a\ color\ outline\ during\ selection\ and\ movement\ with\ the\ mouse.\ Also\ should\ be\ able\ to\ center\ or\ pin\ the\ game\ pieces\ at\ the\ cross\ points.\ Probably\ could\ use\ an\ exit\ button.\n----\nUsing\ the\ Simple\ Canvas\ Demo\ framework,\ the\ code\ has\ installed\ buttons\ for\ switching\ to\ traditional\ Chinese\ pieces,\ Western\ pieces,\ and\ alphabetic\ characters.\ Probably\ the\ buttons\ could\ select\ a\ color\ scheme.\ Xiangqi\ usually\ uses\ a\ gridded\ board.\ Western\ chess\ uses\ brown\ and\ white\ squares.\ Using\ the\ random\ names\ for\ the\ objects\ to\ lock\ ovals\ and\ text\ together.\ This\ works,\ but\ additional\ operations\ on\ the\ gamepieces\ like\ the\ moving\ outline\ are\ gumming\ up.\ Also\ the\ code\ is\ outputing\ the\ mouse\ up\ and\ down\ coordinates\ for\ the\ screen.\n\ \ \ \ \ \n----\nWith\ the\ buttons\ in\ the\ little\ canvas\ demo,\ one\ can\ call\ up\ separate\ routines\ to\ lay\ out\ the\ different\ boards\ and\ install\ the\ various\ options\ of\ chesspieces.\ \ In\ a\ teamwork\ situation,\ programming\ teams\ could\ divide\ up\ the\ several\ tasks\ with\ the\ framework.\ In\ many\ cases,\ it\ is\ advantageous\ to\ have\ or\ write\ little\ demo\ programs\ for\ the\ separate\ subroutines.\ Some\ of\ the\ demo\ code\ decks\ are\ included\ below.\ In\ the\ button\ call\ up\ of\ the\ canvas\ demo,\ separate\ tasks\ can\ laid\ in\ successive\ statements\ to\ clear\ board,\ set\ states,\ layout\ the\ board,\ and\ populate\ the\ chesspieces.\ Loading\ four\ statements\ in\ the\ button\ \ might\ be\ ClrCanvas\ .cv\;\ set\ state3\ 3\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 3\;\ This\ gets\ a\ little\ lengthy\ for\ a\ button\ line,\ so\ these\ statements\ could\ be\ stacked\ in\ a\ separate\ subroutine.\ With\ some\ global\ statements\ for\ any\ constants\ and\ passing\ the\ canvas\ name\ as\ \$w,\ the\ \ subroutine\ could\ be\ written\ like\ \n======\n\ \ proc\ stackedlist\ \{w\}\ \{\n\ \ \ \ global\ state3\n\ \ \ \ ClrCanvas\ \$w\n\ \ \ \ set\ state3\ 3\n\ \ \ \ board\ \$w\n\ \ \ \ populateCanvas\ \$w\ 6\ 6\ 3\n\ \ \}\n======\n\n----\n**Screenshots\ Section**\n\n\[http://farm5.static.flickr.com/4136/4743183050_a37afc987d.jpg\]\n\[http://farm5.static.flickr.com/4096/4743212494_7b08112447.jpg\]\n\[http://farm5.static.flickr.com/4101/4746939385_e67ce71783.jpg\]\n\[http://farm5.static.flickr.com/4076/4747597490_52d5db2c15.jpg\]\n\n----\n**Comments\ Section**\nPlease\ place\ any\ comments\ here,\ Thanks.\n\n\[gold\]\ Changes.\n\n\[AMG\]:\ I\ suggest\ using\ a\ \[for\]\ loop\ to\ make\ \[\[chessboard\]\]\ more\ concise.\n\n\[gold\]\ Is\ there\ some\ way\ to\ multiply\ all\ numbers\ in\ a\ create\ statement,\ leaving\ the\nalpha\ characters\ unchanged?\ Perl\ can\ do\ this.\nI\ tried\ but\ kept\ bombing,\ and\ wound\ up\ with\ this\ code.\n\n======\n\ set\ bee1\ \[\ list\ .c\ create\ poly\ \ -8\ 10\ \ -8\ 7\ \ -5\ 7\ \ -2\ -1\ \ -4\ -5\ \ -2\ -10\ \ 2\ -10\ \ 4\ -5\ \ 2\ -1\ \ 5\ 7\ \ 8\ 7\ \ 8\ 10\ \]\n\ \ \ \ \ \ set\ bee2\ \[\ list\ \ \ \ -8\ 10\ \ -8\ 7\ \ -5\ 7\ \ -2\ -1\ \ -4\ -5\ \ -2\ -10\ \ 2\ -10\ \ 4\ -5\ \ 2\ -1\ \ 5\ 7\ \ 8\ 7\ \ 8\ 10\ \]\n\ \ \ \ set\ check\ \"1\"\n\ \ \ \ \ foreach\ factor\ \[list\ \ 10\ 12\ 14\ 16\ 18\ 20\]\ \{\n\ \ \ \ \ set\ cat\ \[list\ \ \]\n\ \ \ \ \ foreach\ item\ \$bee1\ \{\n\ \ \ \ \ \ if\ \{\ \[catch\ \{expr\ \{1\ *\ \$item\}\}\]\ >>\ 0\}\ \{lappend\ cat\ \ \$item\ \}\n\n\ \ \ \ \ \ if\ \{\ \[catch\ \{expr\ \{1\ *\ \$item\}\}\]\ ==\ 0\ \}\ \{lappend\ cat\ \[\ expr\ 200*\$factor*.1\ +\ \$item\ *\ log(\$factor)\ \ \]\}\n\ \ \ \ \ \ \ \}\n\ \ \ \ \ \n\ \ \ \ \ \ eval\ \$cat\ -outline\ gray\ \ -fill\ \[lpick\ \$randomcolor\ \]\ \n\ \ \ \ \ \ \ \}\n======\n\n\[AMG\]:\ Yes,\ but\ it's\ very\ complex.\ \ You'd\ have\ to\ use\ \[\[\[regexp\]\ -indices\ -all\ \{\\d+\}\ \$string\]\]\ to\ find\ the\ start\ and\ end\ indices\ corresponding\ to\ the\ numbers,\ then\ you'd\ extract\ each\ number,\ multiply\ it,\ and\ replace\ it\ back\ into\ the\ string\ using\ \[\[\[string\ replace\]\]\].\ \ I\ don't\ recommend\ this\ approach,\ especially\ since\ it's\ liable\ to\ modify\ numbers\ you\ didn't\ intend\ to\ modify.\ \ Also,\ that\ regular\ expression\ I\ gave\ only\ works\ for\ integers\;\ detecting\ floating\ point\ numbers\ is\ even\ harder.\n\nWhat\ you\ need\ to\ do\ is\ have\ each\ creation\ parameter\ be\ a\ function\ of\ your\ \[for\]\ loop\ iterators.\ \ You\ say\ you\ have\ a\ \[Fortran\]\ background\;\ this\ concept\ should\ be\ familiar\ to\ you,\ except\ that\ Fortran\ says\ \"DO\"\ instead\ of\ \"for\".\ :^)\ \ More\ seriously,\ Tcl\ for\ loops\ are\ weird\ (in\ the\ same\ way\ that\ \[C\]\ for\ loops\ are\ weird).\ \ They\ take\ four\ arguments:\n\n\ \ \ 1.\ Initialization\ script.\ \ This\ is\ executed\ before\ the\ loop\ begins.\ \ It's\ normally\ used\ to\ create\ the\ iteration\ variable.\n\ \ \ 1.\ Termination\ test.\ \ This\ expression\ is\ tested\ before\ each\ iteration,\ and\ if\ it's\ false,\ the\ loop\ stops.\n\ \ \ 1.\ Advancement\ script.\ \ This\ is\ executed\ after\ each\ iteration\ of\ the\ loop.\ \ It's\ normally\ used\ to\ increment\ the\ iteration\ variable.\n\ \ \ 1.\ Iteration\ body\ script.\ \ This\ is\ executed\ each\ time\ the\ loop\ iterates,\ just\ before\ the\ advancement\ script.\ \ Your\ main\ code\ goes\ here.\n\nHere's\ code\ to\ make\ a\ grid\ similar\ to\ the\ one\ your\ program\ creates.\ \ It\ shows\ both\ for\ and\ \[foreach\].\ \ To\ be\ honest,\ foreach\ is\ simpler\ than\ for\ when\ there\ are\ a\ very\ small\ number\ of\ iterations.\ \ Here,\ replace\ the\ first\ for\ with\ \"`foreach\ i\ \{1\ 2\ 3\ 4\ 5\ 6\ 7\}\ \{...\}`\"\ and\ the\ second\ for\ with\ \"`foreach\ i\ \{0\ 1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 9\}\ \{...\}`\".\n\n======\nset\ dx\ 20\ \ \ \ \;#\ pixels\ between\ adjacent\ vertical\ grid\ lines\nset\ dy\ 20\ \ \ \ \;#\ pixels\ between\ adjacent\ horizontal\ grid\ lines\nset\ x0\ 30\ \ \ \ \;#\ pixels\ between\ left\ of\ canvas\ and\ left\ of\ grid\nset\ y0\ 30\ \ \ \ \;#\ pixels\ between\ top\ of\ canvas\ and\ top\ of\ grid\nset\ win\ .c\ \ \ \;#\ name\ of\ canvas\ widget\nforeach\ i\ \{0\ 8\}\ \{\n\ \ \ \ \$win\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \$y0\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{9\ *\ \$dy\ +\ \$y0\}\]\n\}\nfor\ \{set\ i\ 1\}\ \{\$i\ <\ 8\}\ \{incr\ i\}\ \{\n\ \ \ \ \$win\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \$y0\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{4\ *\ \$dy\ +\ \$y0\}\]\n\ \ \ \ \$win\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{5\ *\ \$dy\ +\ \$y0\}\]\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{9\ *\ \$dy\ +\ \$y0\}\]\n\}\nfor\ \{set\ i\ 0\}\ \{\$i\ <\ 10\}\ \{incr\ i\}\ \{\n\ \ \ \ \$win\ create\ line\ \$x0\ \[expr\ \{\$i\ *\ \$dy\ +\ \$y0\}\]\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[expr\ \{8\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{\$i\ *\ \$dy\ +\ \$y0\}\]\n\}\n======\n\nThere's\ more\ work\ to\ be\ done,\ though.\ \ Hopefully\ this\ will\ get\ you\ started.\n\n----\n**References***\n\n\ \ \ *\ \[Simple\ Canvas\ Demo\]\n\ \ \ *\ http://www.goddesschess.com/chessays/gaddbabylon.html\n\ \ \ *\ http://skookumpete.com/chess_intro.htm\n\ \ \ *\ http://rishida.net/tools/conversion/,\ outstanding\ unicode\ conversion\ online!!!\n\ \ \ *\ http://mayoneez.1g.fi/hiddenlynx/index.html\n\ \ \ *\ http://www.chessvariants.org/graphics.dir/big5/index.html\n\ \ \ *\ http://geert.vanderkelen.org/2009/12/chessboard-in-mysql.html\n\ \ \ *\ http://pinyin.info/tools/converter/chars2uninumbers.html\n\ \ \ *\ http://en.wikipedia.org/wiki/Miscellaneous_Symbols_Unicode_block\n\ \ \ *\ \[A\ little\ checker\ game\]\n\ \ \ *\ \[Simple\ Canvas\ Demo\]\n\ \ \ *\ \[Things\ Chinese\]\n\ \ \ *\ \[Pinyin,\ ASCII\ to\ Unicode\ Converter\]\n\ \ \ *\ http://99.237.250.152/xq/book/xiangqi_printset.pdfunicode\n\ \ \ *\ http://www.yutopian.com/chinesechess/chrules.pdf\n\n**appendix\ TCL\ programs**\n***FIRST\ DEMO***\ \n\n======\ \n\ \ \ \ \ \ \ \ #\ first\ demo\ code\ from\ \[AMG\]\n\ \ \ \ \ \ \ \ #\ pretty\ print\ version\ from\ autoindent\ and\ ased\n\ \ \ \ \ \ \ \ #\ Xiangqi\ chessboard\ with\ little\ frills.\n\ \ \ \ \ \ \ \ #\ Crosspatch\ program,\ dated\ 3JUL2010.\n\ \ \ \ \ \ \ \ #TCL\ WIKI\ contribution\n\ \ \ \ \ \ \ \ package\ require\ Tk\n\ \ \ \ \ \ \ \ proc\ crosspatch\ \{w\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ set\ dx\ 20\ \ \ \ \;#\ pixels\ between\ adjacent\ vertical\ grid\ lines\n\ \ \ \ \ \ \ \ \ \ \ \ set\ dy\ 20\ \ \ \ \;#\ pixels\ between\ adjacent\ horizontal\ grid\ lines\n\ \ \ \ \ \ \ \ \ \ \ \ set\ x0\ 30\ \ \ \ \;#\ pixels\ between\ left\ of\ canvas\ and\ left\ of\ grid\n\ \ \ \ \ \ \ \ \ \ \ \ set\ y0\ 30\ \ \ \ \;#\ pixels\ between\ top\ of\ canvas\ and\ top\ of\ grid\n\ \ \ \ \ \ \ \ \ \ \ \ set\ win\ \$w\ \ \ \;#\ name\ of\ canvas\ widget\n\ \ \ \ \ \ \ \ \ \ \ \ foreach\ i\ \{0\ 8\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \$y0\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{9\ *\ \$dy\ +\ \$y0\}\]\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ for\ \{set\ i\ 1\}\ \{\$i\ <\ 8\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \$y0\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{4\ *\ \$dy\ +\ \$y0\}\]\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{5\ *\ \$dy\ +\ \$y0\}\]\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{9\ *\ \$dy\ +\ \$y0\}\]\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ 10\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ create\ line\ \$x0\ \[expr\ \{\$i\ *\ \$dy\ +\ \$y0\}\]\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[expr\ \{8\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{\$i\ *\ \$dy\ +\ \$y0\}\]\n\ \ \ \ \ \ \ \ \ \ \ \ \}\}\n\ \ \ \ \ \ \ \ pack\ \[\ canvas\ .cx\ -width\ 400\ -height\ 400\ \]\n\ \ \ \ \ \ \ \ crosspatch\ .cx\n======\ \n\n\n***SECOND\ DEMO***\ \n***minimal\ example\ of\ linked\ movement\ on\ canvas***\n\n======\ \n\ \ \ \ \ \ \ \ #\ second\ demo\ code\n\ \ \ \ \ \ \ \ #\ pretty\ print\ from\ autoindent\ and\ ased\ editor\n\ \ \ \ \ \ \ \ #\ Xiangqi\ chessboard\ with\ little\ frills.\n\ \ \ \ \ \ \ \ #\ Linked\ oval\ and\ text\ movement\ on\ TCL\ canvas\ program,\ dated\ 3JUL210.\n\ \ \ \ \ \ \ \ #TCL\ WIKI\ contribution\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ #***minimal\ example\ of\ linked\ movement\ on\ canvas***\n\ \ \ package\ require\ Tk\n\ \ \ \ \ \ \ proc\ grab\ \{\ xx\ yy\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ global\ currentx\ currenty\n\ \ \ \ \ \ \ \ \ \ \ \ set\ currentx\ \$xx\n\ \ \ \ \ \ \ \ \ \ \ \ set\ currenty\ \$yy\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ proc\ move\ \{w\ xx\ yy\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ global\ currentx\ currenty\n\ \ \ \ \ \ \ \ \ \ \ \ set\ dx\ \[expr\ \{\$xx\ -\ \$currentx\}\]\n\ \ \ \ \ \ \ \ \ \ \ \ set\ dy\ \[expr\ \{\$yy\ -\ \$currenty\}\]\n\ \ \ \ \ \ \ \ \ \ \ \ \$w\ move\ movable\ \$dx\ \$dy\n\ \ \ \ \ \ \ \ \ \ \ \ \$w\ raise\ movable\n\ \ \ \ \ \ \ \ \ \ \ \ set\ currentx\ \$xx\n\ \ \ \ \ \ \ \ \ \ \ \ set\ currenty\ \$yy\n\ \ \ \ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ canvas\ .cv\ -width\ 200\ -height\ 200\n\ \ \ \ \ \ \ \ pack\ .cv\n\ \ \ \ \ \ \ \ .cv\ create\ oval\ 10\ 10\ 30\ 30\ -fill\ red\ -tag\ movable\n\ \ \ \ \ \ \ \ .cv\ create\ text\ 20\ 20\ \ \ -text\ @\ -fill\ blue\ -tag\ movable\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ .cv\ create\ rect\ 110\ 10\ 130\ 50\ -fill\ green\ -tag\ stationary\n\ \ \ \ \ \ \ \ .cv\ create\ rect\ 10\ 110\ 50\ 90\ -fill\ yellow\ -tag\ stationary\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ .cv\ bind\ movable\ <Button-1>\ \{grab\ %x\ %y\ \}\n\ \ \ \ \ \ \ \ .cv\ bind\ movable\ <B1-Motion>\ \{move\ .cv\ %x\ %y\ \}\n======\n\n***THIRD\ DEMO***\ \n***pegboard\ DEMO\ with\ little\ frills\ ***\n\n======\ \n\ \ \ \ #\ pretty\ print\ from\ autoindent\ and\ ased\ editor\n\ \ \ \ #\ pegboard\ DEMO\ with\ little\ frills.\n\ \ \ \ #\ PEGBOARD\ program,\ dated\ 3JUL210.\n\ \ \ \ #TCL\ WIKI\ contribution\n\ \ \ \ package\ require\ Tk\ \ \ \ \n\ \ \ \ proc\ pegboard\ \{w\}\ \{\n\ \ \ \ \ \ \ \ console\ show\n\ \ \ \ \ \ \ \ set\ \ max\ 400\n\ \ \ \ \ \ \ \ set\ \ may\ 400\n\ \ \ \ \ \ \ \ for\ \{set\ r\ 50\}\ \{\$r\ <\ \$max\}\ \{incr\ r\ 45\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ for\ \{set\ c\ 50\}\ \{\$c\ <\ \$max\}\ \{incr\ c\ 45\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ tilename\ \ \[expr\ \{int(rand()*1000000000.)\}\]\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ create\ oval\ \$r\ \$c\ \[expr\ \$r+5\]\ \[expr\ \$c+5\]\ -outline\ gray\ -fill\ green\ -width\ 1\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ -tags\ \[concat\ mv\ xdat_\[expr\ \$r+5\]\ \ ydat_\[expr\ \$c+5\]\ obj_\$tilename\]\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ puts\ \"\ xdat_\[expr\ \$r+5\]\ \ ydat_\[expr\ \$c+5\]\ obj_\$tilename\"\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ texter\ \ \"\ \ \[expr\ \$r+5\]\ \[expr\ \$c+5\]\ \ \"\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ create\ text\ \[expr\ \$r+5\]\ \[expr\ \$c+20\]\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ -text\ \$texter\ -fill\ green\ -tags\ \"\ \ \[expr\ \$r+5\]\ \[expr\ \$c+20\]\"\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ \ \ \ \ \}\}\}\n\ \ \ \ pack\ \[\ canvas\ .cx\ -width\ 400\ -height\ 400\ \]\n\ \ \ \ pegboard\ .cx\n\ ======\n\n***FIRST\ VERSION***\ \n\n======\n\ #start\ of\ deck#start\ of\ deck\n\ \ \ \ \ \ \ \ #start\ of\ deck\n\ \ \ \ \ \ \ \ #start\ of\ deck\n\n\ #\ written\ on\ Windowws\ XP\ on\ eTCL\ \n\ \ \ \ \ #\ working\ under\ TCL\ version\ 8.5.6\ and\ eTCL\ 1.0.1\ \n\ \ \ \ \ #\ gold\ on\ TCL\ WIKI\ ,\ 17Jul2010\n\n\ set\ oscwidth\ 1000\ \n\ set\ oschorizontal\ 500\ \n\ proc\ loop\ \{from\ to\ body\}\ \{\n\ \ \ \ upvar\ 1\ i\ i\ \;#\ make\ index\ visible\ in\ body\n\ \ \ \ for\ \{set\ i\ \$from\}\ \{\$i<\$to\}\ \{incr\ i\}\ \{uplevel\ 1\ \$body\}\n\ \}\n\ #--\ And\ likewise,\ a\ shortcut\ for\ addition:\n\ proc\ +\ \{a\ b\}\ \{expr\ \{\$a+\$b\}\}\n\ \n\ pack\ \[canvas\ .cv\ -width\ 400\ -height\ 500\ \]\n\n\ focus\ .cv\ \n\ set\ state2\ 1\n\ proc\ refreshgrid\ \{\ .cv\ state2\}\ \{\n\ global\ oscwidth\ oschorizontal\ colorite\n\ global\ grid\n\ set\ colorite\ blue\ \n\ for\ \{set\ x\ 10\}\ \{\$x<\$oscwidth\}\ \{incr\ x\ 50\}\ \{.cv\ create\ line\ \$x\ 0\ \$x\ \$oschorizontal\ \ -fill\ blue\ -tag\ grid\ -\n\nwidth\ 4\}\n\ for\ \{set\ y\ 20\}\ \{\$y<\$oschorizontal\}\ \{incr\ y\ 50\}\ \{.cv\ create\ line\ 0\ \$y\ \$oschorizontal\ \$y\ -fill\ blue\ \ -tag\ grid\ \n\n-width\ 4\}\ \n\ .cv\ itemconfigure\ grid\ -fill\ blue\ \n\n\ if\ \{\ \$state2\ ==\ 1\ \}\ \{\ .cv\ raise\ grid\ \;\}\ \n\ if\ \{\ \$state2\ ==\ 2\ \}\ \{\ .cv\ lower\ grid\ \;\}\ \n\ \}\n\n\ \ refreshgrid\ \ .cv\ \$state2\ \n\ #\ next\ lines\ start\ withn\ periods,\ but\ hard\ to\ see\n\ .\ configure\ -borderwidth\ 0\ -highlightthickness\ 0\ -takefocus\ 0\ -background\ aquamarine4\n\ .\ configure\ -background\ palegreen\ -highlightcolor\ DarkOliveGreen\ -relief\ raised\ -border\ 30\n\n\ .\ configure\ -width\ 1000\ -height\ 2000\n\n\ .cv\ bind\ all\ <1>\ \{set\ p(X)\ \[.cv\ canvasx\ %x\]\;\ set\ p(Y)\ \[.cv\ canvasy\ %y\]\}\n\ .cv\ bind\ mv\ <B1-Motion>\ \{mv\ .cv\ %x\ %y\}\n\n\ \ proc\ mv\ \{w\ x\ y\}\ \{\n\ \ \ \ global\ p\n\ \ \ \ set\ x\ \ \[\$w\ canvasx\ \$x\]\n\ \ \ \ set\ y\ \ \[\$w\ canvasy\ \$y\]\n\ \ \ \ set\ id\ \[\$w\ find\ withtag\ current\]\n\ \ \ \ set\ numberx\ \[\$w\ \ gettags\ current\]\n\ \ \ \ regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ \n\ \ \ \ puts\ \"1\"\n\ \ \ \ puts\ \$numberx\n\ \ \ \ puts\ \$tilex\n\ \ \ \ puts\ \"\ with\ tag\ \[\$w\ find\ withtag\ obj_\$tilex\ \]\"\n\ \ \ \ foreach\ item\ \[\$w\ find\ withtag\ obj_\$tilex\ \]\ \{\n\ \ \ \ \$w\ move\ \$item\ \[expr\ \{\$x-\$p(X)\}\]\ \[expr\ \{\$y-\$p(Y)\}\]\n\ \ \ \ #\$w\ raise\ \$id\n\ \ \ \ \}\n\ \ \ \ puts\ \"\ x\ y\ \$x\ \$y\"\n\ \ \ \ #\$w\ raise\ \$id\n\ \ \ \ #\ \$w\ move\ \[\$w\ find\ withtag\ \"\$tilex\"\]\ \[expr\ \{\$x-\$p(X)\}\]\ \[expr\ \{\$y-\$p(Y)\}\]\n\ \ \ \ #set\ numberx\ \[\$w\ \ gettags\ current\]\n\ \ \ \ #regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ set\ p(X)\ \$x\;\ set\ p(Y)\ \$y\n\ \}\n\n\ \ \ \ \ set\ bluepieces\ \[list\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]\n\ \ \ \ \ set\ redpieces\ \ \[list\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]\n\ \ \ \ \ #black\ western\n\ \ \ \ \ set\ bluepieces\ \{\ \ \\u265A\ \\u265B\ \\u265C\ \\u265C\ \\u265D\ \\u265D\ \\u265E\ \\u265E\ \\u265F\ \\u265F\ \\u265F\ \\u265F\ \n\n\\u265F\ \\u265F\ \\u265F\ \\u265F\}\ \ \n\ \ \ \ \ #white\ western\n\ \ \ \ \ set\ redpieces\ \{\ \ \\u2654\ \\u2655\ \\u2655\ \\u2656\ \ \\u2656\ \\u2657\ \\u2657\ \ \\u2658\ \\u2658\ \\u2659\ \\u2659\ \\u2659\ \ \n\n\\u2659\ \\u2659\ \\u2659\ \\u2659\ \\u2659\}\ \ \n\ \ \ \ \ \ \ set\ bluepieces\ \{\\u5C07\ \\u58EB\ \ \\u58EB\ \ \\u8C61\ \\u8C61\ \\u99AC\ \\u99AC\ \\u8ECA\ \\u8ECA\ \ \ \\u7832\ \ \ \\u7832\ \ \ \ \n\n\\u5352\ \\u5352\ \\u5352\ \ \ \\u5352\ \\u5352\}\n\ set\ redpieces\ \ \{\ \ 0\ \\u5E25\ \ \ \\u4ED5\ \\u4ED5\ \ \ \\u76F8\ \ \ \\u76F8\ \\u99AC\ \\u99AC\ \\u8ECA\ \\u8ECA\ \ \ \ \ \ \\u70AE\ \ \\u70AE\ \n\n\ \\u5175\ \ \\u5175\ \ \ \ \\u5175\ \ \ \ \ \\u5175\ \ \ \\u5175\ \ \}\ \ \n\ \ \ \ \ \n\ \ \ \ \ set\ ind\ 0\n\ \ \ \ \ set\ indx\ 0\n\ \ \ \ \ set\ baseline\ \{list\ 1\}\n\ \ \ \ \ \ proc\ K\ \{\ x\ y\ \}\ \{\ set\ x\ \}\n\n\ \ \ \ \ proc\ xpop\ \{\ topper\ \}\ \{\n\ \ \ \ \ global\ liner\n\ \ \ \ \ global\ ind\ indx\n\ \ \ \ \ global\ bluepieces\ redpieces\n\ \ \ \ \ global\ baseline\n\ \ \ \ \ set\ topper\ \[\ lindex\ \$bluepieces\ \$ind\ \]\;\n\ \ \ \ \ if\ \{\ \$topper\ ==\ \"\"\ \}\ \{\ \n\ \ \ \ \ set\ topper\ \[\ lindex\ \$redpieces\ \$indx\ \]\n\ \ \ \ \ set\ indx\ \[\ expr\ \{\ \$indx\ +\ 1\}\]\n\ \ \ \ \ \ \ \}\ \n\ \ \ \ \ set\ ind\ \[\ expr\ \{\ \$ind\ +\ 1\}\]\n\ \ \ \ \ lappend\ \$baseline\ \$topper\;\n\ \ \ \ \ return\ \$topper\;\n\ \ \ \ \ \}\n\ \ proc\ populateCanvas\ \{w\ cols\ rows\ args\}\ \{\n\ \ \ \ global\ ind\ indx\n\ \ \ \ variable\ ids\ \;#\ links\ text\ ids\ with\ respective\ rect\ ids\n\ \ \ \ variable\ boxes\ \;#\ lists\ text\ id\ and\ text\ associated\ with\ each\ rect\ id\n\ \ \ \ catch\ \{unset\ ids\ boxes\}\n\ \ \ \ set\ canvas\ \$w\n\ \ \ \ #\ parameters\ for\ drawing\ boxes\n\ \ \ \ set\ boxwidth\ 50\n\ \ \ \ set\ boxheight\ 50\n\ \ \ \ set\ padx\ 3\n\ \ \ \ set\ pady\ 3\n\ \ \ \ set\ colors\ \{\ orange\ yellow\ green\ \ gray\}\n\ \ \ \ set\ labels\ \{one\ two\ three\ four\}\n\n\ \ \ \ #\ draw\ the\ boxes\n\ \ \ \ for\ \{set\ row\ 0\}\ \{\$row\ <\ \$rows\}\ \{incr\ row\}\ \{\n\ \ \ \ \ \ for\ \{set\ col\ 0\}\ \{\$col\ <\ \$cols\}\ \{incr\ col\}\ \{\n\n\ \ \ \ \ \ \ \ #\ calculate\ coordinates\n\ \ \ \ \ \ \ \ set\ x1\ \[expr\ \{\$col\ *\ (\$boxwidth\ +\ \$padx)\ +\ \$padx\}\]\n\ \ \ \ \ \ \ \ set\ x2\ \[expr\ \{\$x1\ +\ \$boxwidth\}\]\n\ \ \ \ \ \ \ \ set\ x3\ \[expr\ \{\$x1\ +\ (\$boxwidth\ /\ 2)\}\]\n\ \ \ \ \ \ \ \ set\ y1\ \[expr\ \{\$row\ *\ (\$boxheight\ +\ \$pady)\ +\ \$pady\}\]\n\ \ \ \ \ \ \ \ set\ y2\ \[expr\ \{\$y1\ +\ \$boxheight\}\]\n\ \ \ \ \ \ \ \ set\ y3\ \[expr\ \{\$y1\ +\ (\$boxheight\ /\ 2)\}\]\n\n\ \ \ \ \ \ \ \ #\ choose\ color\ and\ text\n\ \ \ \ \ \ \ \ set\ color\ \[lindex\ \$colors\ \[expr\ \{int(rand()\ *\ \[llength\ \$colors\])\}\]\]\n\ \ \ \ \ \ \ \ #set\ text\ \[lindex\ \$labels\ \[expr\ \{int(rand()\ *\ \[llength\ \$labels\])\}\]\]\n\ \ \ \ \ \ \ \ #\ set\ text\ \[xpop\ topper\]\n\ \ \ \ \ \ \ \ \ set\ font2\ \[list\ Helvetica\ \[expr\ \$boxwidth/2\]\]\n\n\ \ \ \ \ \ \ \ \ #set\ text\ \"0\"\n\ \ \ \ \ \ \ \ \ #set\ text\ \"K\"\n\ \ \ \ \ \ \ \ \ set\ text\ \[xpop\ 1\ \]\n\ \ \ \ \ \ \ \ \ set\ tilename\ \ \[expr\ \{int(rand()*1000000000.)\}\]\n\ \ \ \ \ \ \ \ #\ create\ the\ boxes\n\ \ \ \ \ \ \ \ set\ boxid\ \[\$canvas\ create\ oval\ \$x1\ \$y1\ \$x2\ \$y2\ \\\n\ \ \ \ \ \ \ \ \ \ -fill\ \$color\ -tags\ \[concat\ mv\ rect\ \$args\ \ obj_\$tilename\]\\\n\ \ \ \ \ \ \ \ \ \ -outline\ black\]\n\ \ \ \ \ \ \ \ set\ colorfo\ blue\n\ \ \ \ \ \ \ \ if\ \{\ \$indx\ >\ 1\ \}\ \{set\ colorfo\ red\}\n\ \ \ \ \ \ \ \ set\ textid\ \[\$canvas\ create\ text\ \$x3\ \$y3\ -font\ \$font2\ -fill\ \$colorfo\ \\\n\ \ \ \ \ \ \ \ \ \ -text\ \$text\ -tags\ \[concat\ mv\ \ \$args\ \ obj_\$tilename\]\ \ \]\n\n\ \ \ \ \ \ \ \ #\ remember\ which\ text\ item\ goes\ with\ which\ box\ and\ what\ the\ text\ says\n\ \ \ \ \ \ \ \ set\ boxes(\$boxid)\ \[list\ \$textid\ \$text\]\n\ \ \ \ \ \ \ \ set\ ids(\$textid)\ \$boxid\n\ \ \ \ \ \ \ \ set\ ids(\$boxid)\ \$boxid\n\ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \}\ \ \n\ \ \ \ \ populateCanvas\ .cv\ 6\ 7\ \ \n\ \ console\ show\ \n\ #end\ of\ deck\n\ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\ \ \ \ \ \ \n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #statements\ for\ random\ names\ of\ objects\n\ \ \ \ \ \ \ \ #set\ numberx\ \[.c\ \ gettags\ current\]\;\n\ \ \ \ \ \ \ \ #\ regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ \ \ \ #.c\ delete\ \"obj_\$tilex+1\"\ \;\n\ \ \ \ \ \ #set\ tilename\ \ \[expr\ \{int(rand()*1000000000.)\}\]\n\ \ \ \ \ #.c\ delete\ obj_\$tilex\ \;\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\ \ \ \ \ \ \n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\ \ \ \ \ \ \n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ #end\ of\ deck\n======\n\n****SECOND\ VERSION\ WITH\ ADDED\ HACKS\ ***\ \n\n======\ \n\n\ \ \ \ \ #start\ of\ deck\n\ \ \ \ \ \ \ \ #start\ of\ deck\n\ \ \ \ \ \ \ \ #start\ of\ deck\ #!/bin/sh\n\ #\ Restart\ with\ tcl:\ -*-\ mode:\ tcl\;\ tab-width:\ 4\;\ -*-\ \\\n\ exec\ wish\ \$0\ \$\{1+\"\$@\"\}\n\n\ #\ demo2-canvas.tcl\ -\ HaJo\ Gurt\ -\ 2005-12-13\ -\ http://wiki.tcl.tk/15073\n\ #:\ CanvasDemo:\ On\ button-click,\ draw\ something\ on\ the\ canvas\n\ #\ gold\ used\ canvas\ demo\ as\ base\ for\ TCL\ \ chess\ display\ board.\n\ \n\ \ package\ require\ Tk\n\n\ \ proc\ ClrCanvas\ \{w\}\ \{\n\ \ \ \ \$w\ delete\ \"all\"\n\ \ \ \ \$w\ configure\ \ -bg\ white\n\ \ \}\n\n\ \ proc\ DrawAxis\ \{w\}\ \{\n\ \ \ \ set\ midX\ \[expr\ \{\ \$::maxX\ /\ 2\ \}\]\n\ \ \ \ set\ midY\ \[expr\ \{\ \$::maxY\ /\ 2\ \}\]\n\ \ \ \ \$w\ create\ line\ 0\ \ \ \ \ \$midY\ \ \$::maxX\ \ \ \$midY\ \ -tags\ \"axis\"\n\ \ \ \ \$w\ create\ line\ \$midX\ 0\ \ \ \ \ \ \ \ \$midX\ \$::maxY\ \ -tags\ \"axis\"\n\ \ \}\n\n\ \ proc\ PaintText\ \{w\ Txt\}\ \{\n\ \ \ \ global\ y\n\ \ \ \ incr\ y\ 10\n\ \ \ \ \$w\ create\ text\ 100\ \$y\ -text\ \$Txt\ -tags\ \"text\"\n\ \ \}\n\n\ \ proc\ DrawBox\ \{w\}\ \{\n\ \ \ \ global\ x1\ y1\ x2\ y2\n\ \ \ \ \$w\ create\ rect\ \ 50\ \ 50\ \ 100\ \ 90\ \ -tags\ \"box\"\n\ \ \ \ \$w\ create\ rect\ \$x1\ \$y1\ \ \$x2\ \$y2\ \ -tags\ \"box\"\n\ \ \ \ incr\ x1\ 15\n\ \ \ \ incr\ x2\ 15\n\ \ \ \ incr\ y1\ 10\n\ \ \ \ incr\ y2\ 10\n\ \ \}\n\n\ \ proc\ DrawFn1\ \{w\}\ \{\n\ \ \ \ \$w\ create\ line\ 0\ 100\ \ 50\ 200\ \ 100\ 50\ \ 150\ 70\ \ 200\ 155\ \ 250\ 50\ \ 300\ 111\ \ 350\ 222\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ -tags\ \"Fn1\"\ \ -smooth\ bezier\n\ \ \}\n\n\ \ proc\ DrawFn2\ \{w\}\ \{\n\ \ \ \ set\ offY\ 0\ \ \ \ \;#\ \[expr\ \{\ \$::maxY\ /\ 2\ \}\]\n\n\ \ \ \ for\ \{\ set\ x\ 0\ \}\ \{\ \$x\ <=\ \$::maxX\ \}\ \{\ incr\ x\ 5\ \}\ \{\n\ \ \ \ \ \ set\ y\ \[expr\ \{\ rand()\ *\ \$::maxY\ +\ \$offY\ \}\]\n\n\ \ \ \ \ #puts\ \"\$x\ \$y\"\n\ \ \ \ \ \ if\ \{\$x>0\}\ \{\ \$w\ create\ line\ \$x0\ \$y0\ \$x\ \$y\ -tags\ \"Fn2\"\ \}\n\ \ \ \ \ \ set\ x0\ \$x\n\ \ \ \ \ \ set\ y0\ \$y\n\ \ \ \ \}\n\ \ \}\n\n\ \ #:\ Main\ :\n\ \ frame\ .f1\n\ \ frame\ .f2\n\ \ pack\ \ .f1\ .f2\n\n\ \ set\ maxX\ 400\n\ \ set\ maxY\ 400\n\ \ set\ y\ \ \ \ \ \ 0\n\n\ \ set\ x1\ 120\n\ \ set\ x2\ 150\n\ \ set\ y1\ \ 50\n\ \ set\ y2\ \ 80\n\n\ \ canvas\ \ .cv\ -width\ \$maxX\ -height\ \$maxY\ \ -bg\ tan\n\ \ pack\ \ \ \ .cv\ -in\ .f1\n\ \ button\ \ .a0\ -text\ \"xiangqi\"\ -command\ \{set\ state2\ 1\;set\ state3\ 1\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 1\ \ \ \}\n\ \ button\ \ .a1\ -text\ \"west*\"\ -command\ \{unset\ state3\;set\ state3\ 3\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 3\ \ \ \}\n\ \ button\ \ .a2\ -text\ \"@\"\ -command\ \{unset\ state3\;set\ state3\ 3\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 2\ \ \ \}\n\ \ button\ \ .b0\ -text\ \"C\"\ -command\ \{\ ClrCanvas\ .cv\ \}\n\ \ button\ \ .b1\ -text\ \"Text\"\ \ -command\ \{\ PaintText\ .cv\ \"Chinese\ Xiangqi\ Chess\"\ \}\n\ \ button\ \ .b2\ -text\ \"+\"\ \ -command\ \{\ DrawAxis\ \ .cv\ \}\n\ \ button\ \ .b3\ -text\ \"\\\[\\\]\"\ \ \ -command\ \{\ DrawBox\ \ \ .cv\ \}\n\ \n\ \ button\ \ .b6\ -text\ \"#dn\"\ \ \ -command\ \{\ refreshgrid\ .cv\ 2\ \}\ \ \ \n\n\ \ button\ \ .b7\ -text\ \"#up\"\ \ \ -command\ \{\ refreshgrid\ .cv\ 1\ \}\ \n\ \ button\ \ .b8\ -text\ \"#^\"\ \ \ -command\ \{.cv\ scale\ all\ 0\ 0\ 1.1\ 1.1\ \}\n\ \ button\ \ .b9\ -text\ \"#<\"\ \ \ -command\ \{.cv\ scale\ all\ 0\ 0\ .9\ .9\ \}\ \ \n\ \ button\ \ .b10\ -text\ \"x\"\ \ \ -command\ \{\ exit\ \ \ \ \}\n\ \ \ set\ info\ \"000\ 000\"\n\ \ \ label\ \ .info\ -textvar\ info\ -just\ left\n\ \ pack\ .a0\ .a1\ .a2\ .b0\ .b1\ .b2\ .b3\ \ .b6\ .b7\ .b8\ .b9\ .b10\ .info\ -in\ .f2\ \ -side\ left\ -padx\ 2\n\n\ #catch\ \{console\ show\}\nset\ oscwidth\ 1000\ \n\ set\ oschorizontal\ 500\ \n\ proc\ loop\ \{from\ to\ body\}\ \{\n\ \ \ \ upvar\ 1\ i\ i\ \;#\ make\ index\ visible\ in\ body\n\ \ \ \ for\ \{set\ i\ \$from\}\ \{\$i<\$to\}\ \{incr\ i\}\ \{uplevel\ 1\ \$body\}\n\ \}\n#--\ And\ likewise,\ a\ shortcut\ for\ addition:\n\ proc\ +\ \{a\ b\}\ \{expr\ \{\$a+\$b\}\}\n\ \n\ #pack\ \[canvas\ .cv\ -width\ 400\ -height\ 500\ \]\n\n#\ focus\ .cv\ \n\ set\ state2\ 1\n\ proc\ refreshgrid\ \{\ .cv\ state2\}\ \{\n\ global\ oscwidth\ oschorizontal\ colorite\n\ global\ grid\n\ \ global\ ind\ indx\n\ \ set\ ind\ 0\n\ \ set\ indx\ 0\n\ set\ colorite\ blue\ \n\ for\ \{set\ x\ 10\}\ \{\$x<\$oscwidth\}\ \{incr\ x\ 50\}\ \{.cv\ create\ line\ \$x\ 0\ \$x\ \$oschorizontal\ \ -fill\ blue\ -tag\ grid\ -width\ 4\}\n\ for\ \{set\ y\ 20\}\ \{\$y<\$oschorizontal\}\ \{incr\ y\ 50\}\ \{.cv\ create\ line\ 0\ \$y\ \$oschorizontal\ \$y\ -fill\ blue\ \ -tag\ grid\ -width\ 4\}\ \n\ .cv\ itemconfigure\ grid\ -fill\ blue\ \n\n\ if\ \{\ \$state2\ ==\ 1\ \}\ \{\ .cv\ raise\ grid\ \;\}\ \n\ if\ \{\ \$state2\ ==\ 2\ \}\ \{\ .cv\ lower\ grid\ \;\}\ \n\ \}\n\n\ \ refreshgrid\ \ .cv\ \$state2\ \n\ #\ next\ lines\ start\ withn\ periods,\ but\ hard\ to\ see\n\ .\ configure\ -borderwidth\ 0\ -highlightthickness\ 0\ -takefocus\ 0\ -background\ aquamarine4\n\ .\ configure\ -background\ palegreen\ -highlightcolor\ DarkOliveGreen\ -relief\ raised\ -border\ 30\n\n\ .\ configure\ -background\ palegreen\ -highlightcolor\ DarkOliveGreen\ -relief\ raised\ -border\ 30\n\ .\ configure\ -width\ 1000\ -height\ 2000\n\n.cv\ bind\ all\ <1>\ \{set\ p(X)\ \[.cv\ canvasx\ %x\]\;\ set\ p(Y)\ \[.cv\ canvasy\ %y\]\;set\ info\ \"\ %x\ %y\ \"\}\n\ .cv\ bind\ mv\ <B1-Motion>\ \{mv\ .cv\ %x\ %y\}\n\ .cv\ bind\ mv\ <ButtonRelease-1>\ \{set\ info\ \"\ %x\ %y\ \"\}\n\ #.cv\ bind\ moveable\ <ButtonPress-1>\ \{item:move\ %W\ %x\ %y\ 1\;set\ info\ \"\ %x\ %y\ \"\}\n\ proc\ mv\ \{w\ x\ y\}\ \{\n\ \ \ \ global\ p\n\ \ \ \ set\ x\ \ \[\$w\ canvasx\ \$x\]\n\ \ \ \ set\ y\ \ \[\$w\ canvasy\ \$y\]\n\ \ \ \ set\ id\ \[\$w\ find\ withtag\ current\]\n\ \ \ \ set\ numberx\ \[\$w\ \ gettags\ current\]\n\ \ \ \ regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ \n\ \ \ \ puts\ \"1\"\n\ \ \ \ puts\ \$numberx\n\ \ \ \ puts\ \$tilex\n\ \ \ \ puts\ \"\ with\ tag\ \[\$w\ find\ withtag\ obj_\$tilex\ \]\"\n\ \ \ \ foreach\ item\ \[\$w\ find\ withtag\ obj_\$tilex\ \]\ \{\n\ \ \ \ \$w\ move\ \$item\ \[expr\ \{\$x-\$p(X)\}\]\ \[expr\ \{\$y-\$p(Y)\}\]\n\ \ \ \ #\$w\ raise\ \$id\n\ \ \ \ \}\n\ \ \ \ puts\ \"\ x\ y\ \$x\ \$y\"\n\ \ \ \ #\$w\ raise\ \$id\n\ \ \ \ #\ \$w\ move\ \[\$w\ find\ withtag\ \"\$tilex\"\]\ \[expr\ \{\$x-\$p(X)\}\]\ \[expr\ \{\$y-\$p(Y)\}\]\n\ \ \ \ #set\ numberx\ \[\$w\ \ gettags\ current\]\n\ \ \ \ #regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ set\ p(X)\ \$x\;\ set\ p(Y)\ \$y\n\ \}\n\ \n\ \ \ \ proc\ board\ \{w\}\ \{\n\ \ \ \ #set\ state3\ 1\n\ \ \ \ set\ state2\ 1\n\ \ \ \ ClrCanvas\ \$w\n\ \ \ \ .\ configure\ -background\ orange\ -highlightcolor\ brown\ -relief\ raised\ -border\ 30\n\ \ \ \ \$w\ configure\ -bg\ tan\n\ \ \ \ \n\ \ \ \ refreshgrid\ \ .cv\ \$state2\ \;\n\ \ \ \ \}\n\ \ \ \ proc\ gamepieces\ \{state3\}\ \{\n\ \ \ \ \ global\ bluepieces\ redpieces\n\ \ \ \ \ if\ \{\ \$state3\ ==\ 2\ \}\ \{\ \n\ \ \ \ \ set\ bluepieces\ \[list\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]\n\ \ \ \ \ set\ redpieces\ \ \[list\ 0\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]\n\ \ \ \ \ \ \ \}\ \n\ \ \ \ \ \n\ \ \ \ if\ \{\ \$state3\ ==\ 3\ \}\ \{\ \n\ \ \ \ \ #black\ western\n\ \ \ \ \ set\ bluepieces\ \{\ \ \\u265A\ \\u265B\ \\u265C\ \\u265C\ \\u265D\ \\u265D\ \\u265E\ \\u265E\ \\u265F\ \\u265F\ \\u265F\ \\u265F\ \\u265F\ \\u265F\ \\u265F\ \\u265F\}\ \ \n\ \ \ \ \ #white\ western\n\ \ \ \ \ set\ redpieces\ \{\ 0\ \ \\u2654\ \\u2655\ \\u2655\ \\u2656\ \ \\u2656\ \\u2657\ \\u2657\ \ \\u2658\ \\u2658\ \\u2659\ \\u2659\ \\u2659\ \ \\u2659\ \\u2659\ \\u2659\ \\u2659\ \\u2659\}\ \ \n\ \ \ \ \ \ \ \}\n\ \ \ \ \ \ if\ \{\ \$state3\ ==\ 1\ \}\ \{\ \n\ \ \ \ \ \ set\ bluepieces\ \{\\u5C07\ \\u58EB\ \ \\u58EB\ \ \\u8C61\ \\u8C61\ \\u99AC\ \\u99AC\ \\u8ECA\ \\u8ECA\ \ \ \\u7832\ \ \ \\u7832\ \ \ \ \\u5352\ \\u5352\ \\u5352\ \ \ \\u5352\ \\u5352\}\n\ set\ redpieces\ \ \{\ \ 0\ \\u5E25\ \ \ \\u4ED5\ \\u4ED5\ \ \ \\u76F8\ \ \ \\u76F8\ \\u99AC\ \\u99AC\ \\u8ECA\ \\u8ECA\ \ \ \ \ \ \\u70AE\ \ \\u70AE\ \ \\u5175\ \ \\u5175\ \ \ \ \\u5175\ \ \ \ \ \\u5175\ \ \ \\u5175\ \ \}\ \ \n\ \ \ \ \ \}\n\ \n\ \ \ \ \ \}\n\n\ \ \ \ \ set\ ind\ 0\n\ \ \ \ \ set\ indx\ 0\n\ \ \ \ \ set\ baseline\ \{list\ 1\}\n\ \ \ \ \ \ proc\ K\ \{\ x\ y\ \}\ \{\ set\ x\ \}\n\n\ \ \ \ \ proc\ xpop\ \{\ topper\ \}\ \{\n\ \ \ \ \ global\ liner\ \n\ \ \ \ \ global\ ind\ indx\ \n\ \ \ \ \ global\ bluepieces\ redpieces\n\ \ \ \ \ global\ baseline\n\ \ \ \ \ set\ topper\ \[\ lindex\ \$bluepieces\ \$ind\ \]\;\n\ \ \ \ \ if\ \{\ \$topper\ ==\ \"\"\ \}\ \{\ \n\ \ \ \ \ set\ topper\ \[\ lindex\ \$redpieces\ \$indx\ \]\n\ \ \ \ \ set\ indx\ \[\ expr\ \{\ \$indx\ +\ 1\}\]\n\ \ \ \ \ \ \ \}\ \n\ \ \ \ \ set\ ind\ \[\ expr\ \{\ \$ind\ +\ 1\}\]\n\ \ \ \ \ lappend\ \$baseline\ \$topper\;\n\ \ \ \ \ return\ \$topper\;\n\ \ \ \ \ \}\n\ \ \ \ \ set\ state2\ 1\n\ \ \ \ \ \ \ \ \ \ proc\ populateCanvas\ \{w\ cols\ rows\ args\}\ \{\n\ \ \ \ global\ state2\ state3\n\ \ \ \ gamepieces\ \$args\n\ \ \ \ #refreshgrid\ \ \$w\ \$state2\ \n\ \ \ \ set\ state3\ \$args\n\ \ \ \ global\ ind\ indx\n\ \ \ \ variable\ ids\ \;#\ links\ text\ ids\ with\ respective\ rect\ ids\n\ \ \ \ variable\ boxes\ \;#\ lists\ text\ id\ and\ text\ associated\ with\ each\ rect\ id\n\ \ \ \ catch\ \{unset\ ids\ boxes\}\n\ \ \ \ set\ canvas\ \$w\n\ \ \ \ \n\ \ \ \ #\ parameters\ for\ drawing\ boxes\n\ \ \ \ set\ boxwidth\ 50\n\ \ \ \ set\ boxheight\ 50\n\ \ \ \ set\ padx\ 3\n\ \ \ \ set\ pady\ 3\n\ \ \ \ set\ colors\ \{\ orange\ yellow\ green\ \ gray\}\n\ \ \ \ set\ labels\ \{one\ two\ three\ four\}\n\n\ \ \ \ #\ draw\ the\ boxes\n\ \ \ \ for\ \{set\ row\ 0\}\ \{\$row\ <\ \$rows\}\ \{incr\ row\}\ \{\n\ \ \ \ \ \ for\ \{set\ col\ 0\}\ \{\$col\ <\ \$cols\}\ \{incr\ col\}\ \{\n\n\ \ \ \ \ \ \ \ #\ calculate\ coordinates\n\ \ \ \ \ \ \ \ set\ x1\ \[expr\ \{\$col\ *\ (\$boxwidth\ +\ \$padx)\ +\ \$padx\}\]\n\ \ \ \ \ \ \ \ set\ x2\ \[expr\ \{\$x1\ +\ \$boxwidth\}\]\n\ \ \ \ \ \ \ \ set\ x3\ \[expr\ \{\$x1\ +\ (\$boxwidth\ /\ 2)\}\]\n\ \ \ \ \ \ \ \ set\ y1\ \[expr\ \{\$row\ *\ (\$boxheight\ +\ \$pady)\ +\ \$pady\}\]\n\ \ \ \ \ \ \ \ set\ y2\ \[expr\ \{\$y1\ +\ \$boxheight\}\]\n\ \ \ \ \ \ \ \ set\ y3\ \[expr\ \{\$y1\ +\ (\$boxheight\ /\ 2)\}\]\n\n\ \ \ \ \ \ \ \ #\ choose\ color\ and\ text\n\ \ \ \ \ \ \ \ set\ color\ \[lindex\ \$colors\ \[expr\ \{int(rand()\ *\ \[llength\ \$colors\])\}\]\]\n\ \ \ \ \ \ \ \ #set\ text\ \[lindex\ \$labels\ \[expr\ \{int(rand()\ *\ \[llength\ \$labels\])\}\]\]\n\ \ \ \ \ \ \ \ #\ set\ text\ \[xpop\ topper\]\n\ \ \ \ \ \ \ \ \ set\ font2\ \[list\ Helvetica\ \[expr\ \$boxwidth/2\]\]\n\n\ \ \ \ \ \ \ \ \ set\ text\ \"0\"\n\ \ \ \ \ \ \ \ \ #set\ text\ \"K\"\n\ \ \ \ \ \ \ \ \ set\ texter\ \[xpop\ 1\ \]\n\ \ \ \ \ \ \ \ \ set\ tilename\ \ \[expr\ \{int(rand()*1000000000.)\}\]\n\ \ \ \ \ \ \ \ #\ create\ the\ boxes\n\ \ \ \ \ \ \ \ set\ boxid\ \[\$w\ create\ oval\ \$x1\ \$y1\ \$x2\ \$y2\ \\\n\ \ \ \ \ \ \ \ \ \ -fill\ \$color\ -tags\ \[concat\ mv\ rect\ \$args\ \ obj_\$tilename\]\\\n\ \ \ \ \ \ \ \ \ \ -outline\ black\]\n\ \ \ \ \ \ \ \ set\ colorfo\ blue\n\ \ \ \ \ \ \ \ if\ \{\ \$indx\ >\ 1\ \}\ \{set\ colorfo\ red\}\n\ \ \ \ \ \ \ \ #set\ textid\ \[\$w\ create\ text\ \$x3\ \$y3\ -font\ \$font2\ -fill\ \$colorfo\ \\\n\ \ \ \ \ \ \ \ #\ \ -text\ \$text\ -tags\ \[concat\ mv\ \ \$args\ \ obj_\$tilename\]\ \ \]\n\n\ \ \ \ \ \ \ \ \ set\ textid\ \[\$w\ create\ text\ \$x3\ \$y3\ -font\ \$font2\ -fill\ \$colorfo\ \\\n\ \ \ \ \ \ \ \ \ \ -text\ \$texter\ -tags\ \[concat\ mv\ \ \$args\ \ obj_\$tilename\ \]\ \ \]\n\n\ \ \ \ \ \ \ \ #\ remember\ which\ text\ item\ goes\ with\ which\ box\ and\ what\ the\ text\ says\n\ \ \ \ \ \ \ \ set\ boxes(\$boxid)\ \[list\ \$textid\ \$text\]\n\ \ \ \ \ \ \ \ set\ ids(\$textid)\ \$boxid\n\ \ \ \ \ \ \ \ set\ ids(\$boxid)\ \$boxid\n\ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \}\ \ \n\ \ \ \ \ populateCanvas\ .cv\ 6\ 6\ 1\ \n\ \ \ \ \ \ \ \ #start\ of\ deck\n\n\ \ \ \ #end\ of\ deck\n\ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\ \ \ \ \ \ \n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ #end\ of\ deck\n======\n\n****Version\ with\ added\ hacks\ and\ pegboard****\n\n======\n\ \ \ \ #start\ of\ deck\n\ \ \ \ \ \ \ \ #start\ of\ deck\n\ \ \ \ \ \ \ \ #start\ of\ deck\ \n\ \ \ #!/bin/sh\n\n\ \ \ #!/bin/sh\n\ #\ Restart\ with\ tcl:\ -*-\ mode:\ tcl\;\ tab-width:\ 4\;\ -*-\ \\\n\ exec\ wish\ \$0\ \$\{1+\"\$@\"\}\n\n\ #\ demo2-canvas.tcl\ -\ HaJo\ Gurt\ -\ 2005-12-13\ -\ http://wiki.tcl.tk/15073\n\ #:\ CanvasDemo:\ On\ button-click,\ draw\ something\ on\ the\ canvas\n\ #\ gold\ used\ canvas\ demo\ as\ base\ for\ TCL\ \ chess\ display\ board.\n\ \n\ #\ written\ on\ Windowws\ XP\ on\ eTCL\ \n\ \ \ \ \ #\ working\ under\ TCL\ version\ 8.5.6\ and\ eTCL\ 1.0.1\ \n\ \ \ \ \ #\ gold\ on\ TCL\ WIKI\ ,\ 17Jul2010\n\n\ \ \ \ \ \ \ \ proc\ scr\ \{w\}\ \{\n\ \ \ \ \ \ \ \ console\ show\n\ \ \ \ \ \ \ \ set\ \ max\ 400\n\ \ \ \ \ \ \ \ set\ \ may\ 400\ \n\ for\ \{set\ r\ 50\}\ \{\$r\ <\ \$max\}\ \{incr\ r\ 45\}\ \{\n\ \ \ \ \ for\ \{set\ c\ 50\}\ \{\$c\ <\ \$max\}\ \{incr\ c\ 45\}\ \{\n\ \ \ \ \ \ \ \ set\ tilename\ \ \[expr\ \{int(rand()*1000000000.)\}\]\n\ \ \n\ \ \ \ \ \ \ \ \ \$w\ create\ oval\ \$r\ \$c\ \[expr\ \$r+5\]\ \[expr\ \$c+5\]\ -outline\ gray\ -fill\ green\ -width\ 1\ \\\n\ \ \ \ \ \ \ \ \ -tags\ \[concat\ mv\ xdat_\[expr\ \$r+5\]\ \ ydat_\[expr\ \$c+5\]\ obj_\$tilename\]\n\ \ \ \ \ \ \ \ \ \ \ puts\ \"\ xdat_\[expr\ \$r+5\]\ \ ydat_\[expr\ \$c+5\]\ obj_\$tilename\"\n\ \ \ \ \ \ \ \ set\ texter\ \ \"\ \ \[expr\ \$r+5\]\ \[expr\ \$c+5\]\ \ \"\n\ \ \ \ \ \ \ \$w\ create\ text\ \[expr\ \$r+5\]\ \[expr\ \$c+20\]\ \\\n\ \ \ \ \ \ \ \ \ \ -text\ \$texter\ -fill\ green\ -tags\ \"\ \ \[expr\ \$r+5\]\ \[expr\ \$c+20\]\"\n\n\ \}\}\}\n\ \n\ \ \ package\ require\ Tk\n\n\ \ proc\ ClrCanvas\ \{w\}\ \{\n\ \ \ \ \$w\ delete\ \"all\"\n\ \ \ \ \$w\ configure\ \ -bg\ white\n\ \ \}\n\n\ \ proc\ DrawAxis\ \{w\}\ \{\n\ \ \ \ set\ midX\ \[expr\ \{\ \$::maxX\ /\ 2\ \}\]\n\ \ \ \ set\ midY\ \[expr\ \{\ \$::maxY\ /\ 2\ \}\]\n\ \ \ \ \$w\ create\ line\ 0\ \ \ \ \ \$midY\ \ \$::maxX\ \ \ \$midY\ \ -tags\ \"axis\"\n\ \ \ \ \$w\ create\ line\ \$midX\ 0\ \ \ \ \ \ \ \ \$midX\ \$::maxY\ \ -tags\ \"axis\"\n\ \ \}\n\n\ \ proc\ PaintText\ \{w\ Txt\}\ \{\n\ \ \ \ global\ y\n\ \ \ \ incr\ y\ 10\n\ \ \ \ \$w\ create\ text\ 100\ \$y\ -text\ \$Txt\ -tags\ \"text\"\n\ \ \}\n\n\ \ proc\ DrawBox\ \{w\}\ \{\n\ \ \ \ global\ x1\ y1\ x2\ y2\n\ \ \ \ \$w\ create\ rect\ \ 50\ \ 50\ \ 100\ \ 90\ \ -tags\ \"box\"\n\ \ \ \ \$w\ create\ rect\ \$x1\ \$y1\ \ \$x2\ \$y2\ \ -tags\ \"box\"\n\ \ \ \ incr\ x1\ 15\n\ \ \ \ incr\ x2\ 15\n\ \ \ \ incr\ y1\ 10\n\ \ \ \ incr\ y2\ 10\n\ \ \}\n\n\ \ proc\ DrawFn1\ \{w\}\ \{\n\ \ \ \ \$w\ create\ line\ 0\ 100\ \ 50\ 200\ \ 100\ 50\ \ 150\ 70\ \ 200\ 155\ \ 250\ 50\ \ 300\ 111\ \ 350\ 222\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ -tags\ \"Fn1\"\ \ -smooth\ bezier\n\ \ \}\n\n\ \ proc\ DrawFn2\ \{w\}\ \{\n\ \ \ \ set\ offY\ 0\ \ \ \ \;#\ \[expr\ \{\ \$::maxY\ /\ 2\ \}\]\n\n\ \ \ \ for\ \{\ set\ x\ 0\ \}\ \{\ \$x\ <=\ \$::maxX\ \}\ \{\ incr\ x\ 5\ \}\ \{\n\ \ \ \ \ \ set\ y\ \[expr\ \{\ rand()\ *\ \$::maxY\ +\ \$offY\ \}\]\n\n\ \ \ \ \ #puts\ \"\$x\ \$y\"\n\ \ \ \ \ \ if\ \{\$x>0\}\ \{\ \$w\ create\ line\ \$x0\ \$y0\ \$x\ \$y\ -tags\ \"Fn2\"\ \}\n\ \ \ \ \ \ set\ x0\ \$x\n\ \ \ \ \ \ set\ y0\ \$y\n\ \ \ \ \}\n\ \ \}\n\n\ \ #:\ Main\ :\n\ \ frame\ .f1\n\ \ frame\ .f2\n\ \ pack\ \ .f1\ .f2\n\n\ \ set\ maxX\ 400\n\ \ set\ maxY\ 450\n\ \ set\ y\ \ \ \ \ \ 0\n\n\ \ set\ x1\ 120\n\ \ set\ x2\ 150\n\ \ set\ y1\ \ 50\n\ \ set\ y2\ \ 80\n\n\ \ canvas\ \ .cv\ -width\ \$maxX\ -height\ \$maxY\ \ -bg\ tan\n\ \ pack\ \ \ \ .cv\ -in\ .f1\n\ \ button\ \ .a0\ -text\ \"xiangqi\"\ -command\ \{set\ state2\ 1\;set\ state3\ 1\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 1\ \ \ \}\n\ \ button\ \ .a1\ -text\ \"west*\"\ -command\ \{unset\ state3\;set\ state3\ 3\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 3\ \ \ \}\n\ \ button\ \ .a2\ -text\ \"@\"\ -command\ \{unset\ state3\;set\ state3\ 3\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 2\ \ \ \}\n\ \ button\ \ .a3\ -text\ \"&\"\ -command\ \{\ \ ClrCanvas\ .cv\;scr\ .cv\ \ \ \}\n\ \ button\ \ .a4\ -text\ \"?\"\ -command\ \{\ \ squarenames\ .cv\;\ refreshgrid\ .cv\ 1\ \ \}\n\ \ \ button\ \ .b0\ -text\ \"C\"\ -command\ \{\ ClrCanvas\ .cv\ \}\n\ \ button\ \ .b1\ -text\ \"Text\"\ \ -command\ \{\ PaintText\ .cv\ \"Chinese\ Xiangqi\ Chess\"\ \}\n\ \ button\ \ .b2\ -text\ \"+\"\ \ -command\ \{\ DrawAxis\ \ .cv\ \}\n\ \ button\ \ .b3\ -text\ \"\\\[\\\]\"\ \ \ -command\ \{\ DrawBox\ \ \ .cv\ \}\n\ \n\ \ button\ \ .b6\ -text\ \"#dn\"\ \ \ -command\ \{\ refreshgrid\ .cv\ 2\ \}\ \ \ \n\n\ \ button\ \ .b7\ -text\ \"#up\"\ \ \ -command\ \{\ refreshgrid\ .cv\ 1\ \}\ \n\ \ button\ \ .b8\ -text\ \"#^\"\ \ \ -command\ \{.cv\ scale\ all\ 0\ 0\ 1.1\ 1.1\ \}\n\ \ button\ \ .b9\ -text\ \"#<\"\ \ \ -command\ \{.cv\ scale\ all\ 0\ 0\ .9\ .9\ \}\ \ \n\ \ button\ \ .b10\ -text\ \"x\"\ \ \ -command\ \{\ exit\ \ \ \ \}\n\ \ \ set\ info\ \"000\ 000\"\n\ \ \ label\ \ .info\ -textvar\ info\ -just\ left\n\ \ pack\ .a0\ .a1\ .a2\ .a3\ .a4\ .b0\ .b1\ .b2\ .b3\ \ .b6\ .b7\ .b8\ .b9\ .b10\ .info\ -in\ .f2\ \ -side\ left\ -padx\ 2\n\n\ \ \ #catch\ \{console\ show\}\n\ \ \ set\ oscwidth\ 1000\ \n\ set\ oschorizontal\ 500\ \n\ proc\ loop\ \{from\ to\ body\}\ \{\n\ \ \ \ upvar\ 1\ i\ i\ \;#\ make\ index\ visible\ in\ body\n\ \ \ \ for\ \{set\ i\ \$from\}\ \{\$i<\$to\}\ \{incr\ i\}\ \{uplevel\ 1\ \$body\}\n\ \}\n\ \ \ #--\ And\ likewise,\ a\ shortcut\ for\ addition:\n\ proc\ +\ \{a\ b\}\ \{expr\ \{\$a+\$b\}\}\n\ \n\ #pack\ \[canvas\ .cv\ -width\ 400\ -height\ 500\ \]\n\n\ \ \ \ #\ focus\ .cv\ \n\ set\ state2\ 1\n\ proc\ refreshgrid\ \{\ w\ state2\}\ \{\n\ global\ oscwidth\ oschorizontal\ colorite\n\ global\ grid\n\ \ global\ ind\ indx\n\ \ set\ ind\ 0\n\ \ set\ indx\ 0\n\ \ \ \ set\ colorite\ blue\ \n\ \ \ \n\n\n\nset\ dx\ 45\ \ \ \ \;#\ pixels\ between\ adjacent\ vertical\ grid\ lines\nset\ dy\ 45\ \ \ \ \;#\ pixels\ between\ adjacent\ horizontal\ grid\ lines\nset\ x0\ 30\ \ \ \ \;#\ pixels\ between\ left\ of\ canvas\ and\ left\ of\ grid\nset\ y0\ 30\ \ \ \ \;#\ pixels\ between\ top\ of\ canvas\ and\ top\ of\ grid\n#set\ win\ \$w\ \ \ \;#\ name\ of\ canvas\ widget\nforeach\ i\ \{0\ 8\}\ \{\n\ \ \ \ \$w\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \$y0\\\n\ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{9\ *\ \$dy\ +\ \$y0\}\]\ -width\ 2\ -fill\ blue\ -tag\ grid\n\}\nfor\ \{set\ i\ 1\}\ \{\$i\ <\ 8\}\ \{incr\ i\}\ \{\n\ \ \ \ \$w\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \$y0\\\n\ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{4\ *\ \$dy\ +\ \$y0\}\]\ -width\ 2\ -fill\ blue\ -tag\ grid\n\ \ \ \ \$w\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{5\ *\ \$dy\ +\ \$y0\}\]\\\n\ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{9\ *\ \$dy\ +\ \$y0\}\]\ -width\ 2\ -fill\ blue\ -tag\ grid\n\}\nfor\ \{set\ i\ 0\}\ \{\$i\ <\ 10\}\ \{incr\ i\}\ \{\n\ \ \ \ \$w\ create\ line\ \$x0\ \[expr\ \{\$i\ *\ \$dy\ +\ \$y0\}\]\\\n\ \ \ \ \[expr\ \{8\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{\$i\ *\ \$dy\ +\ \$y0\}\]\ -width\ 2\ -fill\ blue\ -tag\ grid\n\}\n\n\ .cv\ itemconfigure\ grid\ -fill\ blue\ \n\n\ if\ \{\ \$state2\ ==\ 1\ \}\ \{\ .cv\ raise\ grid\ \;\}\ \n\ if\ \{\ \$state2\ ==\ 2\ \}\ \{\ .cv\ lower\ grid\ \;\}\ \n\ \}\n\n\ \ refreshgrid\ \ .cv\ \$state2\ \n\ #\ next\ lines\ start\ withn\ periods,\ but\ hard\ to\ see\n\ .\ configure\ -borderwidth\ 0\ -highlightthickness\ 0\ -takefocus\ 0\ -background\ aquamarine4\n\ .\ configure\ -background\ palegreen\ -highlightcolor\ DarkOliveGreen\ -relief\ raised\ -border\ 30\n\n\ .\ configure\ -background\ palegreen\ -highlightcolor\ DarkOliveGreen\ -relief\ raised\ -border\ 30\n\ .\ configure\ -width\ 1000\ -height\ 2000\n\n\ \ \ \ \ .cv\ bind\ mv\ <ButtonRelease-1>\ \{set\ info\ \"\ %x\ %y\ \"\;\n\ \ \ \ \ \ \ \ catch\ \{.cv\ itemconfigure\ \[lindex\ \$id\ 0\]\ -outline\ black\ -width\ 1\ \}\n\ \ \ \ \}\n\n\ \ .cv\ bind\ all\ <1>\ \{set\ p(X)\ \[.cv\ canvasx\ %x\]\;\ set\ p(Y)\ \[.cv\ canvasy\ %y\]\;set\ info\ \"\ %x\ %y\ \"\}\n\ set\ haloo\ 50\n\ .cv\ bind\ mv\ <B1-Motion>\ \{mv\ .cv\ %x\ %y\}\n\ #.cv\ bind\ mv\ <ButtonRelease-1>\ \{set\ info\ \"\ %x\ %y\ \"\;puts\ \"\ nearest\ \[.cv\ find\ closest\ \ %x\ %y\ \$haloo\ \]\"\}\n\ #.cv\ bind\ moveable\ <ButtonPress-1>\ \{item:move\ %W\ %x\ %y\ 1\;set\ info\ \"\ %x\ %y\ \"\}\n\ \ \ \ \ \ bind\ .cv\ <Motion>\ \{wm\ title\ .\ \"Xiangqi\ Chessboard\ \[expr\ int(\ \[%W\ canvasx\ %x\])\],\[expr\ int\ (\[%W\ canvasy\ \n\n\ %y\])\]\"\}\n\n\ \ \ \ \ proc\ mv\ \{w\ x\ y\}\ \{\n\ \ \ \ global\ p\ id\n\ \ \ \ set\ x\ \ \[\$w\ canvasx\ \$x\]\n\ \ \ \ set\ y\ \ \[\$w\ canvasy\ \$y\]\n\ \ \ \ set\ id\ \[\$w\ find\ withtag\ current\]\n\ \ \ \ set\ numberx\ \[\$w\ \ gettags\ current\]\n\ \ \ \ regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ \n\ \ \ \ puts\ \"1\"\n\ \ \ \ puts\ \$numberx\n\ \ \ \ puts\ \$tilex\n\ \ \ \ puts\ \"\ with\ tag\ \[\$w\ find\ withtag\ obj_\$tilex\ \]\"\n\ \ \ \ foreach\ item\ \[\$w\ find\ withtag\ obj_\$tilex\ \]\ \{\n\ \ \ \ \$w\ move\ \$item\ \[expr\ \{\$x-\$p(X)\}\]\ \[expr\ \{\$y-\$p(Y)\}\]\n\ \ \ \ catch\ \{\$w\ itemconfigure\ \[lindex\ \$id\ 0\]\ -outline\ purple\ -width\ 5\ \}\n\ \ \ \ #\$w\ raise\ \$id\n\ \ \ \ \}\n\ \ \ \ puts\ \"\ x\ y\ \$x\ \$y\"\n\ \ \ \ #\$w\ raise\ \$id\n\ \ \ \ #\ \$w\ move\ \[\$w\ find\ withtag\ \"\$tilex\"\]\ \[expr\ \{\$x-\$p(X)\}\]\ \[expr\ \{\$y-\$p(Y)\}\]\n\ \ \ \ #set\ numberx\ \[\$w\ \ gettags\ current\]\n\ \ \ \ #regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ \ catch\ \{\$w\ itemconfigure\ \[lindex\ \$id\ 0\]\ -outline\ purple\ -width\ 5\ \}\n\ \ \ \ set\ p(X)\ \$x\;\ set\ p(Y)\ \$y\n\ \}\n\n\ \ \ \ proc\ board\ \{w\}\ \{\n\ \ \ \ #set\ state3\ 1\n\ \ \ \ set\ state2\ 1\n\ \ \ \ ClrCanvas\ \$w\n\ \ \ \ .\ configure\ -background\ orange\ -highlightcolor\ brown\ -relief\ raised\ -border\ 30\n\ \ \ \ \$w\ configure\ -bg\ tan\n\ \ \ \ \ \n\ \ \ \ refreshgrid\ \ .cv\ \$state2\ \;\n\ \ \ \ \}\n\ \ \ \n\ \ \ \ \ proc\ squarenames\ \{l\}\ \{\n\ \ \ \ console\ show\n\ \ \ \ set\ result\ \{\}\n\ \ \ \ set\ i\ \[llength\ \$l\]\n\ \ \ \ \ \ \ \ set\ cc\ 0\n\ \ \ \ \ \ \ \ set\ rr\ 0\n\ \ \ \ \ \ \ \ foreach\ row\ \{8\ 7\ 6\ 5\ 4\ 3\ 2\ 1\}\ \{\n\ \ \ \ \ \ \ \ set\ rowscreen\ \[expr\ \{\$rr*50.\}\]\n\ \ \ \ \ \ \ \ foreach\ column\ \{A\ B\ C\ D\ E\ F\ G\ H\}\ \{\n\ \ \ \ \ \ \ \ set\ colscreen\ \ \[expr\ \{\$cc*50.\}\]\ \ \ \n\ \ \ \ \ \ \ \ lappend\ result\ \ \ \"\$column\$row\ \$rowscreen\ \$colscreen\"\n\ \ \ \ \ \ \ \ incr\ cc\ 1\n\ \ \ \ \ \ \ \ incr\ rr\ 1\n\ \ \ \ \ \ \ \ \ \}\}\n\ \ \ \ puts\ \$result\n\ \ \ \ return\ \$result\n\ \ \ \ \n\ \ \ \}\n\ \ \ \ \ \ \n\ \ \ \ \ \ \ \ #foreach\ row\ \{8\ 7\ 6\ 5\ 4\ 3\ 2\ 1\}\ \{\n\ \ \ \ \ \ \ \ #foreach\ column\ \{A\ B\ C\ D\ E\ F\ G\ H\}\ \{\n\ \ \ \ \ \ \ \ #\ \ \ \ lappend\ res\ \[\"\ \"\ \"\$column\$row\"\]\n\ \ \ \ \ \ \ \ #puts\ \"\ \ \$column\$row\ \"\n\ \ \n\ \ \ \ proc\ gamepieces\ \{state3\}\ \{\n\ \ \ \ \ global\ bluepieces\ redpieces\n\ \ \ \ \ if\ \{\ \$state3\ ==\ 2\ \}\ \{\ \n\ \ \ \ \ set\ bluepieces\ \[list\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]\n\ \ \ \ \ set\ redpieces\ \ \[list\ 0\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]\n\ \ \ \ \ \ \ \}\ \n\ \ \ \ \ \n\ \ \ \ if\ \{\ \$state3\ ==\ 3\ \}\ \{\ \n\ \ \ \ \ #black\ western\n\ \ \ \ \ set\ bluepieces\ \{\ \ \\u265A\ \\u265B\ \\u265C\ \\u265C\ \\u265D\ \\u265D\ \\u265E\ \\u265E\ \\u265F\ \\u265F\ \\u265F\ \\u265F\ \n\n\\u265F\ \\u265F\ \\u265F\ \\u265F\}\ \ \n\ \ \ \ \ #white\ western\n\ \ \ \ \ set\ redpieces\ \{\ 0\ \ \\u2654\ \\u2655\ \\u2655\ \\u2656\ \ \\u2656\ \\u2657\ \\u2657\ \ \\u2658\ \\u2658\ \\u2659\ \\u2659\ \n\n\\u2659\ \n\n\ \\u2659\ \\u2659\ \\u2659\ \\u2659\ \\u2659\}\ \ \n\ \ \ \ \ \ \ \}\n\ \ \ \ \ \ if\ \{\ \$state3\ ==\ 1\ \}\ \{\ \n\ \ \ \ \ \ set\ bluepieces\ \{\\u5C07\ \\u58EB\ \ \\u58EB\ \ \\u8C61\ \\u8C61\ \\u99AC\ \\u99AC\ \\u8ECA\ \\u8ECA\ \ \ \\u7832\ \ \ \\u7832\ \ \ \ \n\n\\u5352\ \\u5352\ \\u5352\ \ \ \\u5352\ \\u5352\}\n\ set\ redpieces\ \ \{\ \ 0\ \\u5E25\ \ \ \\u4ED5\ \\u4ED5\ \ \ \\u76F8\ \ \ \\u76F8\ \\u99AC\ \\u99AC\ \\u8ECA\ \\u8ECA\ \ \ \ \ \ \\u70AE\ \ \n\n\\u70AE\ \n\n\ \\u5175\ \ \\u5175\ \ \ \ \\u5175\ \ \ \ \ \\u5175\ \ \ \\u5175\ \ \}\ \ \n\ \ \ \ \ \}\n\ \n\ \ \ \ \ \}\n\ \ \ \ \n\ \ \ \ \ set\ ind\ 0\n\ \ \ \ \ set\ indx\ 0\n\ \ \ \ \ set\ baseline\ \{list\ 1\}\n\ \ \ \ \ \ proc\ K\ \{\ x\ y\ \}\ \{\ set\ x\ \}\n\n\ \ \ \ \ proc\ xpop\ \{\ topper\ \}\ \{\n\ \ \ \ \ global\ liner\ \n\ \ \ \ \ global\ ind\ indx\ \n\ \ \ \ \ global\ bluepieces\ redpieces\n\ \ \ \ \ global\ baseline\n\ \ \ \ \ set\ topper\ \[\ lindex\ \$bluepieces\ \$ind\ \]\;\n\ \ \ \ \ if\ \{\ \$topper\ ==\ \"\"\ \}\ \{\ \n\ \ \ \ \ set\ topper\ \[\ lindex\ \$redpieces\ \$indx\ \]\n\ \ \ \ \ set\ indx\ \[\ expr\ \{\ \$indx\ +\ 1\}\]\n\ \ \ \ \ \ \ \}\ \n\ \ \ \ \ set\ ind\ \[\ expr\ \{\ \$ind\ +\ 1\}\]\n\ \ \ \ \ lappend\ \$baseline\ \$topper\;\n\ \ \ \ \ return\ \$topper\;\n\ \ \ \ \ \}\n\ \ \ \ \ set\ state2\ 1\n\ \ \ \ \ \ \ \ \ \ proc\ populateCanvas\ \{w\ cols\ rows\ args\}\ \{\n\ \ \ \ global\ state2\ state3\n\ \ \ \ gamepieces\ \$args\n\ \ \ \ #refreshgrid\ \ \$w\ \$state2\ \n\ \ \ \ set\ state3\ \$args\n\ \ \ \ global\ ind\ indx\n\ \ \ \ variable\ ids\ \;#\ links\ text\ ids\ with\ respective\ rect\ ids\n\ \ \ \ variable\ boxes\ \;#\ lists\ text\ id\ and\ text\ associated\ with\ each\ rect\ id\n\ \ \ \ catch\ \{unset\ ids\ boxes\}\n\ \ \ \ set\ canvas\ \$w\n\ \ \ \ \n\ \ \ \ #\ parameters\ for\ drawing\ boxes\n\ \ \ \ set\ boxwidth\ 50\n\ \ \ \ set\ boxheight\ 50\n\ \ \ \ set\ padx\ 3\n\ \ \ \ set\ pady\ 3\n\ \ \ \ set\ colors\ \{\ orange\ yellow\ green\ \ gray\}\n\ \ \ \ set\ labels\ \{one\ two\ three\ four\}\n\n\ \ \ \ #\ draw\ the\ boxes\n\ \ \ \ for\ \{set\ row\ 0\}\ \{\$row\ <\ \$rows\}\ \{incr\ row\}\ \{\n\ \ \ \ \ \ for\ \{set\ col\ 0\}\ \{\$col\ <\ \$cols\}\ \{incr\ col\}\ \{\n\n\ \ \ \ \ \ \ \ #\ calculate\ coordinates\n\ \ \ \ \ \ \ \ set\ x1\ \[expr\ \{\$col\ *\ (\$boxwidth\ +\ \$padx)\ +\ \$padx\}\]\n\ \ \ \ \ \ \ \ set\ x2\ \[expr\ \{\$x1\ +\ \$boxwidth\}\]\n\ \ \ \ \ \ \ \ set\ x3\ \[expr\ \{\$x1\ +\ (\$boxwidth\ /\ 2)\}\]\n\ \ \ \ \ \ \ \ set\ y1\ \[expr\ \{\$row\ *\ (\$boxheight\ +\ \$pady)\ +\ \$pady\}\]\n\ \ \ \ \ \ \ \ set\ y2\ \[expr\ \{\$y1\ +\ \$boxheight\}\]\n\ \ \ \ \ \ \ \ set\ y3\ \[expr\ \{\$y1\ +\ (\$boxheight\ /\ 2)\}\]\n\n\ \ \ \ \ \ \ \ #\ choose\ color\ and\ text\n\ \ \ \ \ \ \ \ set\ color\ \[lindex\ \$colors\ \[expr\ \{int(rand()\ *\ \[llength\ \$colors\])\}\]\]\n\ \ \ \ \ \ \ \ #set\ text\ \[lindex\ \$labels\ \[expr\ \{int(rand()\ *\ \[llength\ \$labels\])\}\]\]\n\ \ \ \ \ \ \ \ #\ set\ text\ \[xpop\ topper\]\n\ \ \ \ \ \ \ \ \ set\ font2\ \[list\ Helvetica\ \[expr\ \$boxwidth/2\]\]\n\n\ \ \ \ \ \ \ \ \ set\ text\ \"0\"\n\ \ \ \ \ \ \ \ \ #set\ text\ \"K\"\n\ \ \ \ \ \ \ \ \ set\ texter\ \[xpop\ 1\ \]\n\ \ \ \ \ \ \ \ \ set\ tilename\ \ \[expr\ \{int(rand()*1000000000.)\}\]\n\ \ \ \ \ \ \ \ #\ create\ the\ boxes\n\ \ \ \ \ \ \ \ set\ boxid\ \[\$w\ create\ oval\ \$x1\ \$y1\ \$x2\ \$y2\ \\\n\ \ \ \ \ \ \ \ \ \ -fill\ \$color\ -tags\ \[concat\ mv\ rect\ \$args\ \ obj_\$tilename\]\\\n\ \ \ \ \ \ \ \ \ \ -outline\ black\]\n\ \ \ \ \ \ \ \ set\ colorfo\ blue\n\ \ \ \ \ \ \ \ if\ \{\ \$indx\ >\ 1\ \}\ \{set\ colorfo\ red\}\n\ \ \ \ \ \ \ \ #set\ textid\ \[\$w\ create\ text\ \$x3\ \$y3\ -font\ \$font2\ -fill\ \$colorfo\ \\\n\ \ \ \ \ \ \ \ #\ \ -text\ \$text\ -tags\ \[concat\ mv\ \ \$args\ \ obj_\$tilename\]\ \ \]\n\n\ \ \ \ \ \ \ \ \ set\ textid\ \[\$w\ create\ text\ \$x3\ \$y3\ -font\ \$font2\ -fill\ \$colorfo\ \\\n\ \ \ \ \ \ \ \ \ \ -text\ \$texter\ -tags\ \[concat\ mv\ \ \$args\ \ obj_\$tilename\ \]\ \ \]\n\n\n\n\ \ \ \ \ \ \ \ #\ remember\ which\ text\ item\ goes\ with\ which\ box\ and\ what\ the\ text\ says\n\ \ \ \ \ \ \ \ set\ boxes(\$boxid)\ \[list\ \$textid\ \$text\]\n\ \ \ \ \ \ \ \ set\ ids(\$textid)\ \$boxid\n\ \ \ \ \ \ \ \ set\ ids(\$boxid)\ \$boxid\n\ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \}\ \ \n\ \ \ \ \ populateCanvas\ .cv\ 6\ 6\ 1\ \n\ \ \ \ \ squarenames\ \{1\ 2\ 3\ \}\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck*\ \n\ \ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\n\ \ \ \ #end\ of\ deck\n\ \ \ \ #end\ of\ deck\n\ \ \ #end\ of\ deck\n\ \ \ #end\ of\ \ deck\n\ \ \ #end\ of\ deck\n\ \ \ #end\ of\ deck\n\ \ \ \ #end\ of\ deck\n\ \n======\n\ \ \ \n----\n'''\[arjen\]\ -\ 2010-06-29\ 03:31:13'''\n\nJust\ a\ minor\ comment:\ the\ characters\ are\ simplified\ Chinese,\ I\ am\ not\ sure\ that\ is\ what\ you\ would\ encounter\ on\ a\ real\ chessboard.\n\n----\ \n\[gold\]#\ \ May\ just\ use\ English\ letters\ initially\ and\ switch\ for\ option\ of\ simplified\ or\ traditional\ characters.\n\n\[gold\]\ 1jul2010,\ There\ are\ Xiangqi\ sets\ with\ simplified\ characters\ made\ in\ PRC,\nbut\ probably\ not\ common\ elsewhere.\ Really\ lacking\ though,\ are\nspecific\ unicode\ fonts\ for\ Xiangqi.\ Meanwhile\ code\ will\ make\ do\ with\nlanguage\ fonts.\ \n\n----\n\[AMG\]:\ A\ note\ concerning\ the\ \[\[\[list\]\]\]\ command:\ It's\ not\ necessary\ to\ use\ \[\[list\]\]\ if\ none\ of\ the\ elements\ are\ the\ product\ of\ substitution.\ \ In\ other\ words,\ if\ the\ list\ will\ always\ have\ the\ same\ elements,\ you\ don't\ need\ the\ \[\[list\]\]\ command\ to\ construct\ the\ list.\ \ Instead\ simply\ surround\ the\ list\ with\ \{braces\}.\ \ Its\ internal\ representation\ will\ become\ list\ when\ it\ gets\ used\ as\ a\ list,\ since\ Tcl\ has\ \[duck\ typing\].\ \ Similar\ goes\ for\ \[\[\[dict\ create\]\]\].\ \ I\ mean,\ when\ you\ want\ a\ number,\ you\ just\ type\ the\ number,\ even\ though\ its\ initial\ internal\ representation\ will\ be\ string.\ \ It\ \"becomes\"\ a\ number\ when\ context\ shows\ that\ it\ is\ a\ number.\ \ You\ never\ see\ code\ that\ does\ this:\ `set\ var\ \[\[expr\ 5\]\]`\;\ only\ this:\ `set\ var\ 5`.\n\n***test\ on\ chess\ and\ xiangqi\ fonts***\n\ \n\ \ \ \ \ ***set\ bluepieces\ \ \{將士\ \ 士將\ \ 象\ 象\ 馬\ 馬\ 車\ 車\ \ \ 砲\ \ \ 砲\ \ \ \ 卒\ 卒卒\ \ \ 卒卒\ \ \ \]#trad.\ \ \ \ \n\ \ \ \ \n\ \ \ \ \ ***set\ redpieces\ \ \{\ \ 帥\ \ \ 仕\ \ 象\ 象\ \ 相\ \ \ 相\ 馬\ 馬\ 車\ 車\ 砲\ 砲\ \ \ 兵炮\ \ 炮\ \ 兵\ \ \ \ \ 兵\ \ \ \ \ 兵\ \ \ 兵\ \ \ \]\ #trad\n\ \ \ \n\ \ \ \ \ ***set\ bluepieces\ \ \{王\ 王\ 王\ 象\ 象\ 马\ 马\ 车\ 车\ \ 炮\ 炮\ \ 典\ 典\ 典\ 典\ 典\ 典\}***#simplified\n\ \ \ \ \ ***set\ redpieces\ \ \{王\ 王\ 王\ 象\ 象\ 马\ 马\ 车\ 车\ \ 炮\ 炮\ \ 典\ 典\ 典\ 典\ 典\ 典\}***simplified\n\ \ \ \ \ set\ bluepieces\ \{K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]#english\ letters\n\ \ \ \ \ set\ redpieces\ \ \{K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]#english\ letters\n\n\ babelfish\ gives炮\n***国王一般普通话大象马运输车大炮战士典当***\n\ from\ \nking\ general\ mandarin\ elephant\nhorse\ chariot\ cannon\ soldier\ pawn,\n\ \ \ #\ probably\ need\ an\ if\ switch\ option\ for\ TCL\ lists\ \ \n\ \ \ \ \ \n\ \ \ \ \ ***set\ bluepieces\ \ \[list\ \ 將士\ \ 士將\ \ 象\ 象\ 馬\ 馬\ 車\ 車\ \ \ 砲,\ \ 砲,\ \ \ 卒\ 卒卒\ \ \ 卒卒\ \ \ \]#trad.\ \ \ \ \n\ \ \ \ \n\ \ \ \ \ ***set\ redpieces\ \ \[list\ \ 帥\ \ \ 仕,\ 象\ 象\ \ 相\ \ \ 相\ 馬\ 馬\ 車\ 車\ 砲\ 砲\ \ \ 兵炮\ \ 炮\ \ 兵\ \ \ \ \ 兵\ \ \ \ \ 兵\ \ \ 兵\ \ \ \]\ #trad\n\ \ \ \ \n\n\ \ \ 將\ King\ \ \ 士\ 士Adviser\ 車\ 車chaRiot\ \ \  \ \ 馬\ 馬Horse\ \ \ 炮\ \ 炮Cannon \ \ \ \ \ 象象\ Elephant卒 卒\ 卒\ 卒\ 卒Pawn\n \ \ \ \ \ 帥\ \ \ King\ \ \ \ \ \ \ \  仕\  仕\ Adviser\ 車\ \ \ 車\ \ chaRiot\ \ \  馬\  馬\ \ \ Horse\ 炮\ 炮\ \ Cannon 仕\  仕\ \ \ \ \ \ Elephant 兵\ \ 兵兵兵兵\ Pawn\n\ \n\ \ \ \ \ ***set\ bluepieces\ \ \[list\ 王\ 王\ 王\ 象\ 象\ 马\ 马\ 车\ 车\ \ 炮\ 炮\ \ 典\ 典\ 典\ 典\ 典\ 典\]***#simplified\n\ \ \ \ \ ***set\ redpieces\ \ \[list\ 王\ 王\ 王\ 象\ 象\ 马\ 马\ 车\ 车\ \ 炮\ 炮\ \ 典\ 典\ 典\ 典\ 典\ 典\]***simplified\n\ \ \ \ \ set\ bluepieces\ \[list\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]#english\ letters\n\ \ \ \ \ set\ redpieces\ \ \[list\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]#english\ letters\n\n\n***♔','♕','♖','♗','♘','♙','♚','♛','♜','♝','♞','♟'***\n\n***gummy\ version\ with\ \ purple\ highlights\ on\ moving\ pieces.***\n======\n\ \ \ \ #start\ of\ deck\n\ \ \ \ \ \ \ \ #start\ of\ deck\n\ \ \ \ \ \ \ \ #start\ of\ deck\ \n\ \ \ #!/bin/sh\n\n\ \ \ #!/bin/sh\n\ #\ Restart\ with\ tcl:\ -*-\ mode:\ tcl\;\ tab-width:\ 4\;\ -*-\ \\\n\ exec\ wish\ \$0\ \$\{1+\"\$@\"\}\n\n\ #\ demo2-canvas.tcl\ -\ HaJo\ Gurt\ -\ 2005-12-13\ -\ http://wiki.tcl.tk/15073\n\ #:\ CanvasDemo:\ On\ button-click,\ draw\ something\ on\ the\ canvas\n\ #\ gold\ used\ canvas\ demo\ as\ base\ for\ TCL\ \ chess\ display\ board.\n\ \n\n\ \ \ \ \ \ \ \ proc\ scr\ \{w\}\ \{\n\ \ \ \ \ \ \ \ console\ show\n\ \ \ \ \ \ \ \ set\ \ max\ 400\n\ \ \ \ \ \ \ \ set\ \ may\ 400\ \n\ for\ \{set\ r\ 50\}\ \{\$r\ <\ \$max\}\ \{incr\ r\ 45\}\ \{\n\ \ \ \ \ for\ \{set\ c\ 50\}\ \{\$c\ <\ \$max\}\ \{incr\ c\ 45\}\ \{\n\ \ \ \ \ \ \ \ set\ tilename\ \ \[expr\ \{int(rand()*1000000000.)\}\]\n\ \ \n\ \ \ \ \ \ \ \ \ \$w\ create\ oval\ \$r\ \$c\ \[expr\ \$r+5\]\ \[expr\ \$c+5\]\ -outline\ gray\ -fill\ green\ -width\ 1\ \\\n\ \ \ \ \ \ \ \ \ -tags\ \[concat\ mv\ xdat_\[expr\ \$r+5\]\ \ ydat_\[expr\ \$c+5\]\ obj_\$tilename\]\n\ \ \ \ \ \ \ \ \ \ \ puts\ \"\ xdat_\[expr\ \$r+5\]\ \ ydat_\[expr\ \$c+5\]\ obj_\$tilename\"\n\ \ \ \ \ \ \ \ set\ texter\ \ \"\ \ \[expr\ \$r+5\]\ \[expr\ \$c+5\]\ \ \"\n\ \ \ \ \ \ \ \$w\ create\ text\ \[expr\ \$r+5\]\ \[expr\ \$c+20\]\ \\\n\ \ \ \ \ \ \ \ \ \ -text\ \$texter\ -fill\ green\ -tags\ \"\ \ \[expr\ \$r+5\]\ \[expr\ \$c+20\]\"\n\n\ \}\}\}\n\ \n\ \ \ package\ require\ Tk\n\n\ \ proc\ ClrCanvas\ \{w\}\ \{\n\ \ \ \ \$w\ delete\ \"all\"\n\ \ \ \ \$w\ configure\ \ -bg\ white\n\ \ \}\n\n\ \ proc\ DrawAxis\ \{w\}\ \{\n\ \ \ \ set\ midX\ \[expr\ \{\ \$::maxX\ /\ 2\ \}\]\n\ \ \ \ set\ midY\ \[expr\ \{\ \$::maxY\ /\ 2\ \}\]\n\ \ \ \ \$w\ create\ line\ 0\ \ \ \ \ \$midY\ \ \$::maxX\ \ \ \$midY\ \ -tags\ \"axis\"\n\ \ \ \ \$w\ create\ line\ \$midX\ 0\ \ \ \ \ \ \ \ \$midX\ \$::maxY\ \ -tags\ \"axis\"\n\ \ \}\n\n\ \ proc\ PaintText\ \{w\ Txt\}\ \{\n\ \ \ \ global\ y\n\ \ \ \ incr\ y\ 10\n\ \ \ \ \$w\ create\ text\ 100\ \$y\ -text\ \$Txt\ -tags\ \"text\"\n\ \ \}\n\n\ \ proc\ DrawBox\ \{w\}\ \{\n\ \ \ \ global\ x1\ y1\ x2\ y2\n\ \ \ \ \$w\ create\ rect\ \ 50\ \ 50\ \ 100\ \ 90\ \ -tags\ \"box\"\n\ \ \ \ \$w\ create\ rect\ \$x1\ \$y1\ \ \$x2\ \$y2\ \ -tags\ \"box\"\n\ \ \ \ incr\ x1\ 15\n\ \ \ \ incr\ x2\ 15\n\ \ \ \ incr\ y1\ 10\n\ \ \ \ incr\ y2\ 10\n\ \ \}\n\n\ \ proc\ DrawFn1\ \{w\}\ \{\n\ \ \ \ \$w\ create\ line\ 0\ 100\ \ 50\ 200\ \ 100\ 50\ \ 150\ 70\ \ 200\ 155\ \ 250\ 50\ \ 300\ 111\ \ 350\ 222\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ -tags\ \"Fn1\"\ \ -smooth\ bezier\n\ \ \}\n\n\ \ proc\ DrawFn2\ \{w\}\ \{\n\ \ \ \ set\ offY\ 0\ \ \ \ \;#\ \[expr\ \{\ \$::maxY\ /\ 2\ \}\]\n\n\ \ \ \ for\ \{\ set\ x\ 0\ \}\ \{\ \$x\ <=\ \$::maxX\ \}\ \{\ incr\ x\ 5\ \}\ \{\n\ \ \ \ \ \ set\ y\ \[expr\ \{\ rand()\ *\ \$::maxY\ +\ \$offY\ \}\]\n\n\ \ \ \ \ #puts\ \"\$x\ \$y\"\n\ \ \ \ \ \ if\ \{\$x>0\}\ \{\ \$w\ create\ line\ \$x0\ \$y0\ \$x\ \$y\ -tags\ \"Fn2\"\ \}\n\ \ \ \ \ \ set\ x0\ \$x\n\ \ \ \ \ \ set\ y0\ \$y\n\ \ \ \ \}\n\ \ \}\n\n\ \ #:\ Main\ :\n\ \ frame\ .f1\n\ \ frame\ .f2\n\ \ pack\ \ .f1\ .f2\n\n\ \ set\ maxX\ 400\n\ \ set\ maxY\ 400\n\ \ set\ y\ \ \ \ \ \ 0\n\n\ \ set\ x1\ 120\n\ \ set\ x2\ 150\n\ \ set\ y1\ \ 50\n\ \ set\ y2\ \ 80\n\n\ \ canvas\ \ .cv\ -width\ \$maxX\ -height\ \$maxY\ \ -bg\ tan\n\ \ pack\ \ \ \ .cv\ -in\ .f1\n\ \ button\ \ .a0\ -text\ \"xiangqi\"\ -command\ \{set\ state2\ 1\;set\ state3\ 1\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 1\ \ \ \}\n\ \ button\ \ .a1\ -text\ \"west*\"\ -command\ \{unset\ state3\;set\ state3\ 3\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 3\ \ \ \}\n\ \ button\ \ .a2\ -text\ \"@\"\ -command\ \{unset\ state3\;set\ state3\ 3\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 2\ \ \ \}\n\ \ button\ \ .a3\ -text\ \"&\"\ -command\ \{\ \ ClrCanvas\ .cv\;scr\ .cv\ \ \ \}\n\ \ button\ \ .b0\ -text\ \"C\"\ -command\ \{\ ClrCanvas\ .cv\ \}\n\ \ button\ \ .b1\ -text\ \"Text\"\ \ -command\ \{\ PaintText\ .cv\ \"Chinese\ Xiangqi\ Chess\"\ \}\n\ \ button\ \ .b2\ -text\ \"+\"\ \ -command\ \{\ DrawAxis\ \ .cv\ \}\n\ \ button\ \ .b3\ -text\ \"\\\[\\\]\"\ \ \ -command\ \{\ DrawBox\ \ \ .cv\ \}\n\ \n\ \ button\ \ .b6\ -text\ \"#dn\"\ \ \ -command\ \{\ refreshgrid\ .cv\ 2\ \}\ \ \ \n\n\ \ button\ \ .b7\ -text\ \"#up\"\ \ \ -command\ \{\ refreshgrid\ .cv\ 1\ \}\ \n\ \ button\ \ .b8\ -text\ \"#^\"\ \ \ -command\ \{.cv\ scale\ all\ 0\ 0\ 1.1\ 1.1\ \}\n\ \ button\ \ .b9\ -text\ \"#<\"\ \ \ -command\ \{.cv\ scale\ all\ 0\ 0\ .9\ .9\ \}\ \ \n\ \ button\ \ .b10\ -text\ \"x\"\ \ \ -command\ \{\ exit\ \ \ \ \}\n\ \ \ set\ info\ \"000\ 000\"\n\ \ \ label\ \ .info\ -textvar\ info\ -just\ left\n\ \ pack\ .a0\ .a1\ .a2\ .a3\ .b0\ .b1\ .b2\ .b3\ \ .b6\ .b7\ .b8\ .b9\ .b10\ .info\ -in\ .f2\ \ -side\ left\ -padx\ 2\n\n\ \ \ #catch\ \{console\ show\}\n\ \ \ set\ oscwidth\ 1000\ \n\ set\ oschorizontal\ 500\ \n\ proc\ loop\ \{from\ to\ body\}\ \{\n\ \ \ \ upvar\ 1\ i\ i\ \;#\ make\ index\ visible\ in\ body\n\ \ \ \ for\ \{set\ i\ \$from\}\ \{\$i<\$to\}\ \{incr\ i\}\ \{uplevel\ 1\ \$body\}\n\ \}\n\ \ \ #--\ And\ likewise,\ a\ shortcut\ for\ addition:\n\ proc\ +\ \{a\ b\}\ \{expr\ \{\$a+\$b\}\}\n\ \n\ #pack\ \[canvas\ .cv\ -width\ 400\ -height\ 500\ \]\n\n\ \ \ \ #\ focus\ .cv\ \n\ set\ state2\ 1\n\ proc\ refreshgrid\ \{\ .cv\ state2\}\ \{\n\ global\ oscwidth\ oschorizontal\ colorite\n\ global\ grid\n\ \ global\ ind\ indx\n\ \ set\ ind\ 0\n\ \ set\ indx\ 0\n\ \ \ \ set\ colorite\ blue\ \n\ \ \ \ for\ \{set\ x\ 10\}\ \{\$x<\$oscwidth\}\ \{incr\ x\ 50\}\ \{.cv\ create\ line\ \$x\ 0\ \$x\ \$oschorizontal\ \ -fill\ blue\ -tag\ grid\ -\n\nwidth\ 4\}\n\ for\ \{set\ y\ 20\}\ \{\$y<\$oschorizontal\}\ \{incr\ y\ 50\}\ \{.cv\ create\ line\ 0\ \$y\ \$oschorizontal\ \$y\ -fill\ blue\ \ -tag\ grid\ \n\n-width\ 4\}\ \n\ .cv\ itemconfigure\ grid\ -fill\ blue\ \n\n\ if\ \{\ \$state2\ ==\ 1\ \}\ \{\ .cv\ raise\ grid\ \;\}\ \n\ if\ \{\ \$state2\ ==\ 2\ \}\ \{\ .cv\ lower\ grid\ \;\}\ \n\ \}\n\n\ \ refreshgrid\ \ .cv\ \$state2\ \n\ #\ next\ lines\ start\ withn\ periods,\ but\ hard\ to\ see\n\ .\ configure\ -borderwidth\ 0\ -highlightthickness\ 0\ -takefocus\ 0\ -background\ aquamarine4\n\ .\ configure\ -background\ palegreen\ -highlightcolor\ DarkOliveGreen\ -relief\ raised\ -border\ 30\n\n\ .\ configure\ -background\ palegreen\ -highlightcolor\ DarkOliveGreen\ -relief\ raised\ -border\ 30\n\ .\ configure\ -width\ 1000\ -height\ 2000\n\n\ \ \ \ \ .cv\ bind\ mv\ <ButtonRelease-1>\ \{set\ info\ \"\ %x\ %y\ \"\;\n\ \ \ \ \ \ \ \ catch\ \{.cv\ itemconfigure\ \[lindex\ \$id\ 0\]\ -outline\ black\ -width\ 1\ \}\n\ \ \ \ \}\n\n\ \ .cv\ bind\ all\ <1>\ \{set\ p(X)\ \[.cv\ canvasx\ %x\]\;\ set\ p(Y)\ \[.cv\ canvasy\ %y\]\;set\ info\ \"\ %x\ %y\ \"\}\n\ set\ haloo\ 50\n\ .cv\ bind\ mv\ <B1-Motion>\ \{mv\ .cv\ %x\ %y\}\n\ #.cv\ bind\ mv\ <ButtonRelease-1>\ \{set\ info\ \"\ %x\ %y\ \"\;puts\ \"\ nearest\ \[.cv\ find\ closest\ \ %x\ %y\ \$haloo\ \]\"\}\n\ #.cv\ bind\ moveable\ <ButtonPress-1>\ \{item:move\ %W\ %x\ %y\ 1\;set\ info\ \"\ %x\ %y\ \"\}\n\ \ \ \ \ \ bind\ .cv\ <Motion>\ \{wm\ title\ .\ \"Xiangqi\ Chessboard\ \[expr\ int(\ \[%W\ canvasx\ %x\])\],\[expr\ int\ (\[%W\ canvasy\ \n\n%y\])\]\"\}\n\n\ \ \ \ \ proc\ mv\ \{w\ x\ y\}\ \{\n\ \ \ \ global\ p\ id\n\ \ \ \ set\ x\ \ \[\$w\ canvasx\ \$x\]\n\ \ \ \ set\ y\ \ \[\$w\ canvasy\ \$y\]\n\ \ \ \ set\ id\ \[\$w\ find\ withtag\ current\]\n\ \ \ \ set\ numberx\ \[\$w\ \ gettags\ current\]\n\ \ \ \ regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ \n\ \ \ \ puts\ \"1\"\n\ \ \ \ puts\ \$numberx\n\ \ \ \ puts\ \$tilex\n\ \ \ \ puts\ \"\ with\ tag\ \[\$w\ find\ withtag\ obj_\$tilex\ \]\"\n\ \ \ \ foreach\ item\ \[\$w\ find\ withtag\ obj_\$tilex\ \]\ \{\n\ \ \ \ \$w\ move\ \$item\ \[expr\ \{\$x-\$p(X)\}\]\ \[expr\ \{\$y-\$p(Y)\}\]\n\ \ \ \ catch\ \{\$w\ itemconfigure\ \[lindex\ \$id\ 0\]\ -outline\ purple\ -width\ 5\ \}\n\ \ \ \ #\$w\ raise\ \$id\n\ \ \ \ \}\n\ \ \ \ puts\ \"\ x\ y\ \$x\ \$y\"\n\ \ \ \ #\$w\ raise\ \$id\n\ \ \ \ #\ \$w\ move\ \[\$w\ find\ withtag\ \"\$tilex\"\]\ \[expr\ \{\$x-\$p(X)\}\]\ \[expr\ \{\$y-\$p(Y)\}\]\n\ \ \ \ #set\ numberx\ \[\$w\ \ gettags\ current\]\n\ \ \ \ #regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ \ catch\ \{\$w\ itemconfigure\ \[lindex\ \$id\ 0\]\ -outline\ purple\ -width\ 5\ \}\n\ \ \ \ set\ p(X)\ \$x\;\ set\ p(Y)\ \$y\n\ \}\n\n\ \ \ \ proc\ board\ \{w\}\ \{\n\ \ \ \ #set\ state3\ 1\n\ \ \ \ set\ state2\ 1\n\ \ \ \ ClrCanvas\ \$w\n\ \ \ \ .\ configure\ -background\ orange\ -highlightcolor\ brown\ -relief\ raised\ -border\ 30\n\ \ \ \ \$w\ configure\ -bg\ tan\n\ \ \ \ \n\ \ \ \ refreshgrid\ \ .cv\ \$state2\ \;\n\ \ \ \ \}\n\ \ \ \ \n\ \ \ \ \ proc\ squarenames\ \{l\}\ \{\n\ \ \ \ console\ show\n\ \ \ \ set\ result\ \{\}\n\ \ \ \ set\ i\ \[llength\ \$l\]\n\ \ \ \ \ \ \ \ set\ cc\ 0\n\ \ \ \ \ \ \ \ set\ rr\ 0\n\ \ \ \ \ \ \ \ foreach\ row\ \{8\ 7\ 6\ 5\ 4\ 3\ 2\ 1\}\ \{\n\ \ \ \ \ \ \ \ set\ rowscreen\ \[expr\ \{\$rr*50.\}\]\n\ \ \ \ \ \ \ \ foreach\ column\ \{A\ B\ C\ D\ E\ F\ G\ H\}\ \{\n\ \ \ \ \ \ \ \ set\ colscreen\ \ \[expr\ \{\$cc*50.\}\]\ \ \ \n\ \ \ \ \ \ \ \ lappend\ result\ \ \ \"\$column\$row\ \$rowscreen\ \$colscreen\"\n\ \ \ \ \ \ \ \ incr\ cc\ 1\n\ \ \ \ \ \ \ \ incr\ rr\ 1\n\ \ \ \ \ \ \ \ \ \}\}\n\ \ \ \ puts\ \$result\n\ \ \ \ return\ \$result\n\ \ \ \ \n\ \ \ \}\n\ \ \ \ \ \ \n\ \ \ \ \ \ \ \ #foreach\ row\ \{8\ 7\ 6\ 5\ 4\ 3\ 2\ 1\}\ \{\n\ \ \ \ \ \ \ \ #foreach\ column\ \{A\ B\ C\ D\ E\ F\ G\ H\}\ \{\n\ \ \ \ \ \ \ \ #\ \ \ \ lappend\ res\ \[\"\ \"\ \"\$column\$row\"\]\n\ \ \ \ \ \ \ \ #puts\ \"\ \ \$column\$row\ \"\n\ \ \ \ \ \ \ \n\ \ \ \ proc\ gamepieces\ \{state3\}\ \{\n\ \ \ \ \ global\ bluepieces\ redpieces\n\ \ \ \ \ if\ \{\ \$state3\ ==\ 2\ \}\ \{\ \n\ \ \ \ \ set\ bluepieces\ \[list\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]\n\ \ \ \ \ set\ redpieces\ \ \[list\ 0\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]\n\ \ \ \ \ \ \ \}\ \n\ \ \ \ \ \n\ \ \ \ if\ \{\ \$state3\ ==\ 3\ \}\ \{\ \n\ \ \ \ \ #black\ western\n\ \ \ \ \ set\ bluepieces\ \{\ \ \\u265A\ \\u265B\ \\u265C\ \\u265C\ \\u265D\ \\u265D\ \\u265E\ \\u265E\ \\u265F\ \\u265F\ \\u265F\ \\u265F\ \n\n\\u265F\ \\u265F\ \\u265F\ \\u265F\}\ \ \n\ \ \ \ \ #white\ western\n\ \ \ \ \ set\ redpieces\ \{\ 0\ \ \\u2654\ \\u2655\ \\u2655\ \\u2656\ \ \\u2656\ \\u2657\ \\u2657\ \ \\u2658\ \\u2658\ \\u2659\ \\u2659\ \\u2659\ \n\n\ \\u2659\ \\u2659\ \\u2659\ \\u2659\ \\u2659\}\ \ \n\ \ \ \ \ \ \ \}\n\ \ \ \ \ \ if\ \{\ \$state3\ ==\ 1\ \}\ \{\ \n\ \ \ \ \ \ set\ bluepieces\ \{\\u5C07\ \\u58EB\ \ \\u58EB\ \ \\u8C61\ \\u8C61\ \\u99AC\ \\u99AC\ \\u8ECA\ \\u8ECA\ \ \ \\u7832\ \ \ \\u7832\ \ \ \ \n\n\\u5352\ \\u5352\ \\u5352\ \ \ \\u5352\ \\u5352\}\n\ set\ redpieces\ \ \{\ \ 0\ \\u5E25\ \ \ \\u4ED5\ \\u4ED5\ \ \ \\u76F8\ \ \ \\u76F8\ \\u99AC\ \\u99AC\ \\u8ECA\ \\u8ECA\ \ \ \ \ \ \\u70AE\ \ \\u70AE\ \n\n\ \\u5175\ \ \\u5175\ \ \ \ \\u5175\ \ \ \ \ \\u5175\ \ \ \\u5175\ \ \}\ \ \n\ \ \ \ \ \}\n\ \n\ \ \ \ \ \}\n\ \ \ \ \n\ \ \ \ \ set\ ind\ 0\n\ \ \ \ \ set\ indx\ 0\n\ \ \ \ \ set\ baseline\ \{list\ 1\}\n\ \ \ \ \ \ proc\ K\ \{\ x\ y\ \}\ \{\ set\ x\ \}\n\n\ \ \ \ \ proc\ xpop\ \{\ topper\ \}\ \{\n\ \ \ \ \ global\ liner\ \n\ \ \ \ \ global\ ind\ indx\ \n\ \ \ \ \ global\ bluepieces\ redpieces\n\ \ \ \ \ global\ baseline\n\ \ \ \ \ set\ topper\ \[\ lindex\ \$bluepieces\ \$ind\ \]\;\n\ \ \ \ \ if\ \{\ \$topper\ ==\ \"\"\ \}\ \{\ \n\ \ \ \ \ set\ topper\ \[\ lindex\ \$redpieces\ \$indx\ \]\n\ \ \ \ \ set\ indx\ \[\ expr\ \{\ \$indx\ +\ 1\}\]\n\ \ \ \ \ \ \ \}\ \n\ \ \ \ \ set\ ind\ \[\ expr\ \{\ \$ind\ +\ 1\}\]\n\ \ \ \ \ lappend\ \$baseline\ \$topper\;\n\ \ \ \ \ return\ \$topper\;\n\ \ \ \ \ \}\n\ \ \ \ \ set\ state2\ 1\n\ \ \ \ \ \ \ \ \ \ proc\ populateCanvas\ \{w\ cols\ rows\ args\}\ \{\n\ \ \ \ global\ state2\ state3\n\ \ \ \ gamepieces\ \$args\n\ \ \ \ #refreshgrid\ \ \$w\ \$state2\ \n\ \ \ \ set\ state3\ \$args\n\ \ \ \ global\ ind\ indx\n\ \ \ \ variable\ ids\ \;#\ links\ text\ ids\ with\ respective\ rect\ ids\n\ \ \ \ variable\ boxes\ \;#\ lists\ text\ id\ and\ text\ associated\ with\ each\ rect\ id\n\ \ \ \ catch\ \{unset\ ids\ boxes\}\n\ \ \ \ set\ canvas\ \$w\n\ \ \ \ \n\ \ \ \ #\ parameters\ for\ drawing\ boxes\n\ \ \ \ set\ boxwidth\ 50\n\ \ \ \ set\ boxheight\ 50\n\ \ \ \ set\ padx\ 3\n\ \ \ \ set\ pady\ 3\n\ \ \ \ set\ colors\ \{\ orange\ yellow\ green\ \ gray\}\n\ \ \ \ set\ labels\ \{one\ two\ three\ four\}\n\n\ \ \ \ #\ draw\ the\ boxes\n\ \ \ \ for\ \{set\ row\ 0\}\ \{\$row\ <\ \$rows\}\ \{incr\ row\}\ \{\n\ \ \ \ \ \ for\ \{set\ col\ 0\}\ \{\$col\ <\ \$cols\}\ \{incr\ col\}\ \{\n\n\ \ \ \ \ \ \ \ #\ calculate\ coordinates\n\ \ \ \ \ \ \ \ set\ x1\ \[expr\ \{\$col\ *\ (\$boxwidth\ +\ \$padx)\ +\ \$padx\}\]\n\ \ \ \ \ \ \ \ set\ x2\ \[expr\ \{\$x1\ +\ \$boxwidth\}\]\n\ \ \ \ \ \ \ \ set\ x3\ \[expr\ \{\$x1\ +\ (\$boxwidth\ /\ 2)\}\]\n\ \ \ \ \ \ \ \ set\ y1\ \[expr\ \{\$row\ *\ (\$boxheight\ +\ \$pady)\ +\ \$pady\}\]\n\ \ \ \ \ \ \ \ set\ y2\ \[expr\ \{\$y1\ +\ \$boxheight\}\]\n\ \ \ \ \ \ \ \ set\ y3\ \[expr\ \{\$y1\ +\ (\$boxheight\ /\ 2)\}\]\n\n\ \ \ \ \ \ \ \ #\ choose\ color\ and\ text\n\ \ \ \ \ \ \ \ set\ color\ \[lindex\ \$colors\ \[expr\ \{int(rand()\ *\ \[llength\ \$colors\])\}\]\]\n\ \ \ \ \ \ \ \ #set\ text\ \[lindex\ \$labels\ \[expr\ \{int(rand()\ *\ \[llength\ \$labels\])\}\]\]\n\ \ \ \ \ \ \ \ #\ set\ text\ \[xpop\ topper\]\n\ \ \ \ \ \ \ \ \ set\ font2\ \[list\ Helvetica\ \[expr\ \$boxwidth/2\]\]\n\n\ \ \ \ \ \ \ \ \ set\ text\ \"0\"\n\ \ \ \ \ \ \ \ \ #set\ text\ \"K\"\n\ \ \ \ \ \ \ \ \ set\ texter\ \[xpop\ 1\ \]\n\ \ \ \ \ \ \ \ \ set\ tilename\ \ \[expr\ \{int(rand()*1000000000.)\}\]\n\ \ \ \ \ \ \ \ #\ create\ the\ boxes\n\ \ \ \ \ \ \ \ set\ boxid\ \[\$w\ create\ oval\ \$x1\ \$y1\ \$x2\ \$y2\ \\\n\ \ \ \ \ \ \ \ \ \ -fill\ \$color\ -tags\ \[concat\ mv\ rect\ \$args\ \ obj_\$tilename\]\\\n\ \ \ \ \ \ \ \ \ \ -outline\ black\]\n\ \ \ \ \ \ \ \ set\ colorfo\ blue\n\ \ \ \ \ \ \ \ if\ \{\ \$indx\ >\ 1\ \}\ \{set\ colorfo\ red\}\n\ \ \ \ \ \ \ \ #set\ textid\ \[\$w\ create\ text\ \$x3\ \$y3\ -font\ \$font2\ -fill\ \$colorfo\ \\\n\ \ \ \ \ \ \ \ #\ \ -text\ \$text\ -tags\ \[concat\ mv\ \ \$args\ \ obj_\$tilename\]\ \ \]\n\n\ \ \ \ \ \ \ \ \ set\ textid\ \[\$w\ create\ text\ \$x3\ \$y3\ -font\ \$font2\ -fill\ \$colorfo\ \\\n\ \ \ \ \ \ \ \ \ \ -text\ \$texter\ -tags\ \[concat\ mv\ \ \$args\ \ obj_\$tilename\ \]\ \ \]\n\n\ \ \ \ \ \ \ \ #\ remember\ which\ text\ item\ goes\ with\ which\ box\ and\ what\ the\ text\ says\n\ \ \ \ \ \ \ \ set\ boxes(\$boxid)\ \[list\ \$textid\ \$text\]\n\ \ \ \ \ \ \ \ set\ ids(\$textid)\ \$boxid\n\ \ \ \ \ \ \ \ set\ ids(\$boxid)\ \$boxid\n\ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \}\ \ \n\ \ \ \ \ populateCanvas\ .cv\ 6\ 6\ 1\ \n\ \ \ \ \ squarenames\ \{1\ 2\ 3\ \}\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck***gummy\ version\ with\ \ purple\ highlights\ on\ moving\ pieces.***\n\ \ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n======\n\n<<categories>>\ Toys\ |\ Example\ |\ Games\ |\ Characters regexp2} CALL {my render {Chinese Xiangqi Chessboard} **Chinese\ Xianqi\ Chessboard**\n\n----\ \ \ \nThis\ page\ is\ under\ development.\ Comments\ are\ welcome,\ but\ please\ load\ any\ comments\ in\ the\ comments\ section\ at\ the\ middle\ of\ the\ page.\ Thanks,\ \[gold\]\n\n----\nHere\ is\ some\ starter\ code\ for\ Chinese\ Xiangqi\ Chessboard.\ There\ are\ several\ avenues\ for\ a\ Xianqi\ chessboard.\ Literature\ search\ showed\ many\ chess\ programs\ relying\ on\ a\ gif\ of\ the\ Chinese\ chessboard.\ Primarily\ looking\ at\ \[RS\]'s\ checkers.tcl\ on\ the\ wiki\ to\ get\ some\ primary\ movable\ pieces\ with\ the\ board.\ \ An\ \ version\ of\ the\ code\ was\ installed\ \ in\ the\ Simple\ Canvas\ Demo\ for\ some\ pictures.\ Also,\ \ TCLpaint\ \ made\ a\ lengthy\ list\ of\ 60\ line\ creations\ in\ TCLpaint,but\ the\ final\ code\ should\ rely\ on\ foreach\ or\ loop\ statements\ for\ compact\ code.\ \n\ \n----\ \nThe\ characters\ are\ generally\ stamped\ red\ and\ blue\ on\ round\ wooden\ pieces,\ which\ might\ be\ unicode\ characters\ in\ chinese.\ Given\ the\ purpose\ to\ display\ an\ Xiangqi\ board,\ a\ wish\ list\ is\ dreamed\ up.\ Probably\ need\ an\ if\ switch\ option\ for\ TCL\ lists\ of\ different\ character\ sets.\ \ Both\ the\ oval\ and\ the\ text\ character\ are\ taqgged\ with\ a\ random\ object\ name\ like\ obj_\$tiilename.\ On\ selection\ of\ a\ chess\ piece,\ the\ code\ finds\ the\ common\ name\ tag\ of\ the\ oval\ and\ text\ piece,\ and\ moves\ both\ at\ the\ same\ time.\ Probably\ should\ add\ a\ color\ outline\ during\ selection\ and\ movement\ with\ the\ mouse.\ Also\ should\ be\ able\ to\ center\ or\ pin\ the\ game\ pieces\ at\ the\ cross\ points.\ Probably\ could\ use\ an\ exit\ button.\n----\nUsing\ the\ Simple\ Canvas\ Demo\ framework,\ the\ code\ has\ installed\ buttons\ for\ switching\ to\ traditional\ Chinese\ pieces,\ Western\ pieces,\ and\ alphabetic\ characters.\ Probably\ the\ buttons\ could\ select\ a\ color\ scheme.\ Xiangqi\ usually\ uses\ a\ gridded\ board.\ Western\ chess\ uses\ brown\ and\ white\ squares.\ Using\ the\ random\ names\ for\ the\ objects\ to\ lock\ ovals\ and\ text\ together.\ This\ works,\ but\ additional\ operations\ on\ the\ gamepieces\ like\ the\ moving\ outline\ are\ gumming\ up.\ Also\ the\ code\ is\ outputing\ the\ mouse\ up\ and\ down\ coordinates\ for\ the\ screen.\n\ \ \ \ \ \n----\nWith\ the\ buttons\ in\ the\ little\ canvas\ demo,\ one\ can\ call\ up\ separate\ routines\ to\ lay\ out\ the\ different\ boards\ and\ install\ the\ various\ options\ of\ chesspieces.\ \ In\ a\ teamwork\ situation,\ programming\ teams\ could\ divide\ up\ the\ several\ tasks\ with\ the\ framework.\ In\ many\ cases,\ it\ is\ advantageous\ to\ have\ or\ write\ little\ demo\ programs\ for\ the\ separate\ subroutines.\ Some\ of\ the\ demo\ code\ decks\ are\ included\ below.\ In\ the\ button\ call\ up\ of\ the\ canvas\ demo,\ separate\ tasks\ can\ laid\ in\ successive\ statements\ to\ clear\ board,\ set\ states,\ layout\ the\ board,\ and\ populate\ the\ chesspieces.\ Loading\ four\ statements\ in\ the\ button\ \ might\ be\ ClrCanvas\ .cv\;\ set\ state3\ 3\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 3\;\ This\ gets\ a\ little\ lengthy\ for\ a\ button\ line,\ so\ these\ statements\ could\ be\ stacked\ in\ a\ separate\ subroutine.\ With\ some\ global\ statements\ for\ any\ constants\ and\ passing\ the\ canvas\ name\ as\ \$w,\ the\ \ subroutine\ could\ be\ written\ like\ \n======\n\ \ proc\ stackedlist\ \{w\}\ \{\n\ \ \ \ global\ state3\n\ \ \ \ ClrCanvas\ \$w\n\ \ \ \ set\ state3\ 3\n\ \ \ \ board\ \$w\n\ \ \ \ populateCanvas\ \$w\ 6\ 6\ 3\n\ \ \}\n======\n\n----\n**Screenshots\ Section**\n\n\[http://farm5.static.flickr.com/4136/4743183050_a37afc987d.jpg\]\n\[http://farm5.static.flickr.com/4096/4743212494_7b08112447.jpg\]\n\[http://farm5.static.flickr.com/4101/4746939385_e67ce71783.jpg\]\n\[http://farm5.static.flickr.com/4076/4747597490_52d5db2c15.jpg\]\n\n----\n**Comments\ Section**\nPlease\ place\ any\ comments\ here,\ Thanks.\n\n\[gold\]\ Changes.\n\n\[AMG\]:\ I\ suggest\ using\ a\ \[for\]\ loop\ to\ make\ \[\[chessboard\]\]\ more\ concise.\n\n\[gold\]\ Is\ there\ some\ way\ to\ multiply\ all\ numbers\ in\ a\ create\ statement,\ leaving\ the\nalpha\ characters\ unchanged?\ Perl\ can\ do\ this.\nI\ tried\ but\ kept\ bombing,\ and\ wound\ up\ with\ this\ code.\n\n======\n\ set\ bee1\ \[\ list\ .c\ create\ poly\ \ -8\ 10\ \ -8\ 7\ \ -5\ 7\ \ -2\ -1\ \ -4\ -5\ \ -2\ -10\ \ 2\ -10\ \ 4\ -5\ \ 2\ -1\ \ 5\ 7\ \ 8\ 7\ \ 8\ 10\ \]\n\ \ \ \ \ \ set\ bee2\ \[\ list\ \ \ \ -8\ 10\ \ -8\ 7\ \ -5\ 7\ \ -2\ -1\ \ -4\ -5\ \ -2\ -10\ \ 2\ -10\ \ 4\ -5\ \ 2\ -1\ \ 5\ 7\ \ 8\ 7\ \ 8\ 10\ \]\n\ \ \ \ set\ check\ \"1\"\n\ \ \ \ \ foreach\ factor\ \[list\ \ 10\ 12\ 14\ 16\ 18\ 20\]\ \{\n\ \ \ \ \ set\ cat\ \[list\ \ \]\n\ \ \ \ \ foreach\ item\ \$bee1\ \{\n\ \ \ \ \ \ if\ \{\ \[catch\ \{expr\ \{1\ *\ \$item\}\}\]\ >>\ 0\}\ \{lappend\ cat\ \ \$item\ \}\n\n\ \ \ \ \ \ if\ \{\ \[catch\ \{expr\ \{1\ *\ \$item\}\}\]\ ==\ 0\ \}\ \{lappend\ cat\ \[\ expr\ 200*\$factor*.1\ +\ \$item\ *\ log(\$factor)\ \ \]\}\n\ \ \ \ \ \ \ \}\n\ \ \ \ \ \n\ \ \ \ \ \ eval\ \$cat\ -outline\ gray\ \ -fill\ \[lpick\ \$randomcolor\ \]\ \n\ \ \ \ \ \ \ \}\n======\n\n\[AMG\]:\ Yes,\ but\ it's\ very\ complex.\ \ You'd\ have\ to\ use\ \[\[\[regexp\]\ -indices\ -all\ \{\\d+\}\ \$string\]\]\ to\ find\ the\ start\ and\ end\ indices\ corresponding\ to\ the\ numbers,\ then\ you'd\ extract\ each\ number,\ multiply\ it,\ and\ replace\ it\ back\ into\ the\ string\ using\ \[\[\[string\ replace\]\]\].\ \ I\ don't\ recommend\ this\ approach,\ especially\ since\ it's\ liable\ to\ modify\ numbers\ you\ didn't\ intend\ to\ modify.\ \ Also,\ that\ regular\ expression\ I\ gave\ only\ works\ for\ integers\;\ detecting\ floating\ point\ numbers\ is\ even\ harder.\n\nWhat\ you\ need\ to\ do\ is\ have\ each\ creation\ parameter\ be\ a\ function\ of\ your\ \[for\]\ loop\ iterators.\ \ You\ say\ you\ have\ a\ \[Fortran\]\ background\;\ this\ concept\ should\ be\ familiar\ to\ you,\ except\ that\ Fortran\ says\ \"DO\"\ instead\ of\ \"for\".\ :^)\ \ More\ seriously,\ Tcl\ for\ loops\ are\ weird\ (in\ the\ same\ way\ that\ \[C\]\ for\ loops\ are\ weird).\ \ They\ take\ four\ arguments:\n\n\ \ \ 1.\ Initialization\ script.\ \ This\ is\ executed\ before\ the\ loop\ begins.\ \ It's\ normally\ used\ to\ create\ the\ iteration\ variable.\n\ \ \ 1.\ Termination\ test.\ \ This\ expression\ is\ tested\ before\ each\ iteration,\ and\ if\ it's\ false,\ the\ loop\ stops.\n\ \ \ 1.\ Advancement\ script.\ \ This\ is\ executed\ after\ each\ iteration\ of\ the\ loop.\ \ It's\ normally\ used\ to\ increment\ the\ iteration\ variable.\n\ \ \ 1.\ Iteration\ body\ script.\ \ This\ is\ executed\ each\ time\ the\ loop\ iterates,\ just\ before\ the\ advancement\ script.\ \ Your\ main\ code\ goes\ here.\n\nHere's\ code\ to\ make\ a\ grid\ similar\ to\ the\ one\ your\ program\ creates.\ \ It\ shows\ both\ for\ and\ \[foreach\].\ \ To\ be\ honest,\ foreach\ is\ simpler\ than\ for\ when\ there\ are\ a\ very\ small\ number\ of\ iterations.\ \ Here,\ replace\ the\ first\ for\ with\ \"`foreach\ i\ \{1\ 2\ 3\ 4\ 5\ 6\ 7\}\ \{...\}`\"\ and\ the\ second\ for\ with\ \"`foreach\ i\ \{0\ 1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 9\}\ \{...\}`\".\n\n======\nset\ dx\ 20\ \ \ \ \;#\ pixels\ between\ adjacent\ vertical\ grid\ lines\nset\ dy\ 20\ \ \ \ \;#\ pixels\ between\ adjacent\ horizontal\ grid\ lines\nset\ x0\ 30\ \ \ \ \;#\ pixels\ between\ left\ of\ canvas\ and\ left\ of\ grid\nset\ y0\ 30\ \ \ \ \;#\ pixels\ between\ top\ of\ canvas\ and\ top\ of\ grid\nset\ win\ .c\ \ \ \;#\ name\ of\ canvas\ widget\nforeach\ i\ \{0\ 8\}\ \{\n\ \ \ \ \$win\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \$y0\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{9\ *\ \$dy\ +\ \$y0\}\]\n\}\nfor\ \{set\ i\ 1\}\ \{\$i\ <\ 8\}\ \{incr\ i\}\ \{\n\ \ \ \ \$win\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \$y0\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{4\ *\ \$dy\ +\ \$y0\}\]\n\ \ \ \ \$win\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{5\ *\ \$dy\ +\ \$y0\}\]\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{9\ *\ \$dy\ +\ \$y0\}\]\n\}\nfor\ \{set\ i\ 0\}\ \{\$i\ <\ 10\}\ \{incr\ i\}\ \{\n\ \ \ \ \$win\ create\ line\ \$x0\ \[expr\ \{\$i\ *\ \$dy\ +\ \$y0\}\]\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[expr\ \{8\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{\$i\ *\ \$dy\ +\ \$y0\}\]\n\}\n======\n\nThere's\ more\ work\ to\ be\ done,\ though.\ \ Hopefully\ this\ will\ get\ you\ started.\n\n----\n**References***\n\n\ \ \ *\ \[Simple\ Canvas\ Demo\]\n\ \ \ *\ http://www.goddesschess.com/chessays/gaddbabylon.html\n\ \ \ *\ http://skookumpete.com/chess_intro.htm\n\ \ \ *\ http://rishida.net/tools/conversion/,\ outstanding\ unicode\ conversion\ online!!!\n\ \ \ *\ http://mayoneez.1g.fi/hiddenlynx/index.html\n\ \ \ *\ http://www.chessvariants.org/graphics.dir/big5/index.html\n\ \ \ *\ http://geert.vanderkelen.org/2009/12/chessboard-in-mysql.html\n\ \ \ *\ http://pinyin.info/tools/converter/chars2uninumbers.html\n\ \ \ *\ http://en.wikipedia.org/wiki/Miscellaneous_Symbols_Unicode_block\n\ \ \ *\ \[A\ little\ checker\ game\]\n\ \ \ *\ \[Simple\ Canvas\ Demo\]\n\ \ \ *\ \[Things\ Chinese\]\n\ \ \ *\ \[Pinyin,\ ASCII\ to\ Unicode\ Converter\]\n\ \ \ *\ http://99.237.250.152/xq/book/xiangqi_printset.pdfunicode\n\ \ \ *\ http://www.yutopian.com/chinesechess/chrules.pdf\n\n**appendix\ TCL\ programs**\n***FIRST\ DEMO***\ \n\n======\ \n\ \ \ \ \ \ \ \ #\ first\ demo\ code\ from\ \[AMG\]\n\ \ \ \ \ \ \ \ #\ pretty\ print\ version\ from\ autoindent\ and\ ased\n\ \ \ \ \ \ \ \ #\ Xiangqi\ chessboard\ with\ little\ frills.\n\ \ \ \ \ \ \ \ #\ Crosspatch\ program,\ dated\ 3JUL2010.\n\ \ \ \ \ \ \ \ #TCL\ WIKI\ contribution\n\ \ \ \ \ \ \ \ package\ require\ Tk\n\ \ \ \ \ \ \ \ proc\ crosspatch\ \{w\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ set\ dx\ 20\ \ \ \ \;#\ pixels\ between\ adjacent\ vertical\ grid\ lines\n\ \ \ \ \ \ \ \ \ \ \ \ set\ dy\ 20\ \ \ \ \;#\ pixels\ between\ adjacent\ horizontal\ grid\ lines\n\ \ \ \ \ \ \ \ \ \ \ \ set\ x0\ 30\ \ \ \ \;#\ pixels\ between\ left\ of\ canvas\ and\ left\ of\ grid\n\ \ \ \ \ \ \ \ \ \ \ \ set\ y0\ 30\ \ \ \ \;#\ pixels\ between\ top\ of\ canvas\ and\ top\ of\ grid\n\ \ \ \ \ \ \ \ \ \ \ \ set\ win\ \$w\ \ \ \;#\ name\ of\ canvas\ widget\n\ \ \ \ \ \ \ \ \ \ \ \ foreach\ i\ \{0\ 8\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \$y0\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{9\ *\ \$dy\ +\ \$y0\}\]\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ for\ \{set\ i\ 1\}\ \{\$i\ <\ 8\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \$y0\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{4\ *\ \$dy\ +\ \$y0\}\]\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{5\ *\ \$dy\ +\ \$y0\}\]\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{9\ *\ \$dy\ +\ \$y0\}\]\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ 10\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ create\ line\ \$x0\ \[expr\ \{\$i\ *\ \$dy\ +\ \$y0\}\]\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[expr\ \{8\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{\$i\ *\ \$dy\ +\ \$y0\}\]\n\ \ \ \ \ \ \ \ \ \ \ \ \}\}\n\ \ \ \ \ \ \ \ pack\ \[\ canvas\ .cx\ -width\ 400\ -height\ 400\ \]\n\ \ \ \ \ \ \ \ crosspatch\ .cx\n======\ \n\n\n***SECOND\ DEMO***\ \n***minimal\ example\ of\ linked\ movement\ on\ canvas***\n\n======\ \n\ \ \ \ \ \ \ \ #\ second\ demo\ code\n\ \ \ \ \ \ \ \ #\ pretty\ print\ from\ autoindent\ and\ ased\ editor\n\ \ \ \ \ \ \ \ #\ Xiangqi\ chessboard\ with\ little\ frills.\n\ \ \ \ \ \ \ \ #\ Linked\ oval\ and\ text\ movement\ on\ TCL\ canvas\ program,\ dated\ 3JUL210.\n\ \ \ \ \ \ \ \ #TCL\ WIKI\ contribution\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ #***minimal\ example\ of\ linked\ movement\ on\ canvas***\n\ \ \ package\ require\ Tk\n\ \ \ \ \ \ \ proc\ grab\ \{\ xx\ yy\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ global\ currentx\ currenty\n\ \ \ \ \ \ \ \ \ \ \ \ set\ currentx\ \$xx\n\ \ \ \ \ \ \ \ \ \ \ \ set\ currenty\ \$yy\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ proc\ move\ \{w\ xx\ yy\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ global\ currentx\ currenty\n\ \ \ \ \ \ \ \ \ \ \ \ set\ dx\ \[expr\ \{\$xx\ -\ \$currentx\}\]\n\ \ \ \ \ \ \ \ \ \ \ \ set\ dy\ \[expr\ \{\$yy\ -\ \$currenty\}\]\n\ \ \ \ \ \ \ \ \ \ \ \ \$w\ move\ movable\ \$dx\ \$dy\n\ \ \ \ \ \ \ \ \ \ \ \ \$w\ raise\ movable\n\ \ \ \ \ \ \ \ \ \ \ \ set\ currentx\ \$xx\n\ \ \ \ \ \ \ \ \ \ \ \ set\ currenty\ \$yy\n\ \ \ \ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ canvas\ .cv\ -width\ 200\ -height\ 200\n\ \ \ \ \ \ \ \ pack\ .cv\n\ \ \ \ \ \ \ \ .cv\ create\ oval\ 10\ 10\ 30\ 30\ -fill\ red\ -tag\ movable\n\ \ \ \ \ \ \ \ .cv\ create\ text\ 20\ 20\ \ \ -text\ @\ -fill\ blue\ -tag\ movable\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ .cv\ create\ rect\ 110\ 10\ 130\ 50\ -fill\ green\ -tag\ stationary\n\ \ \ \ \ \ \ \ .cv\ create\ rect\ 10\ 110\ 50\ 90\ -fill\ yellow\ -tag\ stationary\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ .cv\ bind\ movable\ <Button-1>\ \{grab\ %x\ %y\ \}\n\ \ \ \ \ \ \ \ .cv\ bind\ movable\ <B1-Motion>\ \{move\ .cv\ %x\ %y\ \}\n======\n\n***THIRD\ DEMO***\ \n***pegboard\ DEMO\ with\ little\ frills\ ***\n\n======\ \n\ \ \ \ #\ pretty\ print\ from\ autoindent\ and\ ased\ editor\n\ \ \ \ #\ pegboard\ DEMO\ with\ little\ frills.\n\ \ \ \ #\ PEGBOARD\ program,\ dated\ 3JUL210.\n\ \ \ \ #TCL\ WIKI\ contribution\n\ \ \ \ package\ require\ Tk\ \ \ \ \n\ \ \ \ proc\ pegboard\ \{w\}\ \{\n\ \ \ \ \ \ \ \ console\ show\n\ \ \ \ \ \ \ \ set\ \ max\ 400\n\ \ \ \ \ \ \ \ set\ \ may\ 400\n\ \ \ \ \ \ \ \ for\ \{set\ r\ 50\}\ \{\$r\ <\ \$max\}\ \{incr\ r\ 45\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ for\ \{set\ c\ 50\}\ \{\$c\ <\ \$max\}\ \{incr\ c\ 45\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ tilename\ \ \[expr\ \{int(rand()*1000000000.)\}\]\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ create\ oval\ \$r\ \$c\ \[expr\ \$r+5\]\ \[expr\ \$c+5\]\ -outline\ gray\ -fill\ green\ -width\ 1\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ -tags\ \[concat\ mv\ xdat_\[expr\ \$r+5\]\ \ ydat_\[expr\ \$c+5\]\ obj_\$tilename\]\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ puts\ \"\ xdat_\[expr\ \$r+5\]\ \ ydat_\[expr\ \$c+5\]\ obj_\$tilename\"\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ texter\ \ \"\ \ \[expr\ \$r+5\]\ \[expr\ \$c+5\]\ \ \"\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$w\ create\ text\ \[expr\ \$r+5\]\ \[expr\ \$c+20\]\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ -text\ \$texter\ -fill\ green\ -tags\ \"\ \ \[expr\ \$r+5\]\ \[expr\ \$c+20\]\"\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ \ \ \ \ \}\}\}\n\ \ \ \ pack\ \[\ canvas\ .cx\ -width\ 400\ -height\ 400\ \]\n\ \ \ \ pegboard\ .cx\n\ ======\n\n***FIRST\ VERSION***\ \n\n======\n\ #start\ of\ deck#start\ of\ deck\n\ \ \ \ \ \ \ \ #start\ of\ deck\n\ \ \ \ \ \ \ \ #start\ of\ deck\n\n\ #\ written\ on\ Windowws\ XP\ on\ eTCL\ \n\ \ \ \ \ #\ working\ under\ TCL\ version\ 8.5.6\ and\ eTCL\ 1.0.1\ \n\ \ \ \ \ #\ gold\ on\ TCL\ WIKI\ ,\ 17Jul2010\n\n\ set\ oscwidth\ 1000\ \n\ set\ oschorizontal\ 500\ \n\ proc\ loop\ \{from\ to\ body\}\ \{\n\ \ \ \ upvar\ 1\ i\ i\ \;#\ make\ index\ visible\ in\ body\n\ \ \ \ for\ \{set\ i\ \$from\}\ \{\$i<\$to\}\ \{incr\ i\}\ \{uplevel\ 1\ \$body\}\n\ \}\n\ #--\ And\ likewise,\ a\ shortcut\ for\ addition:\n\ proc\ +\ \{a\ b\}\ \{expr\ \{\$a+\$b\}\}\n\ \n\ pack\ \[canvas\ .cv\ -width\ 400\ -height\ 500\ \]\n\n\ focus\ .cv\ \n\ set\ state2\ 1\n\ proc\ refreshgrid\ \{\ .cv\ state2\}\ \{\n\ global\ oscwidth\ oschorizontal\ colorite\n\ global\ grid\n\ set\ colorite\ blue\ \n\ for\ \{set\ x\ 10\}\ \{\$x<\$oscwidth\}\ \{incr\ x\ 50\}\ \{.cv\ create\ line\ \$x\ 0\ \$x\ \$oschorizontal\ \ -fill\ blue\ -tag\ grid\ -\n\nwidth\ 4\}\n\ for\ \{set\ y\ 20\}\ \{\$y<\$oschorizontal\}\ \{incr\ y\ 50\}\ \{.cv\ create\ line\ 0\ \$y\ \$oschorizontal\ \$y\ -fill\ blue\ \ -tag\ grid\ \n\n-width\ 4\}\ \n\ .cv\ itemconfigure\ grid\ -fill\ blue\ \n\n\ if\ \{\ \$state2\ ==\ 1\ \}\ \{\ .cv\ raise\ grid\ \;\}\ \n\ if\ \{\ \$state2\ ==\ 2\ \}\ \{\ .cv\ lower\ grid\ \;\}\ \n\ \}\n\n\ \ refreshgrid\ \ .cv\ \$state2\ \n\ #\ next\ lines\ start\ withn\ periods,\ but\ hard\ to\ see\n\ .\ configure\ -borderwidth\ 0\ -highlightthickness\ 0\ -takefocus\ 0\ -background\ aquamarine4\n\ .\ configure\ -background\ palegreen\ -highlightcolor\ DarkOliveGreen\ -relief\ raised\ -border\ 30\n\n\ .\ configure\ -width\ 1000\ -height\ 2000\n\n\ .cv\ bind\ all\ <1>\ \{set\ p(X)\ \[.cv\ canvasx\ %x\]\;\ set\ p(Y)\ \[.cv\ canvasy\ %y\]\}\n\ .cv\ bind\ mv\ <B1-Motion>\ \{mv\ .cv\ %x\ %y\}\n\n\ \ proc\ mv\ \{w\ x\ y\}\ \{\n\ \ \ \ global\ p\n\ \ \ \ set\ x\ \ \[\$w\ canvasx\ \$x\]\n\ \ \ \ set\ y\ \ \[\$w\ canvasy\ \$y\]\n\ \ \ \ set\ id\ \[\$w\ find\ withtag\ current\]\n\ \ \ \ set\ numberx\ \[\$w\ \ gettags\ current\]\n\ \ \ \ regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ \n\ \ \ \ puts\ \"1\"\n\ \ \ \ puts\ \$numberx\n\ \ \ \ puts\ \$tilex\n\ \ \ \ puts\ \"\ with\ tag\ \[\$w\ find\ withtag\ obj_\$tilex\ \]\"\n\ \ \ \ foreach\ item\ \[\$w\ find\ withtag\ obj_\$tilex\ \]\ \{\n\ \ \ \ \$w\ move\ \$item\ \[expr\ \{\$x-\$p(X)\}\]\ \[expr\ \{\$y-\$p(Y)\}\]\n\ \ \ \ #\$w\ raise\ \$id\n\ \ \ \ \}\n\ \ \ \ puts\ \"\ x\ y\ \$x\ \$y\"\n\ \ \ \ #\$w\ raise\ \$id\n\ \ \ \ #\ \$w\ move\ \[\$w\ find\ withtag\ \"\$tilex\"\]\ \[expr\ \{\$x-\$p(X)\}\]\ \[expr\ \{\$y-\$p(Y)\}\]\n\ \ \ \ #set\ numberx\ \[\$w\ \ gettags\ current\]\n\ \ \ \ #regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ set\ p(X)\ \$x\;\ set\ p(Y)\ \$y\n\ \}\n\n\ \ \ \ \ set\ bluepieces\ \[list\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]\n\ \ \ \ \ set\ redpieces\ \ \[list\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]\n\ \ \ \ \ #black\ western\n\ \ \ \ \ set\ bluepieces\ \{\ \ \\u265A\ \\u265B\ \\u265C\ \\u265C\ \\u265D\ \\u265D\ \\u265E\ \\u265E\ \\u265F\ \\u265F\ \\u265F\ \\u265F\ \n\n\\u265F\ \\u265F\ \\u265F\ \\u265F\}\ \ \n\ \ \ \ \ #white\ western\n\ \ \ \ \ set\ redpieces\ \{\ \ \\u2654\ \\u2655\ \\u2655\ \\u2656\ \ \\u2656\ \\u2657\ \\u2657\ \ \\u2658\ \\u2658\ \\u2659\ \\u2659\ \\u2659\ \ \n\n\\u2659\ \\u2659\ \\u2659\ \\u2659\ \\u2659\}\ \ \n\ \ \ \ \ \ \ set\ bluepieces\ \{\\u5C07\ \\u58EB\ \ \\u58EB\ \ \\u8C61\ \\u8C61\ \\u99AC\ \\u99AC\ \\u8ECA\ \\u8ECA\ \ \ \\u7832\ \ \ \\u7832\ \ \ \ \n\n\\u5352\ \\u5352\ \\u5352\ \ \ \\u5352\ \\u5352\}\n\ set\ redpieces\ \ \{\ \ 0\ \\u5E25\ \ \ \\u4ED5\ \\u4ED5\ \ \ \\u76F8\ \ \ \\u76F8\ \\u99AC\ \\u99AC\ \\u8ECA\ \\u8ECA\ \ \ \ \ \ \\u70AE\ \ \\u70AE\ \n\n\ \\u5175\ \ \\u5175\ \ \ \ \\u5175\ \ \ \ \ \\u5175\ \ \ \\u5175\ \ \}\ \ \n\ \ \ \ \ \n\ \ \ \ \ set\ ind\ 0\n\ \ \ \ \ set\ indx\ 0\n\ \ \ \ \ set\ baseline\ \{list\ 1\}\n\ \ \ \ \ \ proc\ K\ \{\ x\ y\ \}\ \{\ set\ x\ \}\n\n\ \ \ \ \ proc\ xpop\ \{\ topper\ \}\ \{\n\ \ \ \ \ global\ liner\n\ \ \ \ \ global\ ind\ indx\n\ \ \ \ \ global\ bluepieces\ redpieces\n\ \ \ \ \ global\ baseline\n\ \ \ \ \ set\ topper\ \[\ lindex\ \$bluepieces\ \$ind\ \]\;\n\ \ \ \ \ if\ \{\ \$topper\ ==\ \"\"\ \}\ \{\ \n\ \ \ \ \ set\ topper\ \[\ lindex\ \$redpieces\ \$indx\ \]\n\ \ \ \ \ set\ indx\ \[\ expr\ \{\ \$indx\ +\ 1\}\]\n\ \ \ \ \ \ \ \}\ \n\ \ \ \ \ set\ ind\ \[\ expr\ \{\ \$ind\ +\ 1\}\]\n\ \ \ \ \ lappend\ \$baseline\ \$topper\;\n\ \ \ \ \ return\ \$topper\;\n\ \ \ \ \ \}\n\ \ proc\ populateCanvas\ \{w\ cols\ rows\ args\}\ \{\n\ \ \ \ global\ ind\ indx\n\ \ \ \ variable\ ids\ \;#\ links\ text\ ids\ with\ respective\ rect\ ids\n\ \ \ \ variable\ boxes\ \;#\ lists\ text\ id\ and\ text\ associated\ with\ each\ rect\ id\n\ \ \ \ catch\ \{unset\ ids\ boxes\}\n\ \ \ \ set\ canvas\ \$w\n\ \ \ \ #\ parameters\ for\ drawing\ boxes\n\ \ \ \ set\ boxwidth\ 50\n\ \ \ \ set\ boxheight\ 50\n\ \ \ \ set\ padx\ 3\n\ \ \ \ set\ pady\ 3\n\ \ \ \ set\ colors\ \{\ orange\ yellow\ green\ \ gray\}\n\ \ \ \ set\ labels\ \{one\ two\ three\ four\}\n\n\ \ \ \ #\ draw\ the\ boxes\n\ \ \ \ for\ \{set\ row\ 0\}\ \{\$row\ <\ \$rows\}\ \{incr\ row\}\ \{\n\ \ \ \ \ \ for\ \{set\ col\ 0\}\ \{\$col\ <\ \$cols\}\ \{incr\ col\}\ \{\n\n\ \ \ \ \ \ \ \ #\ calculate\ coordinates\n\ \ \ \ \ \ \ \ set\ x1\ \[expr\ \{\$col\ *\ (\$boxwidth\ +\ \$padx)\ +\ \$padx\}\]\n\ \ \ \ \ \ \ \ set\ x2\ \[expr\ \{\$x1\ +\ \$boxwidth\}\]\n\ \ \ \ \ \ \ \ set\ x3\ \[expr\ \{\$x1\ +\ (\$boxwidth\ /\ 2)\}\]\n\ \ \ \ \ \ \ \ set\ y1\ \[expr\ \{\$row\ *\ (\$boxheight\ +\ \$pady)\ +\ \$pady\}\]\n\ \ \ \ \ \ \ \ set\ y2\ \[expr\ \{\$y1\ +\ \$boxheight\}\]\n\ \ \ \ \ \ \ \ set\ y3\ \[expr\ \{\$y1\ +\ (\$boxheight\ /\ 2)\}\]\n\n\ \ \ \ \ \ \ \ #\ choose\ color\ and\ text\n\ \ \ \ \ \ \ \ set\ color\ \[lindex\ \$colors\ \[expr\ \{int(rand()\ *\ \[llength\ \$colors\])\}\]\]\n\ \ \ \ \ \ \ \ #set\ text\ \[lindex\ \$labels\ \[expr\ \{int(rand()\ *\ \[llength\ \$labels\])\}\]\]\n\ \ \ \ \ \ \ \ #\ set\ text\ \[xpop\ topper\]\n\ \ \ \ \ \ \ \ \ set\ font2\ \[list\ Helvetica\ \[expr\ \$boxwidth/2\]\]\n\n\ \ \ \ \ \ \ \ \ #set\ text\ \"0\"\n\ \ \ \ \ \ \ \ \ #set\ text\ \"K\"\n\ \ \ \ \ \ \ \ \ set\ text\ \[xpop\ 1\ \]\n\ \ \ \ \ \ \ \ \ set\ tilename\ \ \[expr\ \{int(rand()*1000000000.)\}\]\n\ \ \ \ \ \ \ \ #\ create\ the\ boxes\n\ \ \ \ \ \ \ \ set\ boxid\ \[\$canvas\ create\ oval\ \$x1\ \$y1\ \$x2\ \$y2\ \\\n\ \ \ \ \ \ \ \ \ \ -fill\ \$color\ -tags\ \[concat\ mv\ rect\ \$args\ \ obj_\$tilename\]\\\n\ \ \ \ \ \ \ \ \ \ -outline\ black\]\n\ \ \ \ \ \ \ \ set\ colorfo\ blue\n\ \ \ \ \ \ \ \ if\ \{\ \$indx\ >\ 1\ \}\ \{set\ colorfo\ red\}\n\ \ \ \ \ \ \ \ set\ textid\ \[\$canvas\ create\ text\ \$x3\ \$y3\ -font\ \$font2\ -fill\ \$colorfo\ \\\n\ \ \ \ \ \ \ \ \ \ -text\ \$text\ -tags\ \[concat\ mv\ \ \$args\ \ obj_\$tilename\]\ \ \]\n\n\ \ \ \ \ \ \ \ #\ remember\ which\ text\ item\ goes\ with\ which\ box\ and\ what\ the\ text\ says\n\ \ \ \ \ \ \ \ set\ boxes(\$boxid)\ \[list\ \$textid\ \$text\]\n\ \ \ \ \ \ \ \ set\ ids(\$textid)\ \$boxid\n\ \ \ \ \ \ \ \ set\ ids(\$boxid)\ \$boxid\n\ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \}\ \ \n\ \ \ \ \ populateCanvas\ .cv\ 6\ 7\ \ \n\ \ console\ show\ \n\ #end\ of\ deck\n\ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\ \ \ \ \ \ \n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #statements\ for\ random\ names\ of\ objects\n\ \ \ \ \ \ \ \ #set\ numberx\ \[.c\ \ gettags\ current\]\;\n\ \ \ \ \ \ \ \ #\ regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ \ \ \ #.c\ delete\ \"obj_\$tilex+1\"\ \;\n\ \ \ \ \ \ #set\ tilename\ \ \[expr\ \{int(rand()*1000000000.)\}\]\n\ \ \ \ \ #.c\ delete\ obj_\$tilex\ \;\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\ \ \ \ \ \ \n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\ \ \ \ \ \ \n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ #end\ of\ deck\n======\n\n****SECOND\ VERSION\ WITH\ ADDED\ HACKS\ ***\ \n\n======\ \n\n\ \ \ \ \ #start\ of\ deck\n\ \ \ \ \ \ \ \ #start\ of\ deck\n\ \ \ \ \ \ \ \ #start\ of\ deck\ #!/bin/sh\n\ #\ Restart\ with\ tcl:\ -*-\ mode:\ tcl\;\ tab-width:\ 4\;\ -*-\ \\\n\ exec\ wish\ \$0\ \$\{1+\"\$@\"\}\n\n\ #\ demo2-canvas.tcl\ -\ HaJo\ Gurt\ -\ 2005-12-13\ -\ http://wiki.tcl.tk/15073\n\ #:\ CanvasDemo:\ On\ button-click,\ draw\ something\ on\ the\ canvas\n\ #\ gold\ used\ canvas\ demo\ as\ base\ for\ TCL\ \ chess\ display\ board.\n\ \n\ \ package\ require\ Tk\n\n\ \ proc\ ClrCanvas\ \{w\}\ \{\n\ \ \ \ \$w\ delete\ \"all\"\n\ \ \ \ \$w\ configure\ \ -bg\ white\n\ \ \}\n\n\ \ proc\ DrawAxis\ \{w\}\ \{\n\ \ \ \ set\ midX\ \[expr\ \{\ \$::maxX\ /\ 2\ \}\]\n\ \ \ \ set\ midY\ \[expr\ \{\ \$::maxY\ /\ 2\ \}\]\n\ \ \ \ \$w\ create\ line\ 0\ \ \ \ \ \$midY\ \ \$::maxX\ \ \ \$midY\ \ -tags\ \"axis\"\n\ \ \ \ \$w\ create\ line\ \$midX\ 0\ \ \ \ \ \ \ \ \$midX\ \$::maxY\ \ -tags\ \"axis\"\n\ \ \}\n\n\ \ proc\ PaintText\ \{w\ Txt\}\ \{\n\ \ \ \ global\ y\n\ \ \ \ incr\ y\ 10\n\ \ \ \ \$w\ create\ text\ 100\ \$y\ -text\ \$Txt\ -tags\ \"text\"\n\ \ \}\n\n\ \ proc\ DrawBox\ \{w\}\ \{\n\ \ \ \ global\ x1\ y1\ x2\ y2\n\ \ \ \ \$w\ create\ rect\ \ 50\ \ 50\ \ 100\ \ 90\ \ -tags\ \"box\"\n\ \ \ \ \$w\ create\ rect\ \$x1\ \$y1\ \ \$x2\ \$y2\ \ -tags\ \"box\"\n\ \ \ \ incr\ x1\ 15\n\ \ \ \ incr\ x2\ 15\n\ \ \ \ incr\ y1\ 10\n\ \ \ \ incr\ y2\ 10\n\ \ \}\n\n\ \ proc\ DrawFn1\ \{w\}\ \{\n\ \ \ \ \$w\ create\ line\ 0\ 100\ \ 50\ 200\ \ 100\ 50\ \ 150\ 70\ \ 200\ 155\ \ 250\ 50\ \ 300\ 111\ \ 350\ 222\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ -tags\ \"Fn1\"\ \ -smooth\ bezier\n\ \ \}\n\n\ \ proc\ DrawFn2\ \{w\}\ \{\n\ \ \ \ set\ offY\ 0\ \ \ \ \;#\ \[expr\ \{\ \$::maxY\ /\ 2\ \}\]\n\n\ \ \ \ for\ \{\ set\ x\ 0\ \}\ \{\ \$x\ <=\ \$::maxX\ \}\ \{\ incr\ x\ 5\ \}\ \{\n\ \ \ \ \ \ set\ y\ \[expr\ \{\ rand()\ *\ \$::maxY\ +\ \$offY\ \}\]\n\n\ \ \ \ \ #puts\ \"\$x\ \$y\"\n\ \ \ \ \ \ if\ \{\$x>0\}\ \{\ \$w\ create\ line\ \$x0\ \$y0\ \$x\ \$y\ -tags\ \"Fn2\"\ \}\n\ \ \ \ \ \ set\ x0\ \$x\n\ \ \ \ \ \ set\ y0\ \$y\n\ \ \ \ \}\n\ \ \}\n\n\ \ #:\ Main\ :\n\ \ frame\ .f1\n\ \ frame\ .f2\n\ \ pack\ \ .f1\ .f2\n\n\ \ set\ maxX\ 400\n\ \ set\ maxY\ 400\n\ \ set\ y\ \ \ \ \ \ 0\n\n\ \ set\ x1\ 120\n\ \ set\ x2\ 150\n\ \ set\ y1\ \ 50\n\ \ set\ y2\ \ 80\n\n\ \ canvas\ \ .cv\ -width\ \$maxX\ -height\ \$maxY\ \ -bg\ tan\n\ \ pack\ \ \ \ .cv\ -in\ .f1\n\ \ button\ \ .a0\ -text\ \"xiangqi\"\ -command\ \{set\ state2\ 1\;set\ state3\ 1\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 1\ \ \ \}\n\ \ button\ \ .a1\ -text\ \"west*\"\ -command\ \{unset\ state3\;set\ state3\ 3\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 3\ \ \ \}\n\ \ button\ \ .a2\ -text\ \"@\"\ -command\ \{unset\ state3\;set\ state3\ 3\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 2\ \ \ \}\n\ \ button\ \ .b0\ -text\ \"C\"\ -command\ \{\ ClrCanvas\ .cv\ \}\n\ \ button\ \ .b1\ -text\ \"Text\"\ \ -command\ \{\ PaintText\ .cv\ \"Chinese\ Xiangqi\ Chess\"\ \}\n\ \ button\ \ .b2\ -text\ \"+\"\ \ -command\ \{\ DrawAxis\ \ .cv\ \}\n\ \ button\ \ .b3\ -text\ \"\\\[\\\]\"\ \ \ -command\ \{\ DrawBox\ \ \ .cv\ \}\n\ \n\ \ button\ \ .b6\ -text\ \"#dn\"\ \ \ -command\ \{\ refreshgrid\ .cv\ 2\ \}\ \ \ \n\n\ \ button\ \ .b7\ -text\ \"#up\"\ \ \ -command\ \{\ refreshgrid\ .cv\ 1\ \}\ \n\ \ button\ \ .b8\ -text\ \"#^\"\ \ \ -command\ \{.cv\ scale\ all\ 0\ 0\ 1.1\ 1.1\ \}\n\ \ button\ \ .b9\ -text\ \"#<\"\ \ \ -command\ \{.cv\ scale\ all\ 0\ 0\ .9\ .9\ \}\ \ \n\ \ button\ \ .b10\ -text\ \"x\"\ \ \ -command\ \{\ exit\ \ \ \ \}\n\ \ \ set\ info\ \"000\ 000\"\n\ \ \ label\ \ .info\ -textvar\ info\ -just\ left\n\ \ pack\ .a0\ .a1\ .a2\ .b0\ .b1\ .b2\ .b3\ \ .b6\ .b7\ .b8\ .b9\ .b10\ .info\ -in\ .f2\ \ -side\ left\ -padx\ 2\n\n\ #catch\ \{console\ show\}\nset\ oscwidth\ 1000\ \n\ set\ oschorizontal\ 500\ \n\ proc\ loop\ \{from\ to\ body\}\ \{\n\ \ \ \ upvar\ 1\ i\ i\ \;#\ make\ index\ visible\ in\ body\n\ \ \ \ for\ \{set\ i\ \$from\}\ \{\$i<\$to\}\ \{incr\ i\}\ \{uplevel\ 1\ \$body\}\n\ \}\n#--\ And\ likewise,\ a\ shortcut\ for\ addition:\n\ proc\ +\ \{a\ b\}\ \{expr\ \{\$a+\$b\}\}\n\ \n\ #pack\ \[canvas\ .cv\ -width\ 400\ -height\ 500\ \]\n\n#\ focus\ .cv\ \n\ set\ state2\ 1\n\ proc\ refreshgrid\ \{\ .cv\ state2\}\ \{\n\ global\ oscwidth\ oschorizontal\ colorite\n\ global\ grid\n\ \ global\ ind\ indx\n\ \ set\ ind\ 0\n\ \ set\ indx\ 0\n\ set\ colorite\ blue\ \n\ for\ \{set\ x\ 10\}\ \{\$x<\$oscwidth\}\ \{incr\ x\ 50\}\ \{.cv\ create\ line\ \$x\ 0\ \$x\ \$oschorizontal\ \ -fill\ blue\ -tag\ grid\ -width\ 4\}\n\ for\ \{set\ y\ 20\}\ \{\$y<\$oschorizontal\}\ \{incr\ y\ 50\}\ \{.cv\ create\ line\ 0\ \$y\ \$oschorizontal\ \$y\ -fill\ blue\ \ -tag\ grid\ -width\ 4\}\ \n\ .cv\ itemconfigure\ grid\ -fill\ blue\ \n\n\ if\ \{\ \$state2\ ==\ 1\ \}\ \{\ .cv\ raise\ grid\ \;\}\ \n\ if\ \{\ \$state2\ ==\ 2\ \}\ \{\ .cv\ lower\ grid\ \;\}\ \n\ \}\n\n\ \ refreshgrid\ \ .cv\ \$state2\ \n\ #\ next\ lines\ start\ withn\ periods,\ but\ hard\ to\ see\n\ .\ configure\ -borderwidth\ 0\ -highlightthickness\ 0\ -takefocus\ 0\ -background\ aquamarine4\n\ .\ configure\ -background\ palegreen\ -highlightcolor\ DarkOliveGreen\ -relief\ raised\ -border\ 30\n\n\ .\ configure\ -background\ palegreen\ -highlightcolor\ DarkOliveGreen\ -relief\ raised\ -border\ 30\n\ .\ configure\ -width\ 1000\ -height\ 2000\n\n.cv\ bind\ all\ <1>\ \{set\ p(X)\ \[.cv\ canvasx\ %x\]\;\ set\ p(Y)\ \[.cv\ canvasy\ %y\]\;set\ info\ \"\ %x\ %y\ \"\}\n\ .cv\ bind\ mv\ <B1-Motion>\ \{mv\ .cv\ %x\ %y\}\n\ .cv\ bind\ mv\ <ButtonRelease-1>\ \{set\ info\ \"\ %x\ %y\ \"\}\n\ #.cv\ bind\ moveable\ <ButtonPress-1>\ \{item:move\ %W\ %x\ %y\ 1\;set\ info\ \"\ %x\ %y\ \"\}\n\ proc\ mv\ \{w\ x\ y\}\ \{\n\ \ \ \ global\ p\n\ \ \ \ set\ x\ \ \[\$w\ canvasx\ \$x\]\n\ \ \ \ set\ y\ \ \[\$w\ canvasy\ \$y\]\n\ \ \ \ set\ id\ \[\$w\ find\ withtag\ current\]\n\ \ \ \ set\ numberx\ \[\$w\ \ gettags\ current\]\n\ \ \ \ regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ \n\ \ \ \ puts\ \"1\"\n\ \ \ \ puts\ \$numberx\n\ \ \ \ puts\ \$tilex\n\ \ \ \ puts\ \"\ with\ tag\ \[\$w\ find\ withtag\ obj_\$tilex\ \]\"\n\ \ \ \ foreach\ item\ \[\$w\ find\ withtag\ obj_\$tilex\ \]\ \{\n\ \ \ \ \$w\ move\ \$item\ \[expr\ \{\$x-\$p(X)\}\]\ \[expr\ \{\$y-\$p(Y)\}\]\n\ \ \ \ #\$w\ raise\ \$id\n\ \ \ \ \}\n\ \ \ \ puts\ \"\ x\ y\ \$x\ \$y\"\n\ \ \ \ #\$w\ raise\ \$id\n\ \ \ \ #\ \$w\ move\ \[\$w\ find\ withtag\ \"\$tilex\"\]\ \[expr\ \{\$x-\$p(X)\}\]\ \[expr\ \{\$y-\$p(Y)\}\]\n\ \ \ \ #set\ numberx\ \[\$w\ \ gettags\ current\]\n\ \ \ \ #regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ set\ p(X)\ \$x\;\ set\ p(Y)\ \$y\n\ \}\n\ \n\ \ \ \ proc\ board\ \{w\}\ \{\n\ \ \ \ #set\ state3\ 1\n\ \ \ \ set\ state2\ 1\n\ \ \ \ ClrCanvas\ \$w\n\ \ \ \ .\ configure\ -background\ orange\ -highlightcolor\ brown\ -relief\ raised\ -border\ 30\n\ \ \ \ \$w\ configure\ -bg\ tan\n\ \ \ \ \n\ \ \ \ refreshgrid\ \ .cv\ \$state2\ \;\n\ \ \ \ \}\n\ \ \ \ proc\ gamepieces\ \{state3\}\ \{\n\ \ \ \ \ global\ bluepieces\ redpieces\n\ \ \ \ \ if\ \{\ \$state3\ ==\ 2\ \}\ \{\ \n\ \ \ \ \ set\ bluepieces\ \[list\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]\n\ \ \ \ \ set\ redpieces\ \ \[list\ 0\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]\n\ \ \ \ \ \ \ \}\ \n\ \ \ \ \ \n\ \ \ \ if\ \{\ \$state3\ ==\ 3\ \}\ \{\ \n\ \ \ \ \ #black\ western\n\ \ \ \ \ set\ bluepieces\ \{\ \ \\u265A\ \\u265B\ \\u265C\ \\u265C\ \\u265D\ \\u265D\ \\u265E\ \\u265E\ \\u265F\ \\u265F\ \\u265F\ \\u265F\ \\u265F\ \\u265F\ \\u265F\ \\u265F\}\ \ \n\ \ \ \ \ #white\ western\n\ \ \ \ \ set\ redpieces\ \{\ 0\ \ \\u2654\ \\u2655\ \\u2655\ \\u2656\ \ \\u2656\ \\u2657\ \\u2657\ \ \\u2658\ \\u2658\ \\u2659\ \\u2659\ \\u2659\ \ \\u2659\ \\u2659\ \\u2659\ \\u2659\ \\u2659\}\ \ \n\ \ \ \ \ \ \ \}\n\ \ \ \ \ \ if\ \{\ \$state3\ ==\ 1\ \}\ \{\ \n\ \ \ \ \ \ set\ bluepieces\ \{\\u5C07\ \\u58EB\ \ \\u58EB\ \ \\u8C61\ \\u8C61\ \\u99AC\ \\u99AC\ \\u8ECA\ \\u8ECA\ \ \ \\u7832\ \ \ \\u7832\ \ \ \ \\u5352\ \\u5352\ \\u5352\ \ \ \\u5352\ \\u5352\}\n\ set\ redpieces\ \ \{\ \ 0\ \\u5E25\ \ \ \\u4ED5\ \\u4ED5\ \ \ \\u76F8\ \ \ \\u76F8\ \\u99AC\ \\u99AC\ \\u8ECA\ \\u8ECA\ \ \ \ \ \ \\u70AE\ \ \\u70AE\ \ \\u5175\ \ \\u5175\ \ \ \ \\u5175\ \ \ \ \ \\u5175\ \ \ \\u5175\ \ \}\ \ \n\ \ \ \ \ \}\n\ \n\ \ \ \ \ \}\n\n\ \ \ \ \ set\ ind\ 0\n\ \ \ \ \ set\ indx\ 0\n\ \ \ \ \ set\ baseline\ \{list\ 1\}\n\ \ \ \ \ \ proc\ K\ \{\ x\ y\ \}\ \{\ set\ x\ \}\n\n\ \ \ \ \ proc\ xpop\ \{\ topper\ \}\ \{\n\ \ \ \ \ global\ liner\ \n\ \ \ \ \ global\ ind\ indx\ \n\ \ \ \ \ global\ bluepieces\ redpieces\n\ \ \ \ \ global\ baseline\n\ \ \ \ \ set\ topper\ \[\ lindex\ \$bluepieces\ \$ind\ \]\;\n\ \ \ \ \ if\ \{\ \$topper\ ==\ \"\"\ \}\ \{\ \n\ \ \ \ \ set\ topper\ \[\ lindex\ \$redpieces\ \$indx\ \]\n\ \ \ \ \ set\ indx\ \[\ expr\ \{\ \$indx\ +\ 1\}\]\n\ \ \ \ \ \ \ \}\ \n\ \ \ \ \ set\ ind\ \[\ expr\ \{\ \$ind\ +\ 1\}\]\n\ \ \ \ \ lappend\ \$baseline\ \$topper\;\n\ \ \ \ \ return\ \$topper\;\n\ \ \ \ \ \}\n\ \ \ \ \ set\ state2\ 1\n\ \ \ \ \ \ \ \ \ \ proc\ populateCanvas\ \{w\ cols\ rows\ args\}\ \{\n\ \ \ \ global\ state2\ state3\n\ \ \ \ gamepieces\ \$args\n\ \ \ \ #refreshgrid\ \ \$w\ \$state2\ \n\ \ \ \ set\ state3\ \$args\n\ \ \ \ global\ ind\ indx\n\ \ \ \ variable\ ids\ \;#\ links\ text\ ids\ with\ respective\ rect\ ids\n\ \ \ \ variable\ boxes\ \;#\ lists\ text\ id\ and\ text\ associated\ with\ each\ rect\ id\n\ \ \ \ catch\ \{unset\ ids\ boxes\}\n\ \ \ \ set\ canvas\ \$w\n\ \ \ \ \n\ \ \ \ #\ parameters\ for\ drawing\ boxes\n\ \ \ \ set\ boxwidth\ 50\n\ \ \ \ set\ boxheight\ 50\n\ \ \ \ set\ padx\ 3\n\ \ \ \ set\ pady\ 3\n\ \ \ \ set\ colors\ \{\ orange\ yellow\ green\ \ gray\}\n\ \ \ \ set\ labels\ \{one\ two\ three\ four\}\n\n\ \ \ \ #\ draw\ the\ boxes\n\ \ \ \ for\ \{set\ row\ 0\}\ \{\$row\ <\ \$rows\}\ \{incr\ row\}\ \{\n\ \ \ \ \ \ for\ \{set\ col\ 0\}\ \{\$col\ <\ \$cols\}\ \{incr\ col\}\ \{\n\n\ \ \ \ \ \ \ \ #\ calculate\ coordinates\n\ \ \ \ \ \ \ \ set\ x1\ \[expr\ \{\$col\ *\ (\$boxwidth\ +\ \$padx)\ +\ \$padx\}\]\n\ \ \ \ \ \ \ \ set\ x2\ \[expr\ \{\$x1\ +\ \$boxwidth\}\]\n\ \ \ \ \ \ \ \ set\ x3\ \[expr\ \{\$x1\ +\ (\$boxwidth\ /\ 2)\}\]\n\ \ \ \ \ \ \ \ set\ y1\ \[expr\ \{\$row\ *\ (\$boxheight\ +\ \$pady)\ +\ \$pady\}\]\n\ \ \ \ \ \ \ \ set\ y2\ \[expr\ \{\$y1\ +\ \$boxheight\}\]\n\ \ \ \ \ \ \ \ set\ y3\ \[expr\ \{\$y1\ +\ (\$boxheight\ /\ 2)\}\]\n\n\ \ \ \ \ \ \ \ #\ choose\ color\ and\ text\n\ \ \ \ \ \ \ \ set\ color\ \[lindex\ \$colors\ \[expr\ \{int(rand()\ *\ \[llength\ \$colors\])\}\]\]\n\ \ \ \ \ \ \ \ #set\ text\ \[lindex\ \$labels\ \[expr\ \{int(rand()\ *\ \[llength\ \$labels\])\}\]\]\n\ \ \ \ \ \ \ \ #\ set\ text\ \[xpop\ topper\]\n\ \ \ \ \ \ \ \ \ set\ font2\ \[list\ Helvetica\ \[expr\ \$boxwidth/2\]\]\n\n\ \ \ \ \ \ \ \ \ set\ text\ \"0\"\n\ \ \ \ \ \ \ \ \ #set\ text\ \"K\"\n\ \ \ \ \ \ \ \ \ set\ texter\ \[xpop\ 1\ \]\n\ \ \ \ \ \ \ \ \ set\ tilename\ \ \[expr\ \{int(rand()*1000000000.)\}\]\n\ \ \ \ \ \ \ \ #\ create\ the\ boxes\n\ \ \ \ \ \ \ \ set\ boxid\ \[\$w\ create\ oval\ \$x1\ \$y1\ \$x2\ \$y2\ \\\n\ \ \ \ \ \ \ \ \ \ -fill\ \$color\ -tags\ \[concat\ mv\ rect\ \$args\ \ obj_\$tilename\]\\\n\ \ \ \ \ \ \ \ \ \ -outline\ black\]\n\ \ \ \ \ \ \ \ set\ colorfo\ blue\n\ \ \ \ \ \ \ \ if\ \{\ \$indx\ >\ 1\ \}\ \{set\ colorfo\ red\}\n\ \ \ \ \ \ \ \ #set\ textid\ \[\$w\ create\ text\ \$x3\ \$y3\ -font\ \$font2\ -fill\ \$colorfo\ \\\n\ \ \ \ \ \ \ \ #\ \ -text\ \$text\ -tags\ \[concat\ mv\ \ \$args\ \ obj_\$tilename\]\ \ \]\n\n\ \ \ \ \ \ \ \ \ set\ textid\ \[\$w\ create\ text\ \$x3\ \$y3\ -font\ \$font2\ -fill\ \$colorfo\ \\\n\ \ \ \ \ \ \ \ \ \ -text\ \$texter\ -tags\ \[concat\ mv\ \ \$args\ \ obj_\$tilename\ \]\ \ \]\n\n\ \ \ \ \ \ \ \ #\ remember\ which\ text\ item\ goes\ with\ which\ box\ and\ what\ the\ text\ says\n\ \ \ \ \ \ \ \ set\ boxes(\$boxid)\ \[list\ \$textid\ \$text\]\n\ \ \ \ \ \ \ \ set\ ids(\$textid)\ \$boxid\n\ \ \ \ \ \ \ \ set\ ids(\$boxid)\ \$boxid\n\ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \}\ \ \n\ \ \ \ \ populateCanvas\ .cv\ 6\ 6\ 1\ \n\ \ \ \ \ \ \ \ #start\ of\ deck\n\n\ \ \ \ #end\ of\ deck\n\ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\ \ \ \ \ \ \n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ #end\ of\ deck\n======\n\n****Version\ with\ added\ hacks\ and\ pegboard****\n\n======\n\ \ \ \ #start\ of\ deck\n\ \ \ \ \ \ \ \ #start\ of\ deck\n\ \ \ \ \ \ \ \ #start\ of\ deck\ \n\ \ \ #!/bin/sh\n\n\ \ \ #!/bin/sh\n\ #\ Restart\ with\ tcl:\ -*-\ mode:\ tcl\;\ tab-width:\ 4\;\ -*-\ \\\n\ exec\ wish\ \$0\ \$\{1+\"\$@\"\}\n\n\ #\ demo2-canvas.tcl\ -\ HaJo\ Gurt\ -\ 2005-12-13\ -\ http://wiki.tcl.tk/15073\n\ #:\ CanvasDemo:\ On\ button-click,\ draw\ something\ on\ the\ canvas\n\ #\ gold\ used\ canvas\ demo\ as\ base\ for\ TCL\ \ chess\ display\ board.\n\ \n\ #\ written\ on\ Windowws\ XP\ on\ eTCL\ \n\ \ \ \ \ #\ working\ under\ TCL\ version\ 8.5.6\ and\ eTCL\ 1.0.1\ \n\ \ \ \ \ #\ gold\ on\ TCL\ WIKI\ ,\ 17Jul2010\n\n\ \ \ \ \ \ \ \ proc\ scr\ \{w\}\ \{\n\ \ \ \ \ \ \ \ console\ show\n\ \ \ \ \ \ \ \ set\ \ max\ 400\n\ \ \ \ \ \ \ \ set\ \ may\ 400\ \n\ for\ \{set\ r\ 50\}\ \{\$r\ <\ \$max\}\ \{incr\ r\ 45\}\ \{\n\ \ \ \ \ for\ \{set\ c\ 50\}\ \{\$c\ <\ \$max\}\ \{incr\ c\ 45\}\ \{\n\ \ \ \ \ \ \ \ set\ tilename\ \ \[expr\ \{int(rand()*1000000000.)\}\]\n\ \ \n\ \ \ \ \ \ \ \ \ \$w\ create\ oval\ \$r\ \$c\ \[expr\ \$r+5\]\ \[expr\ \$c+5\]\ -outline\ gray\ -fill\ green\ -width\ 1\ \\\n\ \ \ \ \ \ \ \ \ -tags\ \[concat\ mv\ xdat_\[expr\ \$r+5\]\ \ ydat_\[expr\ \$c+5\]\ obj_\$tilename\]\n\ \ \ \ \ \ \ \ \ \ \ puts\ \"\ xdat_\[expr\ \$r+5\]\ \ ydat_\[expr\ \$c+5\]\ obj_\$tilename\"\n\ \ \ \ \ \ \ \ set\ texter\ \ \"\ \ \[expr\ \$r+5\]\ \[expr\ \$c+5\]\ \ \"\n\ \ \ \ \ \ \ \$w\ create\ text\ \[expr\ \$r+5\]\ \[expr\ \$c+20\]\ \\\n\ \ \ \ \ \ \ \ \ \ -text\ \$texter\ -fill\ green\ -tags\ \"\ \ \[expr\ \$r+5\]\ \[expr\ \$c+20\]\"\n\n\ \}\}\}\n\ \n\ \ \ package\ require\ Tk\n\n\ \ proc\ ClrCanvas\ \{w\}\ \{\n\ \ \ \ \$w\ delete\ \"all\"\n\ \ \ \ \$w\ configure\ \ -bg\ white\n\ \ \}\n\n\ \ proc\ DrawAxis\ \{w\}\ \{\n\ \ \ \ set\ midX\ \[expr\ \{\ \$::maxX\ /\ 2\ \}\]\n\ \ \ \ set\ midY\ \[expr\ \{\ \$::maxY\ /\ 2\ \}\]\n\ \ \ \ \$w\ create\ line\ 0\ \ \ \ \ \$midY\ \ \$::maxX\ \ \ \$midY\ \ -tags\ \"axis\"\n\ \ \ \ \$w\ create\ line\ \$midX\ 0\ \ \ \ \ \ \ \ \$midX\ \$::maxY\ \ -tags\ \"axis\"\n\ \ \}\n\n\ \ proc\ PaintText\ \{w\ Txt\}\ \{\n\ \ \ \ global\ y\n\ \ \ \ incr\ y\ 10\n\ \ \ \ \$w\ create\ text\ 100\ \$y\ -text\ \$Txt\ -tags\ \"text\"\n\ \ \}\n\n\ \ proc\ DrawBox\ \{w\}\ \{\n\ \ \ \ global\ x1\ y1\ x2\ y2\n\ \ \ \ \$w\ create\ rect\ \ 50\ \ 50\ \ 100\ \ 90\ \ -tags\ \"box\"\n\ \ \ \ \$w\ create\ rect\ \$x1\ \$y1\ \ \$x2\ \$y2\ \ -tags\ \"box\"\n\ \ \ \ incr\ x1\ 15\n\ \ \ \ incr\ x2\ 15\n\ \ \ \ incr\ y1\ 10\n\ \ \ \ incr\ y2\ 10\n\ \ \}\n\n\ \ proc\ DrawFn1\ \{w\}\ \{\n\ \ \ \ \$w\ create\ line\ 0\ 100\ \ 50\ 200\ \ 100\ 50\ \ 150\ 70\ \ 200\ 155\ \ 250\ 50\ \ 300\ 111\ \ 350\ 222\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ -tags\ \"Fn1\"\ \ -smooth\ bezier\n\ \ \}\n\n\ \ proc\ DrawFn2\ \{w\}\ \{\n\ \ \ \ set\ offY\ 0\ \ \ \ \;#\ \[expr\ \{\ \$::maxY\ /\ 2\ \}\]\n\n\ \ \ \ for\ \{\ set\ x\ 0\ \}\ \{\ \$x\ <=\ \$::maxX\ \}\ \{\ incr\ x\ 5\ \}\ \{\n\ \ \ \ \ \ set\ y\ \[expr\ \{\ rand()\ *\ \$::maxY\ +\ \$offY\ \}\]\n\n\ \ \ \ \ #puts\ \"\$x\ \$y\"\n\ \ \ \ \ \ if\ \{\$x>0\}\ \{\ \$w\ create\ line\ \$x0\ \$y0\ \$x\ \$y\ -tags\ \"Fn2\"\ \}\n\ \ \ \ \ \ set\ x0\ \$x\n\ \ \ \ \ \ set\ y0\ \$y\n\ \ \ \ \}\n\ \ \}\n\n\ \ #:\ Main\ :\n\ \ frame\ .f1\n\ \ frame\ .f2\n\ \ pack\ \ .f1\ .f2\n\n\ \ set\ maxX\ 400\n\ \ set\ maxY\ 450\n\ \ set\ y\ \ \ \ \ \ 0\n\n\ \ set\ x1\ 120\n\ \ set\ x2\ 150\n\ \ set\ y1\ \ 50\n\ \ set\ y2\ \ 80\n\n\ \ canvas\ \ .cv\ -width\ \$maxX\ -height\ \$maxY\ \ -bg\ tan\n\ \ pack\ \ \ \ .cv\ -in\ .f1\n\ \ button\ \ .a0\ -text\ \"xiangqi\"\ -command\ \{set\ state2\ 1\;set\ state3\ 1\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 1\ \ \ \}\n\ \ button\ \ .a1\ -text\ \"west*\"\ -command\ \{unset\ state3\;set\ state3\ 3\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 3\ \ \ \}\n\ \ button\ \ .a2\ -text\ \"@\"\ -command\ \{unset\ state3\;set\ state3\ 3\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 2\ \ \ \}\n\ \ button\ \ .a3\ -text\ \"&\"\ -command\ \{\ \ ClrCanvas\ .cv\;scr\ .cv\ \ \ \}\n\ \ button\ \ .a4\ -text\ \"?\"\ -command\ \{\ \ squarenames\ .cv\;\ refreshgrid\ .cv\ 1\ \ \}\n\ \ \ button\ \ .b0\ -text\ \"C\"\ -command\ \{\ ClrCanvas\ .cv\ \}\n\ \ button\ \ .b1\ -text\ \"Text\"\ \ -command\ \{\ PaintText\ .cv\ \"Chinese\ Xiangqi\ Chess\"\ \}\n\ \ button\ \ .b2\ -text\ \"+\"\ \ -command\ \{\ DrawAxis\ \ .cv\ \}\n\ \ button\ \ .b3\ -text\ \"\\\[\\\]\"\ \ \ -command\ \{\ DrawBox\ \ \ .cv\ \}\n\ \n\ \ button\ \ .b6\ -text\ \"#dn\"\ \ \ -command\ \{\ refreshgrid\ .cv\ 2\ \}\ \ \ \n\n\ \ button\ \ .b7\ -text\ \"#up\"\ \ \ -command\ \{\ refreshgrid\ .cv\ 1\ \}\ \n\ \ button\ \ .b8\ -text\ \"#^\"\ \ \ -command\ \{.cv\ scale\ all\ 0\ 0\ 1.1\ 1.1\ \}\n\ \ button\ \ .b9\ -text\ \"#<\"\ \ \ -command\ \{.cv\ scale\ all\ 0\ 0\ .9\ .9\ \}\ \ \n\ \ button\ \ .b10\ -text\ \"x\"\ \ \ -command\ \{\ exit\ \ \ \ \}\n\ \ \ set\ info\ \"000\ 000\"\n\ \ \ label\ \ .info\ -textvar\ info\ -just\ left\n\ \ pack\ .a0\ .a1\ .a2\ .a3\ .a4\ .b0\ .b1\ .b2\ .b3\ \ .b6\ .b7\ .b8\ .b9\ .b10\ .info\ -in\ .f2\ \ -side\ left\ -padx\ 2\n\n\ \ \ #catch\ \{console\ show\}\n\ \ \ set\ oscwidth\ 1000\ \n\ set\ oschorizontal\ 500\ \n\ proc\ loop\ \{from\ to\ body\}\ \{\n\ \ \ \ upvar\ 1\ i\ i\ \;#\ make\ index\ visible\ in\ body\n\ \ \ \ for\ \{set\ i\ \$from\}\ \{\$i<\$to\}\ \{incr\ i\}\ \{uplevel\ 1\ \$body\}\n\ \}\n\ \ \ #--\ And\ likewise,\ a\ shortcut\ for\ addition:\n\ proc\ +\ \{a\ b\}\ \{expr\ \{\$a+\$b\}\}\n\ \n\ #pack\ \[canvas\ .cv\ -width\ 400\ -height\ 500\ \]\n\n\ \ \ \ #\ focus\ .cv\ \n\ set\ state2\ 1\n\ proc\ refreshgrid\ \{\ w\ state2\}\ \{\n\ global\ oscwidth\ oschorizontal\ colorite\n\ global\ grid\n\ \ global\ ind\ indx\n\ \ set\ ind\ 0\n\ \ set\ indx\ 0\n\ \ \ \ set\ colorite\ blue\ \n\ \ \ \n\n\n\nset\ dx\ 45\ \ \ \ \;#\ pixels\ between\ adjacent\ vertical\ grid\ lines\nset\ dy\ 45\ \ \ \ \;#\ pixels\ between\ adjacent\ horizontal\ grid\ lines\nset\ x0\ 30\ \ \ \ \;#\ pixels\ between\ left\ of\ canvas\ and\ left\ of\ grid\nset\ y0\ 30\ \ \ \ \;#\ pixels\ between\ top\ of\ canvas\ and\ top\ of\ grid\n#set\ win\ \$w\ \ \ \;#\ name\ of\ canvas\ widget\nforeach\ i\ \{0\ 8\}\ \{\n\ \ \ \ \$w\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \$y0\\\n\ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{9\ *\ \$dy\ +\ \$y0\}\]\ -width\ 2\ -fill\ blue\ -tag\ grid\n\}\nfor\ \{set\ i\ 1\}\ \{\$i\ <\ 8\}\ \{incr\ i\}\ \{\n\ \ \ \ \$w\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \$y0\\\n\ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{4\ *\ \$dy\ +\ \$y0\}\]\ -width\ 2\ -fill\ blue\ -tag\ grid\n\ \ \ \ \$w\ create\ line\ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{5\ *\ \$dy\ +\ \$y0\}\]\\\n\ \ \ \ \[expr\ \{\$i\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{9\ *\ \$dy\ +\ \$y0\}\]\ -width\ 2\ -fill\ blue\ -tag\ grid\n\}\nfor\ \{set\ i\ 0\}\ \{\$i\ <\ 10\}\ \{incr\ i\}\ \{\n\ \ \ \ \$w\ create\ line\ \$x0\ \[expr\ \{\$i\ *\ \$dy\ +\ \$y0\}\]\\\n\ \ \ \ \[expr\ \{8\ *\ \$dx\ +\ \$x0\}\]\ \[expr\ \{\$i\ *\ \$dy\ +\ \$y0\}\]\ -width\ 2\ -fill\ blue\ -tag\ grid\n\}\n\n\ .cv\ itemconfigure\ grid\ -fill\ blue\ \n\n\ if\ \{\ \$state2\ ==\ 1\ \}\ \{\ .cv\ raise\ grid\ \;\}\ \n\ if\ \{\ \$state2\ ==\ 2\ \}\ \{\ .cv\ lower\ grid\ \;\}\ \n\ \}\n\n\ \ refreshgrid\ \ .cv\ \$state2\ \n\ #\ next\ lines\ start\ withn\ periods,\ but\ hard\ to\ see\n\ .\ configure\ -borderwidth\ 0\ -highlightthickness\ 0\ -takefocus\ 0\ -background\ aquamarine4\n\ .\ configure\ -background\ palegreen\ -highlightcolor\ DarkOliveGreen\ -relief\ raised\ -border\ 30\n\n\ .\ configure\ -background\ palegreen\ -highlightcolor\ DarkOliveGreen\ -relief\ raised\ -border\ 30\n\ .\ configure\ -width\ 1000\ -height\ 2000\n\n\ \ \ \ \ .cv\ bind\ mv\ <ButtonRelease-1>\ \{set\ info\ \"\ %x\ %y\ \"\;\n\ \ \ \ \ \ \ \ catch\ \{.cv\ itemconfigure\ \[lindex\ \$id\ 0\]\ -outline\ black\ -width\ 1\ \}\n\ \ \ \ \}\n\n\ \ .cv\ bind\ all\ <1>\ \{set\ p(X)\ \[.cv\ canvasx\ %x\]\;\ set\ p(Y)\ \[.cv\ canvasy\ %y\]\;set\ info\ \"\ %x\ %y\ \"\}\n\ set\ haloo\ 50\n\ .cv\ bind\ mv\ <B1-Motion>\ \{mv\ .cv\ %x\ %y\}\n\ #.cv\ bind\ mv\ <ButtonRelease-1>\ \{set\ info\ \"\ %x\ %y\ \"\;puts\ \"\ nearest\ \[.cv\ find\ closest\ \ %x\ %y\ \$haloo\ \]\"\}\n\ #.cv\ bind\ moveable\ <ButtonPress-1>\ \{item:move\ %W\ %x\ %y\ 1\;set\ info\ \"\ %x\ %y\ \"\}\n\ \ \ \ \ \ bind\ .cv\ <Motion>\ \{wm\ title\ .\ \"Xiangqi\ Chessboard\ \[expr\ int(\ \[%W\ canvasx\ %x\])\],\[expr\ int\ (\[%W\ canvasy\ \n\n\ %y\])\]\"\}\n\n\ \ \ \ \ proc\ mv\ \{w\ x\ y\}\ \{\n\ \ \ \ global\ p\ id\n\ \ \ \ set\ x\ \ \[\$w\ canvasx\ \$x\]\n\ \ \ \ set\ y\ \ \[\$w\ canvasy\ \$y\]\n\ \ \ \ set\ id\ \[\$w\ find\ withtag\ current\]\n\ \ \ \ set\ numberx\ \[\$w\ \ gettags\ current\]\n\ \ \ \ regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ \n\ \ \ \ puts\ \"1\"\n\ \ \ \ puts\ \$numberx\n\ \ \ \ puts\ \$tilex\n\ \ \ \ puts\ \"\ with\ tag\ \[\$w\ find\ withtag\ obj_\$tilex\ \]\"\n\ \ \ \ foreach\ item\ \[\$w\ find\ withtag\ obj_\$tilex\ \]\ \{\n\ \ \ \ \$w\ move\ \$item\ \[expr\ \{\$x-\$p(X)\}\]\ \[expr\ \{\$y-\$p(Y)\}\]\n\ \ \ \ catch\ \{\$w\ itemconfigure\ \[lindex\ \$id\ 0\]\ -outline\ purple\ -width\ 5\ \}\n\ \ \ \ #\$w\ raise\ \$id\n\ \ \ \ \}\n\ \ \ \ puts\ \"\ x\ y\ \$x\ \$y\"\n\ \ \ \ #\$w\ raise\ \$id\n\ \ \ \ #\ \$w\ move\ \[\$w\ find\ withtag\ \"\$tilex\"\]\ \[expr\ \{\$x-\$p(X)\}\]\ \[expr\ \{\$y-\$p(Y)\}\]\n\ \ \ \ #set\ numberx\ \[\$w\ \ gettags\ current\]\n\ \ \ \ #regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ \ catch\ \{\$w\ itemconfigure\ \[lindex\ \$id\ 0\]\ -outline\ purple\ -width\ 5\ \}\n\ \ \ \ set\ p(X)\ \$x\;\ set\ p(Y)\ \$y\n\ \}\n\n\ \ \ \ proc\ board\ \{w\}\ \{\n\ \ \ \ #set\ state3\ 1\n\ \ \ \ set\ state2\ 1\n\ \ \ \ ClrCanvas\ \$w\n\ \ \ \ .\ configure\ -background\ orange\ -highlightcolor\ brown\ -relief\ raised\ -border\ 30\n\ \ \ \ \$w\ configure\ -bg\ tan\n\ \ \ \ \ \n\ \ \ \ refreshgrid\ \ .cv\ \$state2\ \;\n\ \ \ \ \}\n\ \ \ \n\ \ \ \ \ proc\ squarenames\ \{l\}\ \{\n\ \ \ \ console\ show\n\ \ \ \ set\ result\ \{\}\n\ \ \ \ set\ i\ \[llength\ \$l\]\n\ \ \ \ \ \ \ \ set\ cc\ 0\n\ \ \ \ \ \ \ \ set\ rr\ 0\n\ \ \ \ \ \ \ \ foreach\ row\ \{8\ 7\ 6\ 5\ 4\ 3\ 2\ 1\}\ \{\n\ \ \ \ \ \ \ \ set\ rowscreen\ \[expr\ \{\$rr*50.\}\]\n\ \ \ \ \ \ \ \ foreach\ column\ \{A\ B\ C\ D\ E\ F\ G\ H\}\ \{\n\ \ \ \ \ \ \ \ set\ colscreen\ \ \[expr\ \{\$cc*50.\}\]\ \ \ \n\ \ \ \ \ \ \ \ lappend\ result\ \ \ \"\$column\$row\ \$rowscreen\ \$colscreen\"\n\ \ \ \ \ \ \ \ incr\ cc\ 1\n\ \ \ \ \ \ \ \ incr\ rr\ 1\n\ \ \ \ \ \ \ \ \ \}\}\n\ \ \ \ puts\ \$result\n\ \ \ \ return\ \$result\n\ \ \ \ \n\ \ \ \}\n\ \ \ \ \ \ \n\ \ \ \ \ \ \ \ #foreach\ row\ \{8\ 7\ 6\ 5\ 4\ 3\ 2\ 1\}\ \{\n\ \ \ \ \ \ \ \ #foreach\ column\ \{A\ B\ C\ D\ E\ F\ G\ H\}\ \{\n\ \ \ \ \ \ \ \ #\ \ \ \ lappend\ res\ \[\"\ \"\ \"\$column\$row\"\]\n\ \ \ \ \ \ \ \ #puts\ \"\ \ \$column\$row\ \"\n\ \ \n\ \ \ \ proc\ gamepieces\ \{state3\}\ \{\n\ \ \ \ \ global\ bluepieces\ redpieces\n\ \ \ \ \ if\ \{\ \$state3\ ==\ 2\ \}\ \{\ \n\ \ \ \ \ set\ bluepieces\ \[list\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]\n\ \ \ \ \ set\ redpieces\ \ \[list\ 0\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]\n\ \ \ \ \ \ \ \}\ \n\ \ \ \ \ \n\ \ \ \ if\ \{\ \$state3\ ==\ 3\ \}\ \{\ \n\ \ \ \ \ #black\ western\n\ \ \ \ \ set\ bluepieces\ \{\ \ \\u265A\ \\u265B\ \\u265C\ \\u265C\ \\u265D\ \\u265D\ \\u265E\ \\u265E\ \\u265F\ \\u265F\ \\u265F\ \\u265F\ \n\n\\u265F\ \\u265F\ \\u265F\ \\u265F\}\ \ \n\ \ \ \ \ #white\ western\n\ \ \ \ \ set\ redpieces\ \{\ 0\ \ \\u2654\ \\u2655\ \\u2655\ \\u2656\ \ \\u2656\ \\u2657\ \\u2657\ \ \\u2658\ \\u2658\ \\u2659\ \\u2659\ \n\n\\u2659\ \n\n\ \\u2659\ \\u2659\ \\u2659\ \\u2659\ \\u2659\}\ \ \n\ \ \ \ \ \ \ \}\n\ \ \ \ \ \ if\ \{\ \$state3\ ==\ 1\ \}\ \{\ \n\ \ \ \ \ \ set\ bluepieces\ \{\\u5C07\ \\u58EB\ \ \\u58EB\ \ \\u8C61\ \\u8C61\ \\u99AC\ \\u99AC\ \\u8ECA\ \\u8ECA\ \ \ \\u7832\ \ \ \\u7832\ \ \ \ \n\n\\u5352\ \\u5352\ \\u5352\ \ \ \\u5352\ \\u5352\}\n\ set\ redpieces\ \ \{\ \ 0\ \\u5E25\ \ \ \\u4ED5\ \\u4ED5\ \ \ \\u76F8\ \ \ \\u76F8\ \\u99AC\ \\u99AC\ \\u8ECA\ \\u8ECA\ \ \ \ \ \ \\u70AE\ \ \n\n\\u70AE\ \n\n\ \\u5175\ \ \\u5175\ \ \ \ \\u5175\ \ \ \ \ \\u5175\ \ \ \\u5175\ \ \}\ \ \n\ \ \ \ \ \}\n\ \n\ \ \ \ \ \}\n\ \ \ \ \n\ \ \ \ \ set\ ind\ 0\n\ \ \ \ \ set\ indx\ 0\n\ \ \ \ \ set\ baseline\ \{list\ 1\}\n\ \ \ \ \ \ proc\ K\ \{\ x\ y\ \}\ \{\ set\ x\ \}\n\n\ \ \ \ \ proc\ xpop\ \{\ topper\ \}\ \{\n\ \ \ \ \ global\ liner\ \n\ \ \ \ \ global\ ind\ indx\ \n\ \ \ \ \ global\ bluepieces\ redpieces\n\ \ \ \ \ global\ baseline\n\ \ \ \ \ set\ topper\ \[\ lindex\ \$bluepieces\ \$ind\ \]\;\n\ \ \ \ \ if\ \{\ \$topper\ ==\ \"\"\ \}\ \{\ \n\ \ \ \ \ set\ topper\ \[\ lindex\ \$redpieces\ \$indx\ \]\n\ \ \ \ \ set\ indx\ \[\ expr\ \{\ \$indx\ +\ 1\}\]\n\ \ \ \ \ \ \ \}\ \n\ \ \ \ \ set\ ind\ \[\ expr\ \{\ \$ind\ +\ 1\}\]\n\ \ \ \ \ lappend\ \$baseline\ \$topper\;\n\ \ \ \ \ return\ \$topper\;\n\ \ \ \ \ \}\n\ \ \ \ \ set\ state2\ 1\n\ \ \ \ \ \ \ \ \ \ proc\ populateCanvas\ \{w\ cols\ rows\ args\}\ \{\n\ \ \ \ global\ state2\ state3\n\ \ \ \ gamepieces\ \$args\n\ \ \ \ #refreshgrid\ \ \$w\ \$state2\ \n\ \ \ \ set\ state3\ \$args\n\ \ \ \ global\ ind\ indx\n\ \ \ \ variable\ ids\ \;#\ links\ text\ ids\ with\ respective\ rect\ ids\n\ \ \ \ variable\ boxes\ \;#\ lists\ text\ id\ and\ text\ associated\ with\ each\ rect\ id\n\ \ \ \ catch\ \{unset\ ids\ boxes\}\n\ \ \ \ set\ canvas\ \$w\n\ \ \ \ \n\ \ \ \ #\ parameters\ for\ drawing\ boxes\n\ \ \ \ set\ boxwidth\ 50\n\ \ \ \ set\ boxheight\ 50\n\ \ \ \ set\ padx\ 3\n\ \ \ \ set\ pady\ 3\n\ \ \ \ set\ colors\ \{\ orange\ yellow\ green\ \ gray\}\n\ \ \ \ set\ labels\ \{one\ two\ three\ four\}\n\n\ \ \ \ #\ draw\ the\ boxes\n\ \ \ \ for\ \{set\ row\ 0\}\ \{\$row\ <\ \$rows\}\ \{incr\ row\}\ \{\n\ \ \ \ \ \ for\ \{set\ col\ 0\}\ \{\$col\ <\ \$cols\}\ \{incr\ col\}\ \{\n\n\ \ \ \ \ \ \ \ #\ calculate\ coordinates\n\ \ \ \ \ \ \ \ set\ x1\ \[expr\ \{\$col\ *\ (\$boxwidth\ +\ \$padx)\ +\ \$padx\}\]\n\ \ \ \ \ \ \ \ set\ x2\ \[expr\ \{\$x1\ +\ \$boxwidth\}\]\n\ \ \ \ \ \ \ \ set\ x3\ \[expr\ \{\$x1\ +\ (\$boxwidth\ /\ 2)\}\]\n\ \ \ \ \ \ \ \ set\ y1\ \[expr\ \{\$row\ *\ (\$boxheight\ +\ \$pady)\ +\ \$pady\}\]\n\ \ \ \ \ \ \ \ set\ y2\ \[expr\ \{\$y1\ +\ \$boxheight\}\]\n\ \ \ \ \ \ \ \ set\ y3\ \[expr\ \{\$y1\ +\ (\$boxheight\ /\ 2)\}\]\n\n\ \ \ \ \ \ \ \ #\ choose\ color\ and\ text\n\ \ \ \ \ \ \ \ set\ color\ \[lindex\ \$colors\ \[expr\ \{int(rand()\ *\ \[llength\ \$colors\])\}\]\]\n\ \ \ \ \ \ \ \ #set\ text\ \[lindex\ \$labels\ \[expr\ \{int(rand()\ *\ \[llength\ \$labels\])\}\]\]\n\ \ \ \ \ \ \ \ #\ set\ text\ \[xpop\ topper\]\n\ \ \ \ \ \ \ \ \ set\ font2\ \[list\ Helvetica\ \[expr\ \$boxwidth/2\]\]\n\n\ \ \ \ \ \ \ \ \ set\ text\ \"0\"\n\ \ \ \ \ \ \ \ \ #set\ text\ \"K\"\n\ \ \ \ \ \ \ \ \ set\ texter\ \[xpop\ 1\ \]\n\ \ \ \ \ \ \ \ \ set\ tilename\ \ \[expr\ \{int(rand()*1000000000.)\}\]\n\ \ \ \ \ \ \ \ #\ create\ the\ boxes\n\ \ \ \ \ \ \ \ set\ boxid\ \[\$w\ create\ oval\ \$x1\ \$y1\ \$x2\ \$y2\ \\\n\ \ \ \ \ \ \ \ \ \ -fill\ \$color\ -tags\ \[concat\ mv\ rect\ \$args\ \ obj_\$tilename\]\\\n\ \ \ \ \ \ \ \ \ \ -outline\ black\]\n\ \ \ \ \ \ \ \ set\ colorfo\ blue\n\ \ \ \ \ \ \ \ if\ \{\ \$indx\ >\ 1\ \}\ \{set\ colorfo\ red\}\n\ \ \ \ \ \ \ \ #set\ textid\ \[\$w\ create\ text\ \$x3\ \$y3\ -font\ \$font2\ -fill\ \$colorfo\ \\\n\ \ \ \ \ \ \ \ #\ \ -text\ \$text\ -tags\ \[concat\ mv\ \ \$args\ \ obj_\$tilename\]\ \ \]\n\n\ \ \ \ \ \ \ \ \ set\ textid\ \[\$w\ create\ text\ \$x3\ \$y3\ -font\ \$font2\ -fill\ \$colorfo\ \\\n\ \ \ \ \ \ \ \ \ \ -text\ \$texter\ -tags\ \[concat\ mv\ \ \$args\ \ obj_\$tilename\ \]\ \ \]\n\n\n\n\ \ \ \ \ \ \ \ #\ remember\ which\ text\ item\ goes\ with\ which\ box\ and\ what\ the\ text\ says\n\ \ \ \ \ \ \ \ set\ boxes(\$boxid)\ \[list\ \$textid\ \$text\]\n\ \ \ \ \ \ \ \ set\ ids(\$textid)\ \$boxid\n\ \ \ \ \ \ \ \ set\ ids(\$boxid)\ \$boxid\n\ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \}\ \ \n\ \ \ \ \ populateCanvas\ .cv\ 6\ 6\ 1\ \n\ \ \ \ \ squarenames\ \{1\ 2\ 3\ \}\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck*\ \n\ \ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\n\ \ \ \ #end\ of\ deck\n\ \ \ \ #end\ of\ deck\n\ \ \ #end\ of\ deck\n\ \ \ #end\ of\ \ deck\n\ \ \ #end\ of\ deck\n\ \ \ #end\ of\ deck\n\ \ \ \ #end\ of\ deck\n\ \n======\n\ \ \ \n----\n'''\[arjen\]\ -\ 2010-06-29\ 03:31:13'''\n\nJust\ a\ minor\ comment:\ the\ characters\ are\ simplified\ Chinese,\ I\ am\ not\ sure\ that\ is\ what\ you\ would\ encounter\ on\ a\ real\ chessboard.\n\n----\ \n\[gold\]#\ \ May\ just\ use\ English\ letters\ initially\ and\ switch\ for\ option\ of\ simplified\ or\ traditional\ characters.\n\n\[gold\]\ 1jul2010,\ There\ are\ Xiangqi\ sets\ with\ simplified\ characters\ made\ in\ PRC,\nbut\ probably\ not\ common\ elsewhere.\ Really\ lacking\ though,\ are\nspecific\ unicode\ fonts\ for\ Xiangqi.\ Meanwhile\ code\ will\ make\ do\ with\nlanguage\ fonts.\ \n\n----\n\[AMG\]:\ A\ note\ concerning\ the\ \[\[\[list\]\]\]\ command:\ It's\ not\ necessary\ to\ use\ \[\[list\]\]\ if\ none\ of\ the\ elements\ are\ the\ product\ of\ substitution.\ \ In\ other\ words,\ if\ the\ list\ will\ always\ have\ the\ same\ elements,\ you\ don't\ need\ the\ \[\[list\]\]\ command\ to\ construct\ the\ list.\ \ Instead\ simply\ surround\ the\ list\ with\ \{braces\}.\ \ Its\ internal\ representation\ will\ become\ list\ when\ it\ gets\ used\ as\ a\ list,\ since\ Tcl\ has\ \[duck\ typing\].\ \ Similar\ goes\ for\ \[\[\[dict\ create\]\]\].\ \ I\ mean,\ when\ you\ want\ a\ number,\ you\ just\ type\ the\ number,\ even\ though\ its\ initial\ internal\ representation\ will\ be\ string.\ \ It\ \"becomes\"\ a\ number\ when\ context\ shows\ that\ it\ is\ a\ number.\ \ You\ never\ see\ code\ that\ does\ this:\ `set\ var\ \[\[expr\ 5\]\]`\;\ only\ this:\ `set\ var\ 5`.\n\n***test\ on\ chess\ and\ xiangqi\ fonts***\n\ \n\ \ \ \ \ ***set\ bluepieces\ \ \{將士\ \ 士將\ \ 象\ 象\ 馬\ 馬\ 車\ 車\ \ \ 砲\ \ \ 砲\ \ \ \ 卒\ 卒卒\ \ \ 卒卒\ \ \ \]#trad.\ \ \ \ \n\ \ \ \ \n\ \ \ \ \ ***set\ redpieces\ \ \{\ \ 帥\ \ \ 仕\ \ 象\ 象\ \ 相\ \ \ 相\ 馬\ 馬\ 車\ 車\ 砲\ 砲\ \ \ 兵炮\ \ 炮\ \ 兵\ \ \ \ \ 兵\ \ \ \ \ 兵\ \ \ 兵\ \ \ \]\ #trad\n\ \ \ \n\ \ \ \ \ ***set\ bluepieces\ \ \{王\ 王\ 王\ 象\ 象\ 马\ 马\ 车\ 车\ \ 炮\ 炮\ \ 典\ 典\ 典\ 典\ 典\ 典\}***#simplified\n\ \ \ \ \ ***set\ redpieces\ \ \{王\ 王\ 王\ 象\ 象\ 马\ 马\ 车\ 车\ \ 炮\ 炮\ \ 典\ 典\ 典\ 典\ 典\ 典\}***simplified\n\ \ \ \ \ set\ bluepieces\ \{K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]#english\ letters\n\ \ \ \ \ set\ redpieces\ \ \{K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]#english\ letters\n\n\ babelfish\ gives炮\n***国王一般普通话大象马运输车大炮战士典当***\n\ from\ \nking\ general\ mandarin\ elephant\nhorse\ chariot\ cannon\ soldier\ pawn,\n\ \ \ #\ probably\ need\ an\ if\ switch\ option\ for\ TCL\ lists\ \ \n\ \ \ \ \ \n\ \ \ \ \ ***set\ bluepieces\ \ \[list\ \ 將士\ \ 士將\ \ 象\ 象\ 馬\ 馬\ 車\ 車\ \ \ 砲,\ \ 砲,\ \ \ 卒\ 卒卒\ \ \ 卒卒\ \ \ \]#trad.\ \ \ \ \n\ \ \ \ \n\ \ \ \ \ ***set\ redpieces\ \ \[list\ \ 帥\ \ \ 仕,\ 象\ 象\ \ 相\ \ \ 相\ 馬\ 馬\ 車\ 車\ 砲\ 砲\ \ \ 兵炮\ \ 炮\ \ 兵\ \ \ \ \ 兵\ \ \ \ \ 兵\ \ \ 兵\ \ \ \]\ #trad\n\ \ \ \ \n\n\ \ \ 將\ King\ \ \ 士\ 士Adviser\ 車\ 車chaRiot\ \ \  \ \ 馬\ 馬Horse\ \ \ 炮\ \ 炮Cannon \ \ \ \ \ 象象\ Elephant卒 卒\ 卒\ 卒\ 卒Pawn\n \ \ \ \ \ 帥\ \ \ King\ \ \ \ \ \ \ \  仕\  仕\ Adviser\ 車\ \ \ 車\ \ chaRiot\ \ \  馬\  馬\ \ \ Horse\ 炮\ 炮\ \ Cannon 仕\  仕\ \ \ \ \ \ Elephant 兵\ \ 兵兵兵兵\ Pawn\n\ \n\ \ \ \ \ ***set\ bluepieces\ \ \[list\ 王\ 王\ 王\ 象\ 象\ 马\ 马\ 车\ 车\ \ 炮\ 炮\ \ 典\ 典\ 典\ 典\ 典\ 典\]***#simplified\n\ \ \ \ \ ***set\ redpieces\ \ \[list\ 王\ 王\ 王\ 象\ 象\ 马\ 马\ 车\ 车\ \ 炮\ 炮\ \ 典\ 典\ 典\ 典\ 典\ 典\]***simplified\n\ \ \ \ \ set\ bluepieces\ \[list\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]#english\ letters\n\ \ \ \ \ set\ redpieces\ \ \[list\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]#english\ letters\n\n\n***♔','♕','♖','♗','♘','♙','♚','♛','♜','♝','♞','♟'***\n\n***gummy\ version\ with\ \ purple\ highlights\ on\ moving\ pieces.***\n======\n\ \ \ \ #start\ of\ deck\n\ \ \ \ \ \ \ \ #start\ of\ deck\n\ \ \ \ \ \ \ \ #start\ of\ deck\ \n\ \ \ #!/bin/sh\n\n\ \ \ #!/bin/sh\n\ #\ Restart\ with\ tcl:\ -*-\ mode:\ tcl\;\ tab-width:\ 4\;\ -*-\ \\\n\ exec\ wish\ \$0\ \$\{1+\"\$@\"\}\n\n\ #\ demo2-canvas.tcl\ -\ HaJo\ Gurt\ -\ 2005-12-13\ -\ http://wiki.tcl.tk/15073\n\ #:\ CanvasDemo:\ On\ button-click,\ draw\ something\ on\ the\ canvas\n\ #\ gold\ used\ canvas\ demo\ as\ base\ for\ TCL\ \ chess\ display\ board.\n\ \n\n\ \ \ \ \ \ \ \ proc\ scr\ \{w\}\ \{\n\ \ \ \ \ \ \ \ console\ show\n\ \ \ \ \ \ \ \ set\ \ max\ 400\n\ \ \ \ \ \ \ \ set\ \ may\ 400\ \n\ for\ \{set\ r\ 50\}\ \{\$r\ <\ \$max\}\ \{incr\ r\ 45\}\ \{\n\ \ \ \ \ for\ \{set\ c\ 50\}\ \{\$c\ <\ \$max\}\ \{incr\ c\ 45\}\ \{\n\ \ \ \ \ \ \ \ set\ tilename\ \ \[expr\ \{int(rand()*1000000000.)\}\]\n\ \ \n\ \ \ \ \ \ \ \ \ \$w\ create\ oval\ \$r\ \$c\ \[expr\ \$r+5\]\ \[expr\ \$c+5\]\ -outline\ gray\ -fill\ green\ -width\ 1\ \\\n\ \ \ \ \ \ \ \ \ -tags\ \[concat\ mv\ xdat_\[expr\ \$r+5\]\ \ ydat_\[expr\ \$c+5\]\ obj_\$tilename\]\n\ \ \ \ \ \ \ \ \ \ \ puts\ \"\ xdat_\[expr\ \$r+5\]\ \ ydat_\[expr\ \$c+5\]\ obj_\$tilename\"\n\ \ \ \ \ \ \ \ set\ texter\ \ \"\ \ \[expr\ \$r+5\]\ \[expr\ \$c+5\]\ \ \"\n\ \ \ \ \ \ \ \$w\ create\ text\ \[expr\ \$r+5\]\ \[expr\ \$c+20\]\ \\\n\ \ \ \ \ \ \ \ \ \ -text\ \$texter\ -fill\ green\ -tags\ \"\ \ \[expr\ \$r+5\]\ \[expr\ \$c+20\]\"\n\n\ \}\}\}\n\ \n\ \ \ package\ require\ Tk\n\n\ \ proc\ ClrCanvas\ \{w\}\ \{\n\ \ \ \ \$w\ delete\ \"all\"\n\ \ \ \ \$w\ configure\ \ -bg\ white\n\ \ \}\n\n\ \ proc\ DrawAxis\ \{w\}\ \{\n\ \ \ \ set\ midX\ \[expr\ \{\ \$::maxX\ /\ 2\ \}\]\n\ \ \ \ set\ midY\ \[expr\ \{\ \$::maxY\ /\ 2\ \}\]\n\ \ \ \ \$w\ create\ line\ 0\ \ \ \ \ \$midY\ \ \$::maxX\ \ \ \$midY\ \ -tags\ \"axis\"\n\ \ \ \ \$w\ create\ line\ \$midX\ 0\ \ \ \ \ \ \ \ \$midX\ \$::maxY\ \ -tags\ \"axis\"\n\ \ \}\n\n\ \ proc\ PaintText\ \{w\ Txt\}\ \{\n\ \ \ \ global\ y\n\ \ \ \ incr\ y\ 10\n\ \ \ \ \$w\ create\ text\ 100\ \$y\ -text\ \$Txt\ -tags\ \"text\"\n\ \ \}\n\n\ \ proc\ DrawBox\ \{w\}\ \{\n\ \ \ \ global\ x1\ y1\ x2\ y2\n\ \ \ \ \$w\ create\ rect\ \ 50\ \ 50\ \ 100\ \ 90\ \ -tags\ \"box\"\n\ \ \ \ \$w\ create\ rect\ \$x1\ \$y1\ \ \$x2\ \$y2\ \ -tags\ \"box\"\n\ \ \ \ incr\ x1\ 15\n\ \ \ \ incr\ x2\ 15\n\ \ \ \ incr\ y1\ 10\n\ \ \ \ incr\ y2\ 10\n\ \ \}\n\n\ \ proc\ DrawFn1\ \{w\}\ \{\n\ \ \ \ \$w\ create\ line\ 0\ 100\ \ 50\ 200\ \ 100\ 50\ \ 150\ 70\ \ 200\ 155\ \ 250\ 50\ \ 300\ 111\ \ 350\ 222\\\n\ \ \ \ \ \ \ \ \ \ \ \ \ -tags\ \"Fn1\"\ \ -smooth\ bezier\n\ \ \}\n\n\ \ proc\ DrawFn2\ \{w\}\ \{\n\ \ \ \ set\ offY\ 0\ \ \ \ \;#\ \[expr\ \{\ \$::maxY\ /\ 2\ \}\]\n\n\ \ \ \ for\ \{\ set\ x\ 0\ \}\ \{\ \$x\ <=\ \$::maxX\ \}\ \{\ incr\ x\ 5\ \}\ \{\n\ \ \ \ \ \ set\ y\ \[expr\ \{\ rand()\ *\ \$::maxY\ +\ \$offY\ \}\]\n\n\ \ \ \ \ #puts\ \"\$x\ \$y\"\n\ \ \ \ \ \ if\ \{\$x>0\}\ \{\ \$w\ create\ line\ \$x0\ \$y0\ \$x\ \$y\ -tags\ \"Fn2\"\ \}\n\ \ \ \ \ \ set\ x0\ \$x\n\ \ \ \ \ \ set\ y0\ \$y\n\ \ \ \ \}\n\ \ \}\n\n\ \ #:\ Main\ :\n\ \ frame\ .f1\n\ \ frame\ .f2\n\ \ pack\ \ .f1\ .f2\n\n\ \ set\ maxX\ 400\n\ \ set\ maxY\ 400\n\ \ set\ y\ \ \ \ \ \ 0\n\n\ \ set\ x1\ 120\n\ \ set\ x2\ 150\n\ \ set\ y1\ \ 50\n\ \ set\ y2\ \ 80\n\n\ \ canvas\ \ .cv\ -width\ \$maxX\ -height\ \$maxY\ \ -bg\ tan\n\ \ pack\ \ \ \ .cv\ -in\ .f1\n\ \ button\ \ .a0\ -text\ \"xiangqi\"\ -command\ \{set\ state2\ 1\;set\ state3\ 1\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 1\ \ \ \}\n\ \ button\ \ .a1\ -text\ \"west*\"\ -command\ \{unset\ state3\;set\ state3\ 3\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 3\ \ \ \}\n\ \ button\ \ .a2\ -text\ \"@\"\ -command\ \{unset\ state3\;set\ state3\ 3\;board\ .cv\;populateCanvas\ .cv\ 6\ 6\ 2\ \ \ \}\n\ \ button\ \ .a3\ -text\ \"&\"\ -command\ \{\ \ ClrCanvas\ .cv\;scr\ .cv\ \ \ \}\n\ \ button\ \ .b0\ -text\ \"C\"\ -command\ \{\ ClrCanvas\ .cv\ \}\n\ \ button\ \ .b1\ -text\ \"Text\"\ \ -command\ \{\ PaintText\ .cv\ \"Chinese\ Xiangqi\ Chess\"\ \}\n\ \ button\ \ .b2\ -text\ \"+\"\ \ -command\ \{\ DrawAxis\ \ .cv\ \}\n\ \ button\ \ .b3\ -text\ \"\\\[\\\]\"\ \ \ -command\ \{\ DrawBox\ \ \ .cv\ \}\n\ \n\ \ button\ \ .b6\ -text\ \"#dn\"\ \ \ -command\ \{\ refreshgrid\ .cv\ 2\ \}\ \ \ \n\n\ \ button\ \ .b7\ -text\ \"#up\"\ \ \ -command\ \{\ refreshgrid\ .cv\ 1\ \}\ \n\ \ button\ \ .b8\ -text\ \"#^\"\ \ \ -command\ \{.cv\ scale\ all\ 0\ 0\ 1.1\ 1.1\ \}\n\ \ button\ \ .b9\ -text\ \"#<\"\ \ \ -command\ \{.cv\ scale\ all\ 0\ 0\ .9\ .9\ \}\ \ \n\ \ button\ \ .b10\ -text\ \"x\"\ \ \ -command\ \{\ exit\ \ \ \ \}\n\ \ \ set\ info\ \"000\ 000\"\n\ \ \ label\ \ .info\ -textvar\ info\ -just\ left\n\ \ pack\ .a0\ .a1\ .a2\ .a3\ .b0\ .b1\ .b2\ .b3\ \ .b6\ .b7\ .b8\ .b9\ .b10\ .info\ -in\ .f2\ \ -side\ left\ -padx\ 2\n\n\ \ \ #catch\ \{console\ show\}\n\ \ \ set\ oscwidth\ 1000\ \n\ set\ oschorizontal\ 500\ \n\ proc\ loop\ \{from\ to\ body\}\ \{\n\ \ \ \ upvar\ 1\ i\ i\ \;#\ make\ index\ visible\ in\ body\n\ \ \ \ for\ \{set\ i\ \$from\}\ \{\$i<\$to\}\ \{incr\ i\}\ \{uplevel\ 1\ \$body\}\n\ \}\n\ \ \ #--\ And\ likewise,\ a\ shortcut\ for\ addition:\n\ proc\ +\ \{a\ b\}\ \{expr\ \{\$a+\$b\}\}\n\ \n\ #pack\ \[canvas\ .cv\ -width\ 400\ -height\ 500\ \]\n\n\ \ \ \ #\ focus\ .cv\ \n\ set\ state2\ 1\n\ proc\ refreshgrid\ \{\ .cv\ state2\}\ \{\n\ global\ oscwidth\ oschorizontal\ colorite\n\ global\ grid\n\ \ global\ ind\ indx\n\ \ set\ ind\ 0\n\ \ set\ indx\ 0\n\ \ \ \ set\ colorite\ blue\ \n\ \ \ \ for\ \{set\ x\ 10\}\ \{\$x<\$oscwidth\}\ \{incr\ x\ 50\}\ \{.cv\ create\ line\ \$x\ 0\ \$x\ \$oschorizontal\ \ -fill\ blue\ -tag\ grid\ -\n\nwidth\ 4\}\n\ for\ \{set\ y\ 20\}\ \{\$y<\$oschorizontal\}\ \{incr\ y\ 50\}\ \{.cv\ create\ line\ 0\ \$y\ \$oschorizontal\ \$y\ -fill\ blue\ \ -tag\ grid\ \n\n-width\ 4\}\ \n\ .cv\ itemconfigure\ grid\ -fill\ blue\ \n\n\ if\ \{\ \$state2\ ==\ 1\ \}\ \{\ .cv\ raise\ grid\ \;\}\ \n\ if\ \{\ \$state2\ ==\ 2\ \}\ \{\ .cv\ lower\ grid\ \;\}\ \n\ \}\n\n\ \ refreshgrid\ \ .cv\ \$state2\ \n\ #\ next\ lines\ start\ withn\ periods,\ but\ hard\ to\ see\n\ .\ configure\ -borderwidth\ 0\ -highlightthickness\ 0\ -takefocus\ 0\ -background\ aquamarine4\n\ .\ configure\ -background\ palegreen\ -highlightcolor\ DarkOliveGreen\ -relief\ raised\ -border\ 30\n\n\ .\ configure\ -background\ palegreen\ -highlightcolor\ DarkOliveGreen\ -relief\ raised\ -border\ 30\n\ .\ configure\ -width\ 1000\ -height\ 2000\n\n\ \ \ \ \ .cv\ bind\ mv\ <ButtonRelease-1>\ \{set\ info\ \"\ %x\ %y\ \"\;\n\ \ \ \ \ \ \ \ catch\ \{.cv\ itemconfigure\ \[lindex\ \$id\ 0\]\ -outline\ black\ -width\ 1\ \}\n\ \ \ \ \}\n\n\ \ .cv\ bind\ all\ <1>\ \{set\ p(X)\ \[.cv\ canvasx\ %x\]\;\ set\ p(Y)\ \[.cv\ canvasy\ %y\]\;set\ info\ \"\ %x\ %y\ \"\}\n\ set\ haloo\ 50\n\ .cv\ bind\ mv\ <B1-Motion>\ \{mv\ .cv\ %x\ %y\}\n\ #.cv\ bind\ mv\ <ButtonRelease-1>\ \{set\ info\ \"\ %x\ %y\ \"\;puts\ \"\ nearest\ \[.cv\ find\ closest\ \ %x\ %y\ \$haloo\ \]\"\}\n\ #.cv\ bind\ moveable\ <ButtonPress-1>\ \{item:move\ %W\ %x\ %y\ 1\;set\ info\ \"\ %x\ %y\ \"\}\n\ \ \ \ \ \ bind\ .cv\ <Motion>\ \{wm\ title\ .\ \"Xiangqi\ Chessboard\ \[expr\ int(\ \[%W\ canvasx\ %x\])\],\[expr\ int\ (\[%W\ canvasy\ \n\n%y\])\]\"\}\n\n\ \ \ \ \ proc\ mv\ \{w\ x\ y\}\ \{\n\ \ \ \ global\ p\ id\n\ \ \ \ set\ x\ \ \[\$w\ canvasx\ \$x\]\n\ \ \ \ set\ y\ \ \[\$w\ canvasy\ \$y\]\n\ \ \ \ set\ id\ \[\$w\ find\ withtag\ current\]\n\ \ \ \ set\ numberx\ \[\$w\ \ gettags\ current\]\n\ \ \ \ regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ \n\ \ \ \ puts\ \"1\"\n\ \ \ \ puts\ \$numberx\n\ \ \ \ puts\ \$tilex\n\ \ \ \ puts\ \"\ with\ tag\ \[\$w\ find\ withtag\ obj_\$tilex\ \]\"\n\ \ \ \ foreach\ item\ \[\$w\ find\ withtag\ obj_\$tilex\ \]\ \{\n\ \ \ \ \$w\ move\ \$item\ \[expr\ \{\$x-\$p(X)\}\]\ \[expr\ \{\$y-\$p(Y)\}\]\n\ \ \ \ catch\ \{\$w\ itemconfigure\ \[lindex\ \$id\ 0\]\ -outline\ purple\ -width\ 5\ \}\n\ \ \ \ #\$w\ raise\ \$id\n\ \ \ \ \}\n\ \ \ \ puts\ \"\ x\ y\ \$x\ \$y\"\n\ \ \ \ #\$w\ raise\ \$id\n\ \ \ \ #\ \$w\ move\ \[\$w\ find\ withtag\ \"\$tilex\"\]\ \[expr\ \{\$x-\$p(X)\}\]\ \[expr\ \{\$y-\$p(Y)\}\]\n\ \ \ \ #set\ numberx\ \[\$w\ \ gettags\ current\]\n\ \ \ \ #regexp\ \{obj_(\\d+)\}\ \$numberx\ ->\ tilex\n\ \ \ \ \ catch\ \{\$w\ itemconfigure\ \[lindex\ \$id\ 0\]\ -outline\ purple\ -width\ 5\ \}\n\ \ \ \ set\ p(X)\ \$x\;\ set\ p(Y)\ \$y\n\ \}\n\n\ \ \ \ proc\ board\ \{w\}\ \{\n\ \ \ \ #set\ state3\ 1\n\ \ \ \ set\ state2\ 1\n\ \ \ \ ClrCanvas\ \$w\n\ \ \ \ .\ configure\ -background\ orange\ -highlightcolor\ brown\ -relief\ raised\ -border\ 30\n\ \ \ \ \$w\ configure\ -bg\ tan\n\ \ \ \ \n\ \ \ \ refreshgrid\ \ .cv\ \$state2\ \;\n\ \ \ \ \}\n\ \ \ \ \n\ \ \ \ \ proc\ squarenames\ \{l\}\ \{\n\ \ \ \ console\ show\n\ \ \ \ set\ result\ \{\}\n\ \ \ \ set\ i\ \[llength\ \$l\]\n\ \ \ \ \ \ \ \ set\ cc\ 0\n\ \ \ \ \ \ \ \ set\ rr\ 0\n\ \ \ \ \ \ \ \ foreach\ row\ \{8\ 7\ 6\ 5\ 4\ 3\ 2\ 1\}\ \{\n\ \ \ \ \ \ \ \ set\ rowscreen\ \[expr\ \{\$rr*50.\}\]\n\ \ \ \ \ \ \ \ foreach\ column\ \{A\ B\ C\ D\ E\ F\ G\ H\}\ \{\n\ \ \ \ \ \ \ \ set\ colscreen\ \ \[expr\ \{\$cc*50.\}\]\ \ \ \n\ \ \ \ \ \ \ \ lappend\ result\ \ \ \"\$column\$row\ \$rowscreen\ \$colscreen\"\n\ \ \ \ \ \ \ \ incr\ cc\ 1\n\ \ \ \ \ \ \ \ incr\ rr\ 1\n\ \ \ \ \ \ \ \ \ \}\}\n\ \ \ \ puts\ \$result\n\ \ \ \ return\ \$result\n\ \ \ \ \n\ \ \ \}\n\ \ \ \ \ \ \n\ \ \ \ \ \ \ \ #foreach\ row\ \{8\ 7\ 6\ 5\ 4\ 3\ 2\ 1\}\ \{\n\ \ \ \ \ \ \ \ #foreach\ column\ \{A\ B\ C\ D\ E\ F\ G\ H\}\ \{\n\ \ \ \ \ \ \ \ #\ \ \ \ lappend\ res\ \[\"\ \"\ \"\$column\$row\"\]\n\ \ \ \ \ \ \ \ #puts\ \"\ \ \$column\$row\ \"\n\ \ \ \ \ \ \ \n\ \ \ \ proc\ gamepieces\ \{state3\}\ \{\n\ \ \ \ \ global\ bluepieces\ redpieces\n\ \ \ \ \ if\ \{\ \$state3\ ==\ 2\ \}\ \{\ \n\ \ \ \ \ set\ bluepieces\ \[list\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]\n\ \ \ \ \ set\ redpieces\ \ \[list\ 0\ K\ A\ A\ E\ E\ H\ H\ R\ R\ C\ C\ P\ P\ P\ P\ P\]\n\ \ \ \ \ \ \ \}\ \n\ \ \ \ \ \n\ \ \ \ if\ \{\ \$state3\ ==\ 3\ \}\ \{\ \n\ \ \ \ \ #black\ western\n\ \ \ \ \ set\ bluepieces\ \{\ \ \\u265A\ \\u265B\ \\u265C\ \\u265C\ \\u265D\ \\u265D\ \\u265E\ \\u265E\ \\u265F\ \\u265F\ \\u265F\ \\u265F\ \n\n\\u265F\ \\u265F\ \\u265F\ \\u265F\}\ \ \n\ \ \ \ \ #white\ western\n\ \ \ \ \ set\ redpieces\ \{\ 0\ \ \\u2654\ \\u2655\ \\u2655\ \\u2656\ \ \\u2656\ \\u2657\ \\u2657\ \ \\u2658\ \\u2658\ \\u2659\ \\u2659\ \\u2659\ \n\n\ \\u2659\ \\u2659\ \\u2659\ \\u2659\ \\u2659\}\ \ \n\ \ \ \ \ \ \ \}\n\ \ \ \ \ \ if\ \{\ \$state3\ ==\ 1\ \}\ \{\ \n\ \ \ \ \ \ set\ bluepieces\ \{\\u5C07\ \\u58EB\ \ \\u58EB\ \ \\u8C61\ \\u8C61\ \\u99AC\ \\u99AC\ \\u8ECA\ \\u8ECA\ \ \ \\u7832\ \ \ \\u7832\ \ \ \ \n\n\\u5352\ \\u5352\ \\u5352\ \ \ \\u5352\ \\u5352\}\n\ set\ redpieces\ \ \{\ \ 0\ \\u5E25\ \ \ \\u4ED5\ \\u4ED5\ \ \ \\u76F8\ \ \ \\u76F8\ \\u99AC\ \\u99AC\ \\u8ECA\ \\u8ECA\ \ \ \ \ \ \\u70AE\ \ \\u70AE\ \n\n\ \\u5175\ \ \\u5175\ \ \ \ \\u5175\ \ \ \ \ \\u5175\ \ \ \\u5175\ \ \}\ \ \n\ \ \ \ \ \}\n\ \n\ \ \ \ \ \}\n\ \ \ \ \n\ \ \ \ \ set\ ind\ 0\n\ \ \ \ \ set\ indx\ 0\n\ \ \ \ \ set\ baseline\ \{list\ 1\}\n\ \ \ \ \ \ proc\ K\ \{\ x\ y\ \}\ \{\ set\ x\ \}\n\n\ \ \ \ \ proc\ xpop\ \{\ topper\ \}\ \{\n\ \ \ \ \ global\ liner\ \n\ \ \ \ \ global\ ind\ indx\ \n\ \ \ \ \ global\ bluepieces\ redpieces\n\ \ \ \ \ global\ baseline\n\ \ \ \ \ set\ topper\ \[\ lindex\ \$bluepieces\ \$ind\ \]\;\n\ \ \ \ \ if\ \{\ \$topper\ ==\ \"\"\ \}\ \{\ \n\ \ \ \ \ set\ topper\ \[\ lindex\ \$redpieces\ \$indx\ \]\n\ \ \ \ \ set\ indx\ \[\ expr\ \{\ \$indx\ +\ 1\}\]\n\ \ \ \ \ \ \ \}\ \n\ \ \ \ \ set\ ind\ \[\ expr\ \{\ \$ind\ +\ 1\}\]\n\ \ \ \ \ lappend\ \$baseline\ \$topper\;\n\ \ \ \ \ return\ \$topper\;\n\ \ \ \ \ \}\n\ \ \ \ \ set\ state2\ 1\n\ \ \ \ \ \ \ \ \ \ proc\ populateCanvas\ \{w\ cols\ rows\ args\}\ \{\n\ \ \ \ global\ state2\ state3\n\ \ \ \ gamepieces\ \$args\n\ \ \ \ #refreshgrid\ \ \$w\ \$state2\ \n\ \ \ \ set\ state3\ \$args\n\ \ \ \ global\ ind\ indx\n\ \ \ \ variable\ ids\ \;#\ links\ text\ ids\ with\ respective\ rect\ ids\n\ \ \ \ variable\ boxes\ \;#\ lists\ text\ id\ and\ text\ associated\ with\ each\ rect\ id\n\ \ \ \ catch\ \{unset\ ids\ boxes\}\n\ \ \ \ set\ canvas\ \$w\n\ \ \ \ \n\ \ \ \ #\ parameters\ for\ drawing\ boxes\n\ \ \ \ set\ boxwidth\ 50\n\ \ \ \ set\ boxheight\ 50\n\ \ \ \ set\ padx\ 3\n\ \ \ \ set\ pady\ 3\n\ \ \ \ set\ colors\ \{\ orange\ yellow\ green\ \ gray\}\n\ \ \ \ set\ labels\ \{one\ two\ three\ four\}\n\n\ \ \ \ #\ draw\ the\ boxes\n\ \ \ \ for\ \{set\ row\ 0\}\ \{\$row\ <\ \$rows\}\ \{incr\ row\}\ \{\n\ \ \ \ \ \ for\ \{set\ col\ 0\}\ \{\$col\ <\ \$cols\}\ \{incr\ col\}\ \{\n\n\ \ \ \ \ \ \ \ #\ calculate\ coordinates\n\ \ \ \ \ \ \ \ set\ x1\ \[expr\ \{\$col\ *\ (\$boxwidth\ +\ \$padx)\ +\ \$padx\}\]\n\ \ \ \ \ \ \ \ set\ x2\ \[expr\ \{\$x1\ +\ \$boxwidth\}\]\n\ \ \ \ \ \ \ \ set\ x3\ \[expr\ \{\$x1\ +\ (\$boxwidth\ /\ 2)\}\]\n\ \ \ \ \ \ \ \ set\ y1\ \[expr\ \{\$row\ *\ (\$boxheight\ +\ \$pady)\ +\ \$pady\}\]\n\ \ \ \ \ \ \ \ set\ y2\ \[expr\ \{\$y1\ +\ \$boxheight\}\]\n\ \ \ \ \ \ \ \ set\ y3\ \[expr\ \{\$y1\ +\ (\$boxheight\ /\ 2)\}\]\n\n\ \ \ \ \ \ \ \ #\ choose\ color\ and\ text\n\ \ \ \ \ \ \ \ set\ color\ \[lindex\ \$colors\ \[expr\ \{int(rand()\ *\ \[llength\ \$colors\])\}\]\]\n\ \ \ \ \ \ \ \ #set\ text\ \[lindex\ \$labels\ \[expr\ \{int(rand()\ *\ \[llength\ \$labels\])\}\]\]\n\ \ \ \ \ \ \ \ #\ set\ text\ \[xpop\ topper\]\n\ \ \ \ \ \ \ \ \ set\ font2\ \[list\ Helvetica\ \[expr\ \$boxwidth/2\]\]\n\n\ \ \ \ \ \ \ \ \ set\ text\ \"0\"\n\ \ \ \ \ \ \ \ \ #set\ text\ \"K\"\n\ \ \ \ \ \ \ \ \ set\ texter\ \[xpop\ 1\ \]\n\ \ \ \ \ \ \ \ \ set\ tilename\ \ \[expr\ \{int(rand()*1000000000.)\}\]\n\ \ \ \ \ \ \ \ #\ create\ the\ boxes\n\ \ \ \ \ \ \ \ set\ boxid\ \[\$w\ create\ oval\ \$x1\ \$y1\ \$x2\ \$y2\ \\\n\ \ \ \ \ \ \ \ \ \ -fill\ \$color\ -tags\ \[concat\ mv\ rect\ \$args\ \ obj_\$tilename\]\\\n\ \ \ \ \ \ \ \ \ \ -outline\ black\]\n\ \ \ \ \ \ \ \ set\ colorfo\ blue\n\ \ \ \ \ \ \ \ if\ \{\ \$indx\ >\ 1\ \}\ \{set\ colorfo\ red\}\n\ \ \ \ \ \ \ \ #set\ textid\ \[\$w\ create\ text\ \$x3\ \$y3\ -font\ \$font2\ -fill\ \$colorfo\ \\\n\ \ \ \ \ \ \ \ #\ \ -text\ \$text\ -tags\ \[concat\ mv\ \ \$args\ \ obj_\$tilename\]\ \ \]\n\n\ \ \ \ \ \ \ \ \ set\ textid\ \[\$w\ create\ text\ \$x3\ \$y3\ -font\ \$font2\ -fill\ \$colorfo\ \\\n\ \ \ \ \ \ \ \ \ \ -text\ \$texter\ -tags\ \[concat\ mv\ \ \$args\ \ obj_\$tilename\ \]\ \ \]\n\n\ \ \ \ \ \ \ \ #\ remember\ which\ text\ item\ goes\ with\ which\ box\ and\ what\ the\ text\ says\n\ \ \ \ \ \ \ \ set\ boxes(\$boxid)\ \[list\ \$textid\ \$text\]\n\ \ \ \ \ \ \ \ set\ ids(\$textid)\ \$boxid\n\ \ \ \ \ \ \ \ set\ ids(\$boxid)\ \$boxid\n\ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \}\ \ \n\ \ \ \ \ populateCanvas\ .cv\ 6\ 6\ 1\ \n\ \ \ \ \ squarenames\ \{1\ 2\ 3\ \}\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck***gummy\ version\ with\ \ purple\ highlights\ on\ moving\ pieces.***\n\ \ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n\ \ \ \ \ \ #end\ of\ deck\n======\n\n<<categories>>\ Toys\ |\ Example\ |\ Games\ |\ Characters} CALL {my revision {Chinese Xiangqi Chessboard}} CALL {::oo::Obj1030438 process revision/Chinese+Xiangqi+Chessboard} CALL {::oo::Obj1030436 process}

-errorcode

NONE

-errorinfo

Unknow state transition: LINE -> END
    while executing
"error $msg"
    (class "::Wiki" method "render_wikit" line 6)
    invoked from within
"my render_$default_markup $N $C $mkup_rendering_engine"
    (class "::Wiki" method "render" line 8)
    invoked from within
"my render $name $C"
    (class "::Wiki" method "revision" line 31)
    invoked from within
"my revision $page"
    (class "::Wiki" method "process" line 56)
    invoked from within
"$server process [string trim $uri /]"

-errorline

4