shogizumen.js

ホーム > 将棋 > shogizumen.js

shogizumen.js は、まあさ(maasa.)さんが作った、将棋の局面図をきれいなSVG(※1)で表示するJavaScript。また、元のkif型式のテキストも表示可能。

http://maasa.g2.xrea.com/shogizumen/ で公開中(以前は  http://www.geocities.jp/ookami_maasa/shogizumen/ で公開されていた)。

shogizumen.jsはMITライセンスになっているので、これに従っていれば改造なども可能。

hiromisoさんによって、shogizumen.jsのバグ(1筋への移動が強調されない)を修正するdiffファイルが公開されている。


このshogizumen.js は、ブログなどで使われている。また、生成されるSVGの局面図をWordなどワープロソフトに貼り付ければ、拡大してもギザギザのないきれいな表示が可能になる。そのため、電子出版でも大いに力を発揮できそう。

ただ、指し将棋の局面図を表示しているため、持駒の部分が「先手/後手」の形になっていて、詰将棋用には使いにくい。

そこで、tumeksterさんのtweetを参考に持駒の部分を改造した。さらに将棋盤を正方形から少し縦長(※2)にして、星も追加した。

詰将棋用 shogizumen.js (と書式設定用の zumen.css)、とりあえずうまく動いているみたい。

詰将棋用 shogizumen.js による表示例

<script src="shogizumen.js" charset="utf-8"></script>

<link rel="stylesheet" type="text/css" href="zumen.css">

<pre class="shogizumen">

後手の持駒:飛二 角二 金二 銀 桂三 香三 歩十六 

  9 8 7 6 5 4 3 2 1

+---------------------------+

| ・ ・ ・ ・ ・ ・ 金v桂v香|一

| ・ ・ ・ ・ ・ ・ 銀v玉 ・|二

| ・ ・ ・ ・ ・ ・v銀v歩 ・|三

| ・ ・ ・ ・ ・ ・ ・ ・ ・|四

| ・ ・ ・ ・ ・ ・ ・ ・ 歩|五

| ・ ・ ・ ・ ・ ・ ・ ・ ・|六

| ・ ・ ・ ・ ・ ・ ・ ・ ・|七

| ・ ・ ・ ・ ・ ・ ・ ・ ・|八

| ・ ・ ・ ・ ・ ・ ・ ・ ・|九

+---------------------------+

先手の持駒:金 銀 

</pre>

スタイルシートでフォントを明朝体に指定

<script src="shogizumen.js" charset="utf-8"></script>

<link rel="stylesheet" type="text/css" href="zumen.css">

<style>

svg { font-family : '游明朝','YuMincho','ヒラギノ明朝 ProN W3','Hiragino Mincho ProN','MS P明朝','MS Mincho',serif; } 

</style>

<pre class="shogizumen">

後手の持駒:飛二 角二 金二 銀 桂三 香三 歩十六 

  9 8 7 6 5 4 3 2 1

+---------------------------+

| ・ ・ ・ ・ ・ ・ 金v桂v香|一

| ・ ・ ・ ・ ・ ・ 銀v玉 ・|二

| ・ ・ ・ ・ ・ ・v銀v歩 ・|三

| ・ ・ ・ ・ ・ ・ ・ ・ ・|四

| ・ ・ ・ ・ ・ ・ ・ ・ 歩|五

| ・ ・ ・ ・ ・ ・ ・ ・ ・|六

| ・ ・ ・ ・ ・ ・ ・ ・ ・|七

| ・ ・ ・ ・ ・ ・ ・ ・ ・|八

| ・ ・ ・ ・ ・ ・ ・ ・ ・|九

+---------------------------+

先手の持駒:金 銀 

</pre>

生成された局面図のsvgファイル(整形済) 

