1 -- generic functions for shogi themes
2 -- FIXME: still depends on Shogi.ttf for the tile
4 function tile(white
, ratio
)
6 local i
= Image(size
,size
)
9 local g
= RadialGradient(Point(size
*0.5,size
*0.5), size
*0.5, Point(size
*0.3,size
*0.3))
15 i
:translate(-size
, -size
)
17 b
:translate(-size
, -size
)
23 i
:translate(size
*(1-ratio
)*0.5, size
*(1-ratio
)*0.5)
25 b
:translate(size
*(1-ratio
)*0.5, size
*(1-ratio
)*0.5)
28 i
:draw_glyph(Rect(0,0,size
,size
), "../ShogiSVG-TTF/Shogi.ttf", "0x2c", "black", b
)
29 --i:draw_svg(Rect(0,0,size,size), "../ShogiSVG/tile.svg")
34 function draw_arrowhead(i
, p
, vx
,vy
, length
, rwidth
, linecolor
,linewidth
)
35 -- normalize to 1 the direction vector
36 local vl
= (vx
*vx
+ vy
*vy
)^
0.5
38 -- the component vector along the arrow direction
39 local vxdirect
, vydirect
= -vx
*length
, -vy
*length
40 -- an orthogonal vector of requested relative width
41 local vxortho
,vyortho
= vydirect
*rwidth
, -vxdirect
*rwidth
43 i
:draw_line(p
,Point(p
.x
+vxdirect
+vxortho
,p
.y
-vydirect
-vyortho
), linecolor
,linewidth
)
44 i
:draw_line(p
,Point(p
.x
+vxdirect
-vxortho
,p
.y
-vydirect
+vyortho
), linecolor
,linewidth
)
47 function shogi_moves(moves
)
48 return function(i
,size
)
49 if not theme
.options
.moves_overlay
.value
then
54 --local xcenter, ycenter, width = size/2, size/2, size/4
55 local xcenter
, ycenter
, width
= 0.8*size
, 0.82*size
, 0.08*size
56 local tilesize
,shortsize
= 0.8*width
, 0.3*width
57 local arrowlen
,arrowrwidth
= 0.2*width
, 0.5
58 local centerpoint
= Point(xcenter
,ycenter
)
59 local b
= Brush("red")
60 for index
,move
in ipairs(moves
) do
61 local x
,y
,long
= move
[1],move
[2],move
[3]
63 local p2
= Point(xcenter
+1.5*x
*width
, ycenter
-1.5*y
*width
)
64 i
:draw_line(centerpoint
,p2
, "purple",1)
65 draw_arrowhead(i
, p2
, x
,y
, arrowlen
,arrowrwidth
, "purple",1)
67 i
:draw_line(centerpoint
, Point(xcenter
+x
*width
,ycenter
-y
*width
),"red",1)
68 i
:fill_rect(Rect(xcenter
+x
*width
-shortsize
/2, ycenter
-y
*width
-shortsize
/2,
69 shortsize
, shortsize
), b
)
74 i
:fill_rect(Rect(xcenter
-tilesize
/2,ycenter
-tilesize
/2,
75 tilesize
,tilesize
), b
)
83 shogichars
["king"] = {"0x7389", {"0x7389", "0x5c06"}}
84 shogichars
["jade general"] = {"0x738b", {"0x738b", "0x5c06"}}
85 shogichars
["flying chariot"] = {"0x98db", {"0x98db", "0x8eca"}}
86 shogichars
["bishop"] = {"0x89d2", {"0x89d2", "0x884c"}}
87 shogichars
["gold general"] = {"0x91d1", {"0x91d1", "0x5c06"}}
88 shogichars
["silver general"] = {"0x9280", {"0x9280", "0x5c06"}}
89 shogichars
["knight"] = {"0x6842", {"0x6842", "0x99ac"}}
90 shogichars
["incense chariot"] = {"0x9999", {"0x9999", "0x8eca"}}
91 shogichars
["pawn"] = {"0x6b69", {"0x6b69", "0x5175"}}
92 shogichars
["dragon king"] = {"0x9f8d", {"0x9f8d", "0x738b"}}
93 shogichars
["dragon horse"] = {"0x99ac", {"0x9f8d", "0x99ac"}}
94 shogichars
["narigin"] = {"0x5168", {"0x6210", "0x9280"}}
95 shogichars
["narikei"] = {"0x572d", {"0x6210", "0x6842"}}
96 shogichars
["narikyo"] = {"0x674f", {"0x6210", "0x9999"}}
97 shogichars
["tokin"] = {"0x3068", {"0x3068", "0x91d1"}}
99 shogichars
["drunken elephant"] = {"0x9154", {"0x9154", "0x8c61"}}
100 shogichars
["crown prince"] = {"0x592a", {"0x592a", "0x5b50"}}
101 -- Chess compatibility (part of Dai Shogi)
102 shogichars
["free king"] = {"0x5954", {"0x5954", "0x738b"}}
107 {-1,-1},{0,-1},{1,-1}}
108 shogimoves_rook
= {{-1,0,1},{1,0,1},{0,-1,1},{0,1,1}}
109 shogimoves_dragon
= {
110 {-1,0,1},{1,0,1},{0,-1,1},{0,1,1},
111 {-1,-1},{1,-1},{-1,1},{1,1}}
112 shogimoves_bishop
= {{-1,-1,1},{1,-1,1},{-1,1,1},{1,1,1}}
114 {-1,-1,1},{1,-1,1},{-1,1,1},{1,1,1},
115 {-1,0},{1,0},{0,-1},{0,1}}
119 shogimoves_silver
= {
122 shogimoves_knight
= {{-1,2},{1,2}}
123 shogimoves_lance
= {{0,1,1}}
124 shogimoves_pawn
= {{0,1}}
126 shogimoves_drunken_elephant
= {
131 shogimoves_freeking
= {
132 {-1,1,1},{0,1,1},{1,1,1},
134 {-1,-1,1},{0,-1,1},{1,-1,1}}