<svg xmlns="http://www.w3.org/2000/svg" width="264" height="239.8" style="vertical-align: bottom;">

  <g>

    <rect x="27" y="16" width="199" height="216.82000000000002" stroke-width="2" stroke="currentColor" fill="none"></rect>

    <circle cx="93.5" cy="88.44000000000001" r="2" stroke="currentColor" fill="currentColor"></circle>

    <circle cx="93.5" cy="160.38000000000002" r="2" stroke="currentColor" fill="currentColor"></circle>

    <circle cx="159.5" cy="88.44000000000001" r="2" stroke="currentColor" fill="currentColor"></circle>

    <circle cx="159.5" cy="160.38000000000002" r="2" stroke="currentColor" fill="currentColor"></circle>

    <text x="38" y="12.003333333333334" font-family="inherit" font-size="8.8" fill="currentColor" text-anchor="middle">9</text>

    <text x="232.7" y="29.2" font-size="8.8" font-family="inherit" fill="currentColor" text-anchor="middle">一</text>

    <line x1="49.5" x2="49.5" y1="16.5" y2="232.32000000000002" stroke-width="1" stroke="currentColor"></line>

    <line y1="40.480000000000004" y2="40.480000000000004" x1="27.5" x2="225.5" stroke-width="1" stroke="currentColor"></line>

    <text x="60" y="12.003333333333334" font-family="inherit" font-size="8.8" fill="currentColor" text-anchor="middle">8</text>

    <text x="232.7" y="53.18000000000001" font-size="8.8" font-family="inherit" fill="currentColor" text-anchor="middle">二</text>

    <line x1="71.5" x2="71.5" y1="16.5" y2="232.32000000000002" stroke-width="1" stroke="currentColor"></line>

    <line y1="64.46000000000001" y2="64.46000000000001" x1="27.5" x2="225.5" stroke-width="1" stroke="currentColor"></line>

    <text x="82" y="12.003333333333334" font-family="inherit" font-size="8.8" fill="currentColor" text-anchor="middle">7</text>

    <text x="232.7" y="77.16" font-size="8.8" font-family="inherit" fill="currentColor" text-anchor="middle">三</text>

    <line x1="93.5" x2="93.5" y1="16.5" y2="232.32000000000002" stroke-width="1" stroke="currentColor"></line>

    <line y1="88.44000000000001" y2="88.44000000000001" x1="27.5" x2="225.5" stroke-width="1" stroke="currentColor"></line>

    <text x="104" y="12.003333333333334" font-family="inherit" font-size="8.8" fill="currentColor" text-anchor="middle">6</text>

    <text x="232.7" y="101.14000000000001" font-size="8.8" font-family="inherit" fill="currentColor" text-anchor="middle">四</text>

    <line x1="115.5" x2="115.5" y1="16.5" y2="232.32000000000002" stroke-width="1" stroke="currentColor"></line>

    <line y1="112.42" y2="112.42" x1="27.5" x2="225.5" stroke-width="1" stroke="currentColor"></line>

    <text x="126" y="12.003333333333334" font-family="inherit" font-size="8.8" fill="currentColor" text-anchor="middle">5</text>

    <text x="232.7" y="125.12" font-size="8.8" font-family="inherit" fill="currentColor" text-anchor="middle">五</text>

    <line x1="137.5" x2="137.5" y1="16.5" y2="232.32000000000002" stroke-width="1" stroke="currentColor"></line>

    <line y1="136.4" y2="136.4" x1="27.5" x2="225.5" stroke-width="1" stroke="currentColor"></line>

    <text x="148" y="12.003333333333334" font-family="inherit" font-size="8.8" fill="currentColor" text-anchor="middle">4</text>

    <text x="232.7" y="149.1" font-size="8.8" font-family="inherit" fill="currentColor" text-anchor="middle">六</text>

    <line x1="159.5" x2="159.5" y1="16.5" y2="232.32000000000002" stroke-width="1" stroke="currentColor"></line>

    <line y1="160.38000000000002" y2="160.38000000000002" x1="27.5" x2="225.5" stroke-width="1" stroke="currentColor"></line>

    <text x="170" y="12.003333333333334" font-family="inherit" font-size="8.8" fill="currentColor" text-anchor="middle">3</text>

    <text x="232.7" y="173.08" font-size="8.8" font-family="inherit" fill="currentColor" text-anchor="middle">七</text>

    <line x1="181.5" x2="181.5" y1="16.5" y2="232.32000000000002" stroke-width="1" stroke="currentColor"></line>

    <line y1="184.36" y2="184.36" x1="27.5" x2="225.5" stroke-width="1" stroke="currentColor"></line>

    <text x="192" y="12.003333333333334" font-family="inherit" font-size="8.8" fill="currentColor" text-anchor="middle">2</text>

    <text x="232.7" y="197.06" font-size="8.8" font-family="inherit" fill="currentColor" text-anchor="middle">八</text>

    <line x1="203.5" x2="203.5" y1="16.5" y2="232.32000000000002" stroke-width="1" stroke="currentColor"></line>

    <line y1="208.34" y2="208.34" x1="27.5" x2="225.5" stroke-width="1" stroke="currentColor"></line>

    <text x="214" y="12.003333333333334" font-family="inherit" font-size="8.8" fill="currentColor" text-anchor="middle">1</text>

    <text x="232.7" y="221.04" font-size="8.8" font-family="inherit" fill="currentColor" text-anchor="middle">九</text>

  </g>

  <g transform="translate(170.5,28.490000000000002)">

    <text fill="currentColor" dy="7.04" font-size="18.04" font-family="inherit" text-anchor="middle">金</text>

  </g>

  <g transform="translate(192.5,28.490000000000002) scale(-1,-1)">

    <text fill="currentColor" dy="7.04" font-size="18.04" font-family="inherit" text-anchor="middle">桂</text>

  </g>

  <g transform="translate(214.5,28.490000000000002) scale(-1,-1)">

    <text fill="currentColor" dy="7.04" font-size="18.04" font-family="inherit" text-anchor="middle">香</text>

  </g>

  <g transform="translate(170.5,52.470000000000006)">

    <text fill="currentColor" dy="7.04" font-size="18.04" font-family="inherit" text-anchor="middle">銀</text>

  </g>

  <g transform="translate(192.5,52.470000000000006) scale(-1,-1)">

    <text fill="currentColor" dy="7.04" font-size="18.04" font-family="inherit" text-anchor="middle">玉</text>

  </g>

  <g transform="translate(170.5,76.45) scale(-1,-1)">

    <text fill="currentColor" dy="7.04" font-size="18.04" font-family="inherit" text-anchor="middle">銀</text>

  </g>

  <g transform="translate(192.5,76.45) scale(-1,-1)">

    <text fill="currentColor" dy="7.04" font-size="18.04" font-family="inherit" text-anchor="middle">歩</text>

  </g>

  <g transform="translate(214.5,124.41)">

    <text fill="currentColor" dy="7.04" font-size="18.04" font-family="inherit" text-anchor="middle">歩</text>

  </g>

  <g transform="translate(249.7,232.606) scale(1,1)">

    <text font-family="inherit" font-size="14.142857142857142" fill="currentColor" text-anchor="middle" x="0" y="0">銀</text>

    <text font-family="inherit" font-size="14.142857142857142" fill="currentColor" text-anchor="middle" x="0" y="-15.415714285714285">金</text>

    <text font-family="inherit" font-size="14.142857142857142" fill="currentColor" text-anchor="middle" x="0" y="-30.83142857142857"> </text>

    <text font-family="inherit" font-size="14.142857142857142" fill="currentColor" text-anchor="middle" x="0" y="-46.24714285714286">駒</text>

    <text font-family="inherit" font-size="14.142857142857142" fill="currentColor" text-anchor="middle" x="0" y="-61.66285714285714">持</text>

  </g>

</svg>

※1 SVGは、Scalable Vector Graphicsの略。くわしくは、WikipediaのScalable Vector Graphicsを参照のこと。

※2 将棋盤は縦が1尺2寸、横が1尺1寸だそうなので、縦横の比率を 12 ÷ 11 ≒ 1.09 として計算した。

2023年2月15日作成/2023年420日修正

ホーム > 将棋 > shogizumen.